Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bundling Function #2

Open
theory opened this issue Apr 9, 2024 · 0 comments
Open

Add Bundling Function #2

theory opened this issue Apr 9, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@theory
Copy link
Contributor

theory commented Apr 9, 2024

It might be useful to add a function that can bundle multiple schemas into a single schema, as described here. This pattern allows one to use a single schema JSON object that bundles together all of its subschemas. They're simply collected in the $defs object. A couple of notes:

  • The $id of each sub-schema must also be its key in the $defs object.
  • Probably makes sense to reject sub-schemas without an $id as an error.

Sample from the docs "customer" schema that bundles the address schema it references:

{
  "$id": "https://example.com/schemas/customer",
  "type": "object",
  "properties": {
    "first_name": { "type": "string" },
    "last_name": { "type": "string" },
    "shipping_address": { "$ref": "/schemas/address" },
    "billing_address": { "$ref": "/schemas/address" }
  },
  "required": ["first_name", "last_name", "shipping_address", "billing_address"],
  "$defs": {
    "https://example.com/schemas/address": {
      "$id": "https://example.com/schemas/address",
      "type": "object",
      "properties": {
        "street_address": { "type": "string" },
        "city": { "type": "string" },
        "state": { "type": "string" }
      },
      "required": ["street_address", "city", "state"]
    }
  }
}
@theory theory added the enhancement New feature or request label Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant