Conversation
89cfc87 to
7de454f
Compare
Eomm
left a comment
There was a problem hiding this comment.
TLDR: In OAS 2.0 the definitions map has no constraint on the key but from OAS 3.x, where components.schemas keys must match ^[a-zA-Z0-9\.\-_]+$.
So, this PR enable the swagger 2.0 user to use / and ~ as special chars in its schema definitions (while this is blocked on OAS 3)
Now, I think the codebase already does a decent job on splitting the logic between spec/openapi and spec/swagger, but lib/util/resolve-local-ref.js does not.
| definitions: { | ||
| 'generic/query': { |
There was a problem hiding this comment.
The / should be invalid:
https://spec.openapis.org/oas/v3.1.1.html#fixed-fields-5
Note that definitions should be parameters but we convert it internally
There was a problem hiding this comment.
You're right, thanks. The / was only there to exercise the ~1 unescaping, it isn't needed to reproduce #791. Renamed the definition to genericQuery in both the openapi and swagger tests.
Agreed that With the tests now using a valid name, no test relies on the unescaping anymore. How would you prefer to handle it?
I'd lean towards 3 to keep the scope small, happy to go either way. Also, could you expand on " |
Proposal:
When
querystring,paramsorheadersis a$refpointing to a subschema of a shared schema:resolveLocalRefonly used the schema name and ignored the rest of the pointer, so the wholesharedschema was used instead of the referenced subschema. In Swagger 2.0 mode this throwsCannot create property 'in' on string 'object'.Changes:
resolveLocalReffollows the whole JSON pointer (with~0/~1unescaping), for both the#/definitions/...and#/components/schemas/...formats;resolveCommonParamsreceives the raw shared schemas, as the OpenAPI one already did;resolveCommonParamsis removed, since it is now handled in one place for both modes.Backward compatibility: when the pointer does not lead to a set of parameters (e.g. the existing
support $ref schematest usesquerystring: { $ref: 'subschema-two#/properties/hello' }, a string schema), the resolved definition is used as it has always been. Happy to drop this fallback if you prefer the stricter behavior.Out of scope: the "PS" of #791, adding sibling properties next to
$ref, is rejected by Fastify's own schema compiler (strict mode: unknown keyword).allOf+propertiesis the valid way to express it.This does not overlap with #945 (different lines of the same function, verified on top of it).
Note:
$refto definitions of shared schemas #952Fixes #791