json-schema-ref-parser icon indicating copy to clipboard operation
json-schema-ref-parser copied to clipboard

Internal $id reference not derefernced

Open zuker opened this issue 6 years ago • 1 comments

STR:

  1. Create file schema.json
{
  "$schema": "http://json-schema.org/draft-07/schema#",

  "definitions": {
    "address": {
      "$id": "#address",
      "type": "object",
      "properties": {
        "street_address": { "type": "string" },
        "city":           { "type": "string" },
        "state":          { "type": "string" }
      },
      "required": ["street_address", "city", "state"]
    }
  },

  "type": "object",

  "properties": {
    "billing_address": { "$ref": "#address" },
    "shipping_address": { "$ref": "#address" }
  }
}

this actually example from https://json-schema.org/understanding-json-schema/structuring.html#using-id-with-ref

  1. npm i json-schema-ref-parser
  2. node -e "(async () => { console.log(JSON.stringify(await require('json-schema-ref-parser').dereference(require('./schema.json')), null, 2))})()"

Actual result:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "address": {
      "$id": "#address",
      "type": "object",
      "properties": {
        "street_address": {
          "type": "string"
        },
        "city": {
          "type": "string"
        },
        "state": {
          "type": "string"
        }
      },
      "required": [
        "street_address",
        "city",
        "state"
      ]
    }
  },
  "type": "object",
  "properties": {
    "billing_address": {
      "$ref": "#address"
    },
    "shipping_address": {
      "$ref": "#address"
    }
  }
}

Expected result: properties.billing_address and properties.shipping_address are dereferenced

zuker avatar Sep 10 '19 12:09 zuker

Seems this test https://github.com/APIDevTools/json-schema-ref-parser/blob/v7.1.1/test/specs/internal/bundled.js#L7 actualy not testing the case since #fragment has no other props

zuker avatar Sep 10 '19 12:09 zuker

Duplicate of #145.

philsturgeon avatar Nov 26 '22 13:11 philsturgeon