-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
Description
Hi,
I have the following problem when using a Date-Array-Parameter in my swagger file:
The generated client is not serializing the dates correctly and the server is returning Bad request: Validation errors
.
For example:
The client generates: createdAfter= Thu%20Mar%2008%202018%2015:56:22%20GMT%2B0100%20(CET), Thu%20Mar%2008%202018%2015:56:22%20GMT%2B0100%20(CET),
instead of;
createdAfter=2018-03-08T15:56:22Z,2018-03-08T15:56:22Z
Everything is working perfectly fine, if I only have a single date-query-parameter.
Swagger-codegen version
2.3.1
Swagger declaration file content or url
This is the relevant part of my swagger file:
parameters:
- name: createdAfter
in: query
required: false
type: array
items:
type: string
format: date-time
Command line used for generation
java -jar libs/swagger-codegen-cli-2.3.1.jar generate -i src/api/swagger/swagger.yaml -l typescript-angular -o ~/swaggerGeneratedCode/typescript-angular/ --additional-properties=modelPropertyNaming=original
Suggest a fix/enhancement
I think, I already found the problem.
This is my generated code:
queryParameters = queryParameters.set('createdAfter', createdBefore.join(COLLECTION_FORMATS['csv']));
We have to call toISOString()
. So it should be something like:
queryParameters = queryParameters.set('createdAfter', createdAfter.map((i) => i.toISOString()).join(COLLECTION_FORMATS['csv']));
This line in the template is generating the wrong code:
swagger-codegen/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache
Lines 146 to 148 in f00a1ef
{{^isCollectionFormatMulti}} | |
{{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])); | |
{{/isCollectionFormatMulti}} |
A check is already there for single date-parameters a few lines below:
swagger-codegen/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache
Lines 153 to 155 in f00a1ef
{{#isDateTime}} | |
{{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.set('{{baseName}}', <any>{{paramName}}.toISOString()); | |
{{/isDateTime}} |
So I guess, in case of date-array-params the template code should be something like:
{{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.set('{{baseName}}', {{paramName}}.map((i) => i.toISOString()).join(COLLECTION_FORMATS['{{collectionFormat}}']));
(just added .map((i) => i.toISOString())
)
What is missing for a fix, is a test for the child-elements of the listContainer
if they are of type date
. I have no idea how to implement that in mustache-templates.
Please help and thanks in advance.