Skip to content
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

File extension in $id #1502

Open
andriy-dmytruk opened this issue Apr 9, 2024 · 2 comments
Open

File extension in $id #1502

andriy-dmytruk opened this issue Apr 9, 2024 · 2 comments

Comments

@andriy-dmytruk
Copy link

The JSON schema spec does not seem to put any constraints on the $id, but all the examples seem to follow a similar pattern that omits the extension, e.g.:

{  "$id": "/schemas/address", ... }

Is it discouraged to put the extension in the URL, as this is how the schema will be stored?

{  "$id": "/schemas/address.schema.json", ... }
@jdesrosiers
Copy link
Member

The short answer is that it doesn't matter. Use whatever you like.

That said, keep in mind that schema identifiers can't be relative as they are in your example. Whether or not I would use an extension depends on the URI scheme being used. If using http(s):, I wouldn't use an extension https://example.com/schemas/address) because that's the convention for the http(s): URI scheme.

However, what I prefer is to not use $id and allow the file's location on the file system to be the be the schema's identifier (file:///path/to/schema/address.schema.json). In this case, the identifier includes the extension because the file has an extension. References to this schema are file system relative, so you'll see references like, ./address.schema.json for this schema.

@gregsdennis
Copy link
Member

@andriy-dmytruk, to clarify, the JSON Schema specification explicitly recommends in section 8.2.1.1 that $id be included with a fully-qualified (absolute), fragment-less URI to serve as a base identifier.

Self identification holds the highest priority according to the URI specification, section 5.1, whereas file location holds the second lowest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants