CaravanStudios / open-product-recovery

Apache License 2.0
26 stars 20 forks source link

Schema compiler sometimes outputs the same type twice, leading to compilation errors. #47

Closed johndayrichter closed 1 year ago

johndayrichter commented 1 year ago

Expected Behavior

types.ts contains each type definition exactly once.

Actual Behavior

The same output type may occur multiple times.

Steps to Reproduce the Problem

Add a file named jsonpatchop.schema.json with contents:

{
  "$id": "jsonpatchop.schema.json",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "comment": "Copied and reformatted from source at https://json.schemastore.org/json-patch.json",
  "description": "A JSON Patch operation",
  "examples": [
    {
      "op": "replace",
      "path": "",
      "value": {}
    }
  ],
  "title": "JSONPatchOp",
  "oneOf": [
    {
      "additionalProperties": false,
      "required": ["value", "op", "path"],
      "properties": {
        "path": {
          "$ref": "jsonpath.schema.json"
        },
        "op": {
          "description": "The operation to perform.",
          "type": "string",
          "enum": ["add", "replace", "test"]
        },
        "value": {
          "description": "The value to add, replace or test."
        }
      }
    },
    {
      "additionalProperties": false,
      "required": ["op", "path"],
      "properties": {
        "path": {
          "$ref": "jsonpath.schema.json"
        },
        "op": {
          "description": "The operation to perform.",
          "type": "string",
          "enum": ["remove"]
        }
      }
    },
    {
      "additionalProperties": false,
      "required": ["from", "op", "path"],
      "properties": {
        "path": {
          "$ref": "jsonpath.schema.json"
        },
        "op": {
          "description": "The operation to perform.",
          "type": "string",
          "enum": ["move", "copy"]
        },
        "from": {
          "$ref": "jsonpath.schema.json",
          "description": "A JSON Pointer path pointing to the location to move/copy from."
        }
      }
    }
  ]
}

Replace the definition of jsonpatch.schema.json with:

{
  "$id": "jsonpatch.schema.json",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "comment": "Copied and reformatted from source at https://json.schemastore.org/json-patch.json",
  "description": "A JSON Patch array",
  "examples": [
    [
      {
        "op": "replace",
        "path": "",
        "value": {}
      }
    ]
  ],
  "items": {
    "$ref" : "jsonpatchop.schema.json"
  },
  "title": "JSONPatch",
  "type": "array"
}

Run `npm run compile' in opr-models.

Specifications