APIDevTools / json-schema-ref-parser

Parse, Resolve, and Dereference JSON Schema $ref pointers in Node and browsers
https://apitools.dev/json-schema-ref-parser
MIT License
957 stars 228 forks source link

$ref at root level is not omitted #174

Closed dibericky closed 4 years ago

dibericky commented 4 years ago

Steps to reproduce

With a jsonSchema like:

{
  components: {
    schemas: {
      Pet: {
        type: "string"
      }
    }
  },
  $ref: "#/components/schemas/Pet"
};

the $ref is correctly resolved, but is kept a "$ref: "#" in the result. Example

+ expected - actual ... Lines skipped

  {
-   '$ref': '#',
    components: {
...
    type: 'string'
  }

What is expected? I expect that the $ref is omitted from the result:

{
      components: {
        schemas: {
          Pet: {
            type: "string"
          }
        }
      },
      type: "string"
    }

Other info

Danielecina commented 4 years ago

I have the same problem. This $ref left in the root, blocks the recursive resolution of the $ref

How to use example:

philsturgeon commented 4 years ago

Can you put the content in the root instead of defining it inside then hosting it with a $ref? This is known to work, and what you've got in this example isn't adding any benefit over it.

Also what is components, thats commonly used in OpenAPI v3.x which is a whole other thing.

Having siblings is not valid JSON Schema 07, it was added in JSON Schema 2019-09, which is being addressed in #145. Let's cover this there.