-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Inconsistent curl generated for array of objects in multipart/form-data request #7625
Comments
@wojtekm462 Any secret knowledge you've obtained in the meantime that you might share with me? I'm experiencing the same issue and haven't managed to dig out a solution |
Hi, I faced the same issue, did you find any working solution? |
@RedMickey I think I managed to find a workaround in Nest using Let me know in return if you figure out how to handle multipart file uploads in nested properties! 🤣 e.g. EDIT: adding the relevant code snippet in case I ever ruin the link above. What this code does is: if the property is of type string, turn it into an array. This essentially takes care of the faulty Swagger handling and ignores all other situations. @ArrayUnique()
@Type(() => String)
@ApiProperty({ type: [String] })
@Transform(({ value }: { value: string[] | string }) => {
if (typeof value === 'string') {
return value.split(',');
} else return value;
})
hashlist: string[];
} |
Hi @josip-volarevic thanks for you reply. I managed to find the following solution:
If I specify encoding options, then the swagger splits the array properly on sending. My workaround is based on this comment. So, in the request body I get the following:
|
@RedMickey don't you now have issues with the |
Hi,
Curl command generated for a request with multipart/form-data is inconsistent/mixed.
Having array of objects as form field in multipart/form-data request. Each array object is JSON object.
First element is properly presented in curl command without stringify operation applied.
Any array object added as result of "Add object item" button is stringified and ends as string, not an object.
Issue spotted when working on project using Python 3.8, Connexion 2.9.0, swagger-ui bundle 0.0.9 but can be reproduced on editor.swagger.io as well.
Q&A (please complete the following information)
Content & configuration
Given below example Swagger/OpenAPI definition:
Swagger-UI configuration options: None
Describe the bug you're encountering
Produced curl command from editor.swagger.io is as follows:
property2 is the array where first element is true JSON object, but second one is plain string and not object according to schema.
In case of input validation to the API specification as is in Connexion framework the second of stringified JSON object does not pass the JSON schema validation and request is rejected.
To reproduce...
Steps to reproduce the behavior:
Expected behavior
Expected curl for array of objects shall be like first element, without stringified contents of elements added with 'Add object item'
Screenshots
Additional context or thoughts
Generated curl does not respect the supplied encoding in request body by not specifying the form fields with ';type='
Proper curl coding of array of JSON objects would be:
The text was updated successfully, but these errors were encountered: