-
-
Notifications
You must be signed in to change notification settings - Fork 313
Modular schema libraries (avoid hardcoding the base URI) #966
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
Comments
You can have an I use precisely this method for managing schemas across both production and staging instances of my application, where the uri references to individual schemas (e.g. "request.json", "response.json", "app-definitions.json") are constant but the base uris vary. |
@jayrbolton Does the solution proposed by @karenetheridge sound like it would work for you? Broadly, I think we would consider making either of the changes you suggested, as outside the scope of JSON Schema. There's templating via other existing tooling, and you could pre-compile your schemas. BUT, as @karenetheridge points out, you can use a uri-reference, which can be a relative reference as opposed to a full URI. |
It sounds like what I'm looking for, but I'm not totally understanding what my schema would look like. Say I had a login form schema, which references two other schemas, each with different base URIs: {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Login Fields",
"type": "object",
"additionalProperties": false,
"required": ["email", "password"],
"properties": {
"email": {"$ref": "{base_uri1}/defs.json#/definitions/email"},
"password": {"$ref": "{base_uri2}/base/defs1.json#/definitions/password"}
}
} What would this look like if I instead used uri-reference |
If you want more than one base URI, then you're out of luck. Feel free to join our open slack server if you want to ask general questions or chat about approaches. |
I realize similar issues to this have come up before (eg here). I also realize this may be more of an implementation issue. If there is a better place to move this post, let me know. Basically, I want to avoid hardcoding any base URI references in a schema in order to better control dependencies in different environments (not unlike imports in a programming language).
A more concrete example:
Here are a couple proposed solutions (both very much in the implementation layers):
Side note: ideally, I would want to avoid any hard dependencies on http URLs to third party servers if I want the application to still work in a few years
The text was updated successfully, but these errors were encountered: