json-schema-tools / traverse

Traverse and optionally mutate a json schema and all it's subschema
https://json-schema-tools.github.io/traverse/
Apache License 2.0
9 stars 3 forks source link

Traverse non-standard paths. #462

Open caschbre opened 2 years ago

caschbre commented 2 years ago

Is your feature request related to a problem? Please describe.

From what I could see, traverse only goes down the 'properties' path. However if I were to setup a sibling node (e.g. x-foobar), I'm unable to traverse down that path.

const mySchema = {
  title: "baz",
  type: "object",
  properties: {
    foo: {
      title: "foo",
      type: "array",
      items: { type: "string" }
    },
    bar: {
      title: "bar",
      anyOf: [
        { title: "stringerific", type: "string" },
        { title: "numberoo", type: "number" }
      ]
    }
  },
  "x-foobar": {
    haz: { bar: "foo" }
  }
};

Describe the solution you'd like

Ability to traverse down any path in the schema.

BelfordZ commented 1 year ago

Thanks @caschbre for the issue. Would love to work this in as an option.

What do you think about a constructor option:

interface customSubschemaPath: JSONPath | JSON-Pointer | regex

or maybe we should accept a JSON schema that extends the meta-schema

{
  type: "object",
  patternProperties: {
    "x-*": {
      properties: { $ref: `https://meta.json-schema.tools/` }
    }
  }
}