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

Impossible to bundle JSON Schema draft-04 itself.

Open robertmassaioli opened this issue 4 years ago • 5 comments

Here is my basic schema:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "additionalProperties": false,
    "properties": {
        "schema": {
            "$ref": "http://json-schema.org/draft-04/schema",
            "title": "schema"
        },
        "tags": {
            "items": {
                "enum": [
                    "forge"
                ],
                "type": "string"
            },
            "title": "tags",
            "type": "array"
        },
    },
    "required": [
        "schema"
    ],
    "type": "object"
}

My code is:

const $RefParser = require('json-schema-ref-parser');

$RefParser.bundle("schema.json").then(schema => {
   console.log(JSON.stringify(schema, null, 2));
}).catch(e => {
   console.error(e);
});

As you can see in "$ref": "http://json-schema.org/draft-04/schema",, I want to bundle the draft-04 schema. Instead, my output is:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "additionalProperties": false,
  "properties": {
    "schema": {
      "$ref": "#/properties/schema/properties/not",
      "title": "schema"
    },
    "tags": {
      "items": {
        "enum": [
          "forge"
        ],
        "type": "string"
      },
      "title": "tags",
      "type": "array"
    }
  },
  "required": [
    "schema"
  ],
  "type": "object"
}

That's not even a valid schema. This looks like a bug to me but I would be very interested in understanding what I have done wrong.

Can somebody please confirm if this is a bug? Cheers.

robertmassaioli avatar Feb 04 '21 04:02 robertmassaioli

Oh, here is a complete bundle of a sample app. error-example.zip

robertmassaioli avatar Feb 04 '21 04:02 robertmassaioli

Can you expand on why this needs to work? Not sure of the use case or what is happening, the issue is pretty sparse.

philsturgeon avatar Mar 13 '21 21:03 philsturgeon

@philsturgeon If I want to have a JSON value, that contains a JSON Schema at v4, then I should be able to just reference the v4 schema as a validator. And then when I run the bundle tool here on it, it should make sure that it is bundled inline and that everything works as expected.

robertmassaioli avatar Jun 26 '21 07:06 robertmassaioli

What do I need to provide such that the use case is easier to understand here? I'm confused that it's not clear that this is a bug and what the expected output would be.

robertmassaioli avatar Jun 26 '21 07:06 robertmassaioli

What tool are you passing this JSON value too that it needs the JSON Schema $schema definition bundled in? Why would a tool want or need that to be done?

philsturgeon avatar Jun 27 '21 19:06 philsturgeon