Replies: 3 comments 3 replies
-
Another question to consider if we allow PRO:
CON:
|
Beta Was this translation helpful? Give feedback.
-
Be aware that for the next JSON Schema version, we've planned to remove the non-dynamic behavior from While this technically wouldn't affect 2020-12 schemas that are included, this change in behavior should at least be considered for however OAS wants to use these reference targets. |
Beta Was this translation helpful? Give feedback.
-
Not sure what your feelings on implicit code are, but you could have the key under A pure JSON Schema implementation probably wouldn't like that, but I suppose an OAS implementation shouldn't have any issues. |
Beta Was this translation helpful? Give feedback.
-
Moonwalk imports are intended to drastically simplify OAD Document parsing and loading. JSON Schema referencing presents a challenge for this goal. This isn't so much a proposal as it is a listing of all the options I can think of. It assumes that #72 or something similar is used for imports.
NOTE: This proposal does not address any modularity that might support alternative content schema systems. Although fencing in the referencing/linking system of any format that we might embed in an OAD Document is something that we'll need to think of if we want to support multiple systems.
Importing separate JSON Schema resources
The easiest case is if all JSON Schemas are in separate documents of type
application/schema+json
(or some functional equivalent e.g. YAML). Since imports use IRIs, importing a JSON Schema document works just like importing an OAD Document, except with$id
assigning the resource's URI instead of the OpenAPI Object'sself
field.The challenge is then how to identify the exact schema to use, which may be the entire document or may be a subschema of some sort.
We'll use this schema for examples:
and we'll assume our examples happen in an OAD that includes this:
Accessing subschemas
For subschemas, I can think of three options for the name part of the
<namespace>:<name>
syntax. Two of them are based on URI fragments, and could both be used. That approach could then automatically extend to any other format that defines a URI fragment syntax.Use names under "$defs"
PROS:
CONS:
Use names from plain name fragments as component names
Note the lack of
#
as we are not using this in a URI context. For imports, it does not matter whether the fragment was created by\$anchor
or\$dynamicAnchor
. keywords.PROS:
CONS:
Use JSON Pointers
Again, note the plain-text, rather than fragment-encoded, JSON Pointer.
PROS:
CONS:
$id
-crossing JSON PointersAccessing the whole schema resource
If JSON Pointers are used, the empty string would indicate the whole document:
Note that the quotes are required or YAML will think it is an object key.
If plain name fragments are defined and are the only supported component name, authors can just define one in the document root schema.
If
$defs
names are used, using the namespace without a colon is the only idea I've had so far:Defining JSON Schemas inline
Inline schemas introduce two areas of complexity:
$id
,$anchor
, and$dynamicAnchor
In particular, a same-document reference from an inline Schema Object that does not use
$id
can point anywhere in an OAD Document using JSON Pointer fragments, which contradicts the principle of only re-using components in the Components Object.One thing we might want to do is place limits on inline schemas and require everything else to be placed in external documents. I can think of a few variations on this offhand:
Require a nonempty $id in the Schema Object root if $ref or $dynamicRef are present
References in inline Schema Objects that use
\$id
in the root object are resolved just as if the Schema Object were an external document.PRO:
CON:
$id
$id
when adding$ref
later$schema
Forbid $ref and $dyanamicRef (and $id, $anchor, and $dynamicAnchor) in inline Schema Objects
This would enable using inline schemas for simple schemas, but push everything requiring referencing to external files and avoid the need to scan OpenAPI Documents for JSON Schema keywords that establish referencing targets.
PRO:
$id
in a subschema)$schema
as it is only meaningful alongside$id
outside of schema document rootsCON:
Different restrictions for schema components vs inline schemas elsewehre
This is kind of a combination of the previous two: forbid the referencing and identification keywords everywhere except under
/components/schemas
, and require$id
in a schema component if$ref
or$dynamicRef
is used.PRO:
$id
keeps reference resolution equivalent to separate documentsCONS:
$id
in subschemas) and$schema
... unless those are also forbidden / banished to schemas in external documentsBeta Was this translation helpful? Give feedback.
All reactions