Skip to content

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

@y805939188

Description

@y805939188

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-viewer": "^4.15.1"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions