Repository navigation
Description
Is your feature request related to a problem?
The JSON Schema 2020-12 namespace does not refract definitions, so a $ref written inside a definitions entry is not dereferenced. The same schema under $defs is fully dereferenced.
The 2020-12 default meta-schema (https://json-schema.org/draft/2020-12/schema) still lists definitions (marked deprecated), and the validation specification, Appendix A, says: "implementations SHOULD assume that $defs and definitions have the same behavior when that meta-schema is used". Documents written for earlier drafts and declaring this $schema commonly use definitions.
Cause:
apidom-ns-json-schema-2019-09removes thedefinitionsfixed field (src/refractor/specification.ts,dissocPath(...)), and thedefinitionsgetter and setter of itsJSONSchemaElementthrowUnsupportedOperationError("renamed to $defs").apidom-ns-json-schema-2020-12builds on it and doesn't re-add the field, sodefinitionsis a generic member. Its entries are not JSON Schema elements and the dereference visitors don't visit them.
Reproduction (@swagger-api/apidom-ns-json-schema-2020-12 1.14.0):
const { refract } = require('@swagger-api/apidom-ns-json-schema-2020-12');
const e = refract({
$schema: 'https://json-schema.org/draft/2020-12/schema',
definitions: { A: { type: 'string' } },
$defs: { B: { type: 'string' } },
});
for (const k of ['definitions', '$defs']) {
const m = e.get(k);
console.log(k, m.element, m.classes.toValue(), m.get(k === 'definitions' ? 'A' : 'B').element);
}
// definitions object [] object
// $defs object [ 'json-schema-$defs' ] JSONSchema202012Through swagger-client 3.39.0 (json-schema-2020-12-apidom strategy), for this document:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": { "product": { "$ref": "#/definitions/Product" } },
"definitions": {
"Product": { "type": "object", "properties": { "price": { "$ref": "#/definitions/Price" } } },
"Price": { "type": "number", "exclusiveMinimum": 0 }
}
}properties.product is dereferenced including price, because the $ref points into definitions. But definitions.Product.properties.price stays { "$ref": "#/definitions/Price" }. With the entries under $defs instead, both are resolved.
Describe the solution you'd like
Refract definitions like $defs in the 2020-12 namespace: a fixed field reusing the $defs visitor, its class entry in refractor/plugins/replace-empty-element.ts, and a working getter and setter on JSONSchemaElement instead of the inherited throwing ones. Add refractor tests and an apidom-reference dereference test that resolves a $ref inside definitions.
The 2020-12 JSONSchemaElement is shared with the OpenAPI 3.1 and 3.2 and Arazzo namespaces, where definitions inside a Schema Object has no meaning. Those would have to keep it out (e.g. dissocPath in their specifications), or the behavior would have to be limited to standalone JSON Schema documents.
Describe alternatives you've considered
- Resolving
definitionsoutside ApiDOM (copying its entries under a temporary$defsbefore dereferencing, then moving them back) works but is a workaround that every consumer would have to repeat. - Leaving it as is and documenting that refs inside
definitionsare not resolved.
Additional context
- Found while rendering standalone JSON Schema documents in Swagger UI: feat(json-schema-document): render definitions like $defs swagger-ui#11120.
- Tracked as item 2.26 in
.claude/skills/FOLLOW-UPS.mdby chore(skills): add JSON Schema 2020-12 definitions follow-up #5302. dependencies,$recursiveAnchorand$recursiveRefare covered by the same Appendix A sentence but are out of scope here.
Activity
fix(json-schema-document): address Copilot review on dependencies
fix(json-schema-document): address Copilot review on dependencies
feat(json-schema-document): render dependencies like its successors (#…
chore(release): cut the 5.35.0 release
fix(deps): update dependency swagger-ui-react to v5.35.0 (#1047)
chore(deps): update dependency swagger-ui-dist to v5.35.0 (#981)
Update dependency org.webjars:swagger-ui to v5.35.1 (#6929)