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

Compose all component types, not just schemas #2936

Open
k98kurz opened this issue May 31, 2022 · 4 comments
Open

Compose all component types, not just schemas #2936

k98kurz opened this issue May 31, 2022 · 4 comments
Labels
re-use: ref-group-combine Re-use requests involving grouping components and combining groups

Comments

@k98kurz
Copy link

k98kurz commented May 31, 2022

The current state of affairs is that responses can be defined as components and referenced with the "$ref":"{uri}" syntax, but these cannot be composed using the allOf directive. Trying to do so results in an error. Adding sibling properties also results in an error. So there is currently no way to define a response with a general schema and then add endpoint-specific models or examples. This seems like a gross oversight and major limitation.

For example, let's say that there are multiple endpoints that return lists of models following a standard response format, but each endpoint returns different models. It would be ideal to keep the reusable format of the response in a response component and compose it with the specific model under the path definition.

Without this functionality, the only options are to have invalid documents or abandon the use of response components.

@darrelmiller
Copy link
Member

This was not an oversight. It is an intentional design choice based on years of conversations on how to resolve the semantics of merging one or more objects together. JSON Schema is able to support constructions of all of by categorizing members into either annotations, whose behavior is application defined, or validators that are independent constructs that return a boolean value which can be safely merged for an aggregate result.
OpenAPI concepts such as Response Objects are not so easily aggregated.
I have yet to see an example of a polymorphic response that could not be efficiently described with a single response object and a flexible schema.

@k98kurz
Copy link
Author

k98kurz commented Jun 21, 2022

... I have yet to see an example of a polymorphic response that could not be efficiently described with a single response object and a flexible schema.

@darrelmiller How? What am I missing?

@faelin
Copy link

faelin commented Aug 9, 2022

@k98kurz – To facilitate communication, could you provide a counter-argument describing a response object that would be hard to describe using "a single response object and a flexible schema"?

(to be clear, I am not challenging the possibility of such an issue, but I wish to facilitate clear conversation)

@handrews
Copy link
Member

handrews commented Nov 6, 2022

@k98kurz you might be interested in the referencing proposals that are just getting started right now. The JRI proposal grapples with the problem of composing references (which it calls "keyword semantics") vs references that just replace the object containing $ref (which it calls "object semantics").

it is a difficult topic that poses challenges for generic tooling.

@handrews handrews added $ref re-use: ref-group-combine Re-use requests involving grouping components and combining groups and removed $ref labels Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
re-use: ref-group-combine Re-use requests involving grouping components and combining groups
Projects
None yet
Development

No branches or pull requests

4 participants