Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get allOf field from originalFragment when $ref is used within allOf #36

Open
y805939188 opened this issue Mar 21, 2024 · 0 comments

Comments

@y805939188
Copy link

Context

I want to determine whether a node is a ref node by checking if its parent includes $ref.

my schema:

{
  "type": "object",
  "properties": {
    "user": {
      "allOf": [
        {
          "$ref": "#/definitions/employee"
        }
      ]
    }
  },
  "definitions": {
    "employee": {
      "type": "object",
      "properties": {
        "company": {
          "$ref": "#/definitions/company"
        }
      }
    },
    "company": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "description": "The company's name",
          "default": "Unknown"
        }
      }
    }
  }
}

Current Behavior

I want to determine if user.company.name originates from a $ref, but there is not $ref in parent's originalFragment:
image

Expected Behavior

The originalFragment should include all of the schema's original info.

Possible Workaround/Solution

Steps to Reproduce

my js code:

import { SchemaTree } from "@stoplight/json-schema-tree";

const mySchema = {
  type: "object",
  properties: {
    user: {
      allOf: [
        {
          $ref: "#/definitions/employee",
        },
      ],
    },
  },
  definitions: {
    employee: {
      type: "object",
      properties: {
        company: {
          $ref: "#/definitions/company",
        },
      },
    },
    company: {
      type: "object",
      properties: {
        name: {
          type: "string",
          description: "The company's name",
          default: "Unknown",
        },
      },
    },
  },
};

const tree = new SchemaTree(mySchema);
tree.walker.hookInto("stepIn", (node) => {
  console.log("************************");
  console.log("path: ", node.path, " node: ", node);
  console.log("************************");
  return true;
});

tree.populate();

Environment

"@stoplight/json-schema-tree": "^4.0.0"

issue ref: stoplightio/json-schema-viewer#253

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant