-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Investigate multiple schema case (different mime types) in ModelUtils #144
Comments
@jmini I've tagged this as general discussion/suggestion. We don't have a tag for infrastructural code that affects all generators, and it wasn't clear to me if you're documenting a thought or looking for additional inputs (I agree that in OAS 3.0, you can end up with different models but it's not as easy in OAS 2.0). |
Hi there, I recently encountered these two warnings and find them rather annoying. That is: Although my input files are perfectly valid (from what I can tell), my build log contains these warnings, indicating that there is something wrong where afaik there isn't. Is it possible to suppress those warnings or get rid of them by any other means? |
Hi I am also getting this warning when i generate Apis from my yaml file. The thing is I am having text/csv or application/json contents for the same endpoint in order to avoid duplicate calls. It works perfectly fine for different response forms. But I find the warning annoying. So suppressing the warnings would be good. Any ideas? |
Hi, i'm facing the same issue but in request. |
Hi, I am also facing the same issue. Here is my swagger: I am getting the following response: Any help is appreciated. Thanks! |
@jmini , @jimschubert, IMO the easiest approach here would be to build CodegenOperation for each combination of possible request body Methods mentioned above will need to have additional |
@typhoon2k would you be able to provide an example of what you mean? The issues that I see are:
|
@jimschubert , let's use the following example: paths:
/person:
post:
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/SuperManA"
application/xml:
schema:
$ref: "#/components/schemas/SuperManA"
application/avro:
schema:
$ref: "#/components/schemas/SuperManB"
operationId: someOperation
responses:
'201':
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/SuperManA"
application/xml:
schema:
$ref: "#/components/schemas/SuperManB"
application/avro:
schema:
$ref: "#/components/schemas/SuperManB" Taking into account current situation (that many generators expect only one schema in request body and response) my idea was that we can generate 4 CodegenOperations:
I.e. expectation to have single request body and response is not broken. On your example with JSONifying response - I feel that this example works only for specific use cases, where only one response is defined (or maybe generator is reducing list of responses to only one 2xx response). Also it would be useful to include isJson/isXml/isBinary/etc into CodegenResponse to make sure that correct conversion is used. On your last item - unfortunately I don't have enough knowledge on those languages/frameworks, but if framework permits unique method/function names (generated using unique operationId) with duplicate paths & different content types, then that should work. If duplicate paths are not permitted, then this approach won't work. I consider proposed approach more as a workaround to reduce amount of necessary changes. |
@typhoon2k I'm assuming your example expects 1:1 matching with request and response content types? Again, that's not really something we can assume across the board due to content negotiation. For instance, a request can pass xml and accept json, while another expects xml+xml. We'd have to generate each permutation of these in some generators. What do you think about if we were to move the logic which grabs the first element of each of these lists into DefaultCodegen somewhere, and allow generators to pass all request/responses to templates? It would also allow generators that require it to generate transient operations with the additional parameters. That way we can phase this support rather than tackling as all-or-nothing. I think if we go that route, we could add a generator feature enum or two, like |
I was thinking about replacing all CodegenProperty related fields with Map<String, CodegenProperty> in CodegenParameter and CodegenResponse (i.e. map from content type to schema). As I said for backwards compatibility getters of replaced fields can return values of the same fields from first CodegenProperty in map. |
Thanks for working on the issue guys 👍 |
@jimschubert , I've reviewed dependencies that we have on |
@typhoon2k What's the status of this change? I'm currently developing an API that is versioned via the |
Hi, any updates on this change? |
I'm also curious about updates on this. |
In my opinion, content negotiation is a very basic concept of HTTP / REST. |
Any updates on this? Returning different schema based on accept header is common imo. We are currently forced to workaround this, which is not ideal, so it would be great if this was implemented. |
We're suffering from the same issue. What's the status of this issue after 2.5years? |
Any status of this? |
Are there any plans to implement this in the near future? IMO this is a bug. Why can't the OpenAPI Generator handle multiple content types? Other generators handle this correctly. I think having different content types in the requestBody is a common use case, e.g.: /api/item:
post:
operationId: addItem
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Item'
multipart/form-data:
schema:
type: object
properties:
item:
$ref: '#/components/schemas/Item'
file:
$ref: '#/components/schemas/InputStream' |
I have also problems to find a way to deal with that except breaking the REST principle by having multiple methods for multiple response content types. I'm also open for alternatives. |
In my case, at least, the client I want to generate only needs to support a single content type. However, "the first one" is not the one I want. Is there a way to specify which one to use?
Thanks for your assistance. |
Please start support content negotiation, it's one of the basic REST concepts. Should be on the high demand, imo |
Yes #10973 solves this problem; I am using it in this PR: #8325 to allow users to send request bodies with different body content types supported.
|
@spacether Just to extend your answer based on what I see. For Java, it's expected to be fixed with #6708 in |
@artemptushkin There is an extension for Java and / or Spring? I haven't found a PR yet? |
@MelleD I refer to this comment of @spacether #6708 (comment) so, I assume only so far. But I'd expect content-negotiation problem will be closed with #6708 |
any news about this? |
I've tried every typescript generator here but they all don't work for the multiple schema case: https://openapi-generator.tech/docs/generators/. I'm running this command:
I looked at the help message and other docs and can't find any relevant flags to enable this. Given the issue is closed I would expect this to work, am I missing something? |
The investigation is done. One generator has implemented multiple content types. The information is available for any other generators to use. This is an investigation ticket not an implementation ticket. |
In
ModelUtils
those two methods return a singleSchema
for aRequestBody
or aApiResponse
:ModelUtils.getSchemaFromRequestBody(RequestBody)
ModelUtils.getSchemaFromResponse(ApiResponse)
This feels wrong because when multiple Mime types are defined (like
application/json
orapplication/xml
) different Schemas can be returned.With #74 an additional warning log was added:
We should investigate on the impacts.
When multiple mime types are defined we might need to compare if the defined schema are different or not.
The text was updated successfully, but these errors were encountered: