openapi-typescript-codegen
openapi-typescript-codegen copied to clipboard
Add support for the `explode` query parameters
I don't see that the explode
definitions have any connection in the code currently.
Is it possible to add this support specified here: https://swagger.io/docs/specification/serialization/#query
What would be nice that the service API would expose an explode
parameters as id: Array<number>
instead of the id: number
it is currently generated, so that you can easily pass multiple values.
@sjoerdmulder Yes, great idea, we have a similar problem with the FormData. See the ticket here: https://github.com/ferdikoomen/openapi-typescript-codegen/issues/658 I haven't prioritised this, since most projects I'm working on use JSON bodies for FormData and 'default' encoding for query params.
Great I already have some POC code ready, will prepare a PR later this week
Op di 27 apr. 2021 13:41 schreef Ferdi Koomen @.***>:
@sjoerdmulder https://github.com/sjoerdmulder Yes, great idea, we have a similar problem with the FormData. See the ticket here: #658 https://github.com/ferdikoomen/openapi-typescript-codegen/issues/658 I haven't prioritised this, since most projects I'm working on use JSON bodies for FormData and 'default' encoding for query params.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ferdikoomen/openapi-typescript-codegen/issues/654#issuecomment-827540883, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABZRYIQU2HHT5L43HE53TDTK2PHRANCNFSM42YXNLFA .
@sjoerdmulder Cool, you probably already found these, but still good to mention:
Swagger (version 2)
-
parameterObject
allows you to set thecollectionFormat
to control the formatting: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterObject
OpenAPI (version 3)
-
requestBody
allows you to control formatting with properties likestyle
,explode
,allowReserved
: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#encodingObject -
parameter
has similar propertiesstyle
,explode
,allowReserved
: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#parameterObject
I would probably create the options for OpenAPI (version 3) and then see how to map then to the collectionFormat
prop in the older Swagger format (version2).
Hey @ferdikoomen @sjoerdmulder , I have problem that is most likely related to this. Codegen incorrectly transforms the following:
- in: query
name: status__in
schema:
type: array
items:
type: number
description: Multiple values may be separated by commas.
explode: false
style: form
into e.g.: ...?status__in=2&status__in=3
... While the correct one should be status__in=2,3
.
The problem is described here as well (https://github.com/tfranzel/drf-spectacular/issues/599) with the explanation. Right now I need to hardcode the status__in
parameter as comma-separated stringified values to have the query params value in correct format. Do you plan to implement this feature please? Thank you for any info, appreciate your work.