-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Dynamic schemas using templated "$ref" #36
Comments
Venders who want to generate API libraries won't like that much =D |
@Relequestual I believe it would technically be possible to generate API libraries for this, treating those templated parameters generitcally, and the library would need to fetch those schemas using references at run-time. This allows for much more powerful/flexible APIs which work on multiple instances/deployments using the same templated API definition, and thus greatly increases interoperability. |
Maybe. My response was a little throw-away. |
@jerstlouis Thanks for writing up your thoughts. We can't make changes to the Generally, implementing a new keyword should be easy, but this one probably won't be because it violates a core assumption in JSON Schema that there are only two kinds of things: schemas and instances. You have added a new kind of thing: template variables. Rather than just writing a plugin, you'll likely have to fork your favorite implementation and modify it (or write something from scratch). But, first things first, your proposal needs more detail. Here are some things you will need to think about and address.
|
@jdesrosiers Thank you very much for proposing a way to move this forward.
I am realizing that really what needs to be extended is probably the OpenAPI Reference Object or the JSON Reference, rather than JSON Schema, from https://swagger.io/specification/ :
Thank you! |
As discussed in #35 (comment) , in a context of using JSON Schema in an OpenAPI definition, I suggested the possibility to use templated path parameters in "$ref", to allow validation of later path parameters based on dynamic schemas that could be retrieved by substituting the templates by the selected value for earlier path parameters.
The resolved "$ref" would become regular "$ref", but in OpenAPI definitions one could write e.g.
"$ref" : "./api/collections-styles/{collectionId}"
and before the final validation step, the
{collectionId}
template would be replaced by a selected value likecollection1
.(e.g. in this example, this "$ref" is used to define the valid values for
{styleId}
in a path/collections/{collectionId}/styles/{styleId}
).The
{collectionId}
would have previously been validated against another potentially dynamic list like"$ref" : "./api/collections"
../api/collections
would return something like:and
./api/collection-styles/collection1
would return something likewhile
./api/collection-styles/collection2
would return something likeThe context being that available/compatibles styles depend on the selected collection.
One simple way to implement this would be to have a validating function for such schemas which accepts a dictionary of template parameters / values, allowing to resolve all the templated
$ref
.The text was updated successfully, but these errors were encountered: