swagger-js
swagger-js copied to clipboard
Incorrect request body when 'multipart/mixed' is used
Q&A (please complete the following information)
- OS: Windows, macOS
- Environment: Nodejs 12, any browser
- Method of installation: npm
- Swagger-Client version: 3.18
- Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration
Swagger/OpenAPI definition:
requestBody:
description: .....
content:
application/json:
schema:
$ref: 'certificate.yaml#/Certificate'
multipart/mixed; boundary=BOUNDARY:
schema:
type: object
properties:
CertificateBody:
$ref: '#/Certificate'
CerificateContent:
type: string
format: binary
required: true
Swagger-Client usage: Default configuration, just use a definition containing multipart/mixed
Describe the bug you're encountering
Multipart/mixed request is broken. When used, the request body is JSON and not multipart. It was working prior to version 3.10.6. All later versions including the latest have the same behavior.
To reproduce...
Steps to reproduce the behavior:
- Compose a yaml using OpenAPI 3.0 and use multipart/mixed content type. Use two parts - one JSON, and the other string/binary.
- Add the yaml in swagger url
- Fill the JSON/file parts of the request and execute
Expected behavior
The request body should be multipart.
Current behavior
The request body is JSON and the request fails.
Screenshots
Additional context or thoughts
I think the issue is caused by this commit: https://github.com/swagger-api/swagger-js/commit/651e85713c90345508c3d32bfef63cba7fce7c5c The condition for multipart/ is changed to 'multipart/form-data' which results in non-working multipart/mixed.
Hi @plamen-dzhorev,
Could you please show the code you used to issue a multipart/mixed request?
According to my research it never worker with proper syntax nor semantics.
This is test on [email protected]:
const client = await SwaggerClient({ url: "https://gist.githubusercontent.com/char0n/26963c407fbc6c053913e903132c3ace/raw/af0b57672f0820971664ab8c0aef69101f65ba7e/openapi.yaml" });
const result = await client.apis.pet.addPet({}, {
requestContentType: 'multipart/mixed; boundary=BOUNDARY',
requestBody: {
CertificateBody: 'body',
CertificateContent: 'binary content',
}
});
This would just create a request with content type of multipart/mixed; boundary=BOUNDARY, but the proper MIME boundaries were never generated and made the request invalid multipart/mixed requets.
@plamen-dzhorev please correct me if I'm wrong on these asumptions.