-
Notifications
You must be signed in to change notification settings - Fork 215
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
Multiple Content-Type body contents are not handled #3377
Comments
In our specific use-case (Apicurio Registry REST API) there may be two separate issues:
In our case we have a single operation with both of these things! Here are three examples in order of (1) and then (2) above, and finally a combination. Multiple Media Types openapi: 3.0.2
info:
title: Multiple Input Types API
version: 1.0.0
paths:
/widgets:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Widget'
application/vnd.widget.extended+json:
schema:
$ref: '#/components/schemas/ExtendedWidget'
required: true
responses:
'201':
description: Widget successfully created.
operationId: createWidget
summary: Create a widget
description: Creates a widget (either normal or extended).
components:
schemas:
Widget:
type: object
properties:
id:
format: int32
type: integer
name:
type: string
ExtendedWidget:
type: object
properties:
id:
type: string
name:
type: string
description:
type: string
keywords:
type: array
items:
type: string File Upload : openapi: 3.0.2
info:
title: File Upload API
version: 1.0.0
paths:
/files:
post:
requestBody:
content:
'*/*':
schema:
$ref: '#/components/schemas/FileContent'
required: true
responses:
'201':
description: Returned when a file is successfully uploaded.
operationId: uploadFile
summary: Upload a file
components:
schemas:
FileMetaData:
type: object
properties:
uploadedOn:
format: date-time
type: string
uploadedBy:
type: string
size:
format: int32
type: integer
contentType:
type: string
FileContent:
format: binary
description: ''
type: string Putting Them Together openapi: 3.0.2
info:
title: All Together API
version: 1.0.0
paths:
/files:
post:
requestBody:
content:
'*/*':
schema:
$ref: '#/components/schemas/FileContent'
application/vnd.file.extended+json:
schema:
$ref: '#/components/schemas/FileUpload'
required: true
responses:
'201':
description: File successfully uploaded.
operationId: uploadFile
summary: Upload a file
description: Upload a file.
components:
schemas:
FileContent:
format: binary
description: ''
type: string
FileUpload:
type: object
properties:
name:
type: string
content:
type: string |
Thanks for bringing this up. But focusing on the content types here, I think there are multiple questions:
With that context in mind the challenges we're trying to solve for in #2317 are:
We don't have immediate plans to solve for this now as this is limited to a small APIs subset as far as we've observed. But we're eager to read what you might propose. |
This is definitely related to #2317 , thanks for pointing it out, and it will be nice to hear from @darrelmiller as well. I understand that those changes are going to impact the generated code size, and I don't have a good way to quantify it, we should probably experiment a bit here. As per the encoding, I think that we should keep the current direct style on the "happy path" as it is today, one possibility would be to generate one single additional method that takes an extra parameter, being it the specific content type in a But this is just "on top of my head", let's see what @EricWittmann comes up with 🙂 |
Request Body with
|
I like @darrelmiller proposal very much:
What is still missing is how this will look from the user/code perspective. |
@andreaTP fox context this is the outcome of a brainstorm we were having yesterday. We still have cases that are not described here: when the schemas are not the same. And we still have to solve how to detect schemas are the same or different. But I believe this first set of cases could be a good first stop as an improvement over the current implementation. During our implementation we could assume schemas are the same, knowing some edge cases wouldn't work just yet, and solve for those later on. To answer your questions:
Only in the case the intersection between structured types and request body described types yields an empty set, and we have multiple described types. In that case, the executor and the generator methods would have an additional parameter for the content type. In the similar case but for the response, the generated code will send application/octet-stream, people can override it (c.f. the other issue). Requesting people to provide it all the time would be additional friction for cases we have enough information for. The structured types is set by default in the appsettings of kiota, and can be changed through the relevant command line argument. (and we still have to find a place for that in the vscode extension)
I'm not sure how encoding is relevant in this discussion? Did you mean content type? if so in which case?
With the assumption of this scenario (the schema matches for all content types, or it's an un-schematized payload), we don't need to. For the Accept, the generated code can just set the intersection with the preference weight (as RFC 9110 plans for). For the Content-Type, same logic applies, only the generator select the most preferred one. The troubles come when the schemas diverge for different content types (we still have to solve for that). Also all the scenarios above make the assumption that if we have both a schematized content type and an unschematized content type for the same operation, the schematized type will take precedence and the unschematized one will be ignored. |
Moved to 1.8 for now so we consider it during our next planning session. We'll probably create another issue for the less trivial cases where the schemas don't match once we have a design for that. |
Thanks a lot for taking this one on you @baywet ! Much appreciated! |
Description
When an OpenAPI description defines endpoints with > 1 content types for the body content, only the first
application/json
ish entry is handled by the SDK.Repro
Given a minimal OpenAPI such as:
We can observe that the only generated
PostRequestInformation
contains this line (in Java but similar in other languages):Questions
Is it a deliberate choice? I'm failing at finding references in the docs.
Would it be possible to generate multiple
toPostRequestInformation
methods to cover all of theContent-Type
s handled by the server? Cannot find another issue referring to this limitation.Do you have an idiomatic way to work around the current behavior other than fixing the
RequestInformation
object before sending it through theadapter
?Should the(current) implementation give precedence to
application/json
and, only if not found, apply cleaning?Thoughts?
The text was updated successfully, but these errors were encountered: