Get a JSON instance
GET https://example.com/book/12345
[ | |
{ | |
"description": "Hierarchical ambiguous defaults", | |
"schema": { | |
"type": "object", | |
"properties": { | |
"foo": { | |
"$ref": "#/$defs/foo", | |
"default": true | |
} |
import { readFile } from "node:fs/promises"; | |
import { registerSchema } from "@hyperjump/json-schema/draft-2019-09"; | |
import { addKeyword, defineVocabulary } from "@hyperjump/json-schema/experimental"; | |
import * as Browser from "@hyperjump/browser"; | |
const baseUri = "https://schemas.amazon.com/selling-partners/definitions/product-types"; | |
addKeyword({ | |
id: `${baseUri}/keyword/maxUniqueItems`, | |
compile: async (schema) => Browser.value(schema), |
This is a starter for building a custom evaluation handler for [@hyperjump/json-schema
] using its AST. Using the AST allows you to support any JSON Schema version [@hyperjump/json-schema
] supports without having to code for the inticacies of schema identification and referencing. You can implement each keyword as if there were no references.
This code will walk through the schema using the AST. You provide a handler for each keyword to do whatever evaluation you require.
The concept of keywords being identified as URIs is unique to [@hyperjump/json-schema
] and not part of the JSON Schema standard. Unfortunately, there are some keywords that have changed from one release to another and using URIs to identify them allows us to distinguish between two keywords with the same name. For example, items
changes behavior in 2020-12, so there are different URIs for each version.
{ | |
"$id": "https://json-schema.org/draft/2020-12/schema", | |
"$schema": "https://json-schema.org/draft/2020-12/schema", | |
"title": "Core and Validation specifications meta-schema", | |
"$dynamicAnchor": "meta", | |
"allOf": [ | |
{ | |
"$ref": "meta/core" | |
}, | |
{ |
{ | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"$id": "http://example.com/my-custom-draft-07/schema#", | |
"title": "Core schema meta-schema", | |
"allOf": [{ "$ref": "#/definitions/schema" }], | |
"$comment": "Add constraints here that should only apply to root schemas and not sub-schemas", | |
"definitions": { | |
"schema": { |
Starting with the release of OpenAPI 3.1, the dialect of JSON Schema used in OpenAPI documents is configurable. By default, you get the OpenAPI 3.1 Schema dialect, but you can choose to use draft 2020-12 or any other dialect if you choose. This brings up the question of how to validate an OpenAPI 3.1 document if one of its components (JSON Schema) is open-ended. In this article, we'll cover how to configure the default JSON Schema dialect of an OpenAPI 3.1 document and how to validate that document, including JSON Schemas, no matter which dialect(s) you choose to use.
Because not everyone is familiar with the term "dialect" in this context, let's take a moment to define it before moving on. A JSON Schema dialect is any unique incarnation of JSON Schema. This includes any official release of JSON Schema such as draft-07 or draft 2020-12, but it also includes custom versions of JSON Schema. OpenAPI has effectively had three dialects of JS