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

✨ Proposal: Provide resourceMediaType and resourceSchema when string format is a resource identifier, similar to contentMediaType and contentSchema #1557

Open
torsknod-the-caridian opened this issue Nov 11, 2024 · 2 comments
Labels
proposal Initial discussion of a new idea. A project will be created once a proposal document is created.

Comments

@torsknod-the-caridian
Copy link

Describe the inspiration for your proposal

I have JSON schemata, which contain URIs to further data (mostly further JSON and/ or XML, sometimes ZIPed before).
It would be helpful to have a way to define in which format this data, so people know what they can and have to support when following the data.

Describe the proposal

We already have https://json-schema.org/understanding-json-schema/reference/non_json_data#contentmediatype and https://json-schema.org/understanding-json-schema/reference/non_json_data#contentschema .
If the type is string and format is one of https://json-schema.org/understanding-json-schema/reference/string#resource-identifiers, allow to provide resourceMediaType and resourceSchema following the same rules like contentMediaType and contentSchema.

Describe alternatives you've considered

I first thought about using contentMediaType and contentSchema, but this is meant for the content to be the string, not the string being the reference to it.
This might cause trouble with existing tooling.

Additional context

No response

@torsknod-the-caridian torsknod-the-caridian added the proposal Initial discussion of a new idea. A project will be created once a proposal document is created. label Nov 11, 2024
@gregsdennis
Copy link
Member

Thanks for the proposal. It sounds like you're suggesting that we provide the media type of a secondary resource that they'd need to fetch (e.g. from another server). If that's the case,

  1. The server should return the correct media type for the content its serving. Any indication of the media type in the schema would be at best redundant and at worst wrong.
  2. We discourage implementations from automatically fetching external resources (even schemas through $ref) for various reasons, including some security concerns. It seems you're suggesting this would be a user/client action rather than the implementation, but it's still something to be aware of.

If the schema implementation itself isn't supposed to do anything with these hints, I recommend just adding an annotation keyword. In 2020-12, you can use any keyword, and it will be ignored by the implementation; moving forward, you'll need to prefix the keyword with x- to get the same effect. (The content* keywords are all annotations as well.)

@jdesrosiers
Copy link
Member

It's a little unclear from your description, but it sounds like what you're looking for is JSON Hyper-Schema. Specifically, you're looking for targetMediaType and targetSchema. As Greg, pointed out, the HTTP response is the authority of the actual media type and schema and these keywords are just hints, but hints can be useful sometimes.

We're working on some friendly getting-started type documentation for JSON Hyper-Schema, but for now all we have is the specification which can be a bit dense. If you want to provide a simple example of the kind of thing you're doing, I'd be happy to show how you could express it using JSON Hyper-Schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Initial discussion of a new idea. A project will be created once a proposal document is created.
Projects
None yet
Development

No branches or pull requests

3 participants