swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.04k stars 6.03k forks source link

[Typescript-angular2] Date in path is not correctly formatted for typescript-angular2 client #4813

Open colinbreame opened 7 years ago

colinbreame commented 7 years ago
Description

The generated client does not format any date-time that is part of an operation path.

For an endpoint with this path:

/api/value/{date}/{id}

An example request (as generated by the client) would look like this:

http://localhost:5000/api/value/Thu%20Feb%2016%202017%2020:57:11%20GMT+0000%20(GMT%20Standard%20Time)/1

Swagger-codegen version

2.2.2-SNAPSHOT with HEAD as 0d14496bd6fbdbd763844f239b34e198459fe4d9

Swagger declaration file content or url

{"swagger":"2.0","info":{"version":"v1","title":"API V1"},"basePath":"/","paths":{"/api/category":{"get":{"tags":["Tracker"],"operationId":"ApiCategoryGet","consumes":[],"produces":["application/json"],"responses":{"200":{"description":"Success","schema":{"type":"array","items":{"$ref":"#/definitions/Category"}}}},"deprecated":false}},"/api/metric":{"get":{"tags":["Tracker"],"operationId":"ApiMetricGet","consumes":[],"produces":["application/json"],"responses":{"200":{"description":"Success","schema":{"type":"array","items":{"$ref":"#/definitions/Metric"}}}},"deprecated":false},"post":{"tags":["Tracker"],"operationId":"ApiMetricPost","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"metric","in":"body","required":false,"schema":{"$ref":"#/definitions/Metric"}}],"responses":{"200":{"description":"Success","schema":{"format":"int64","type":"integer"}}},"deprecated":false}},"/api/value/{date}/{metricId}":{"put":{"tags":["Tracker"],"operationId":"ApiValueByDateByMetricIdPut","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"metricId","in":"path","required":true,"type":"integer","format":"int64"},{"name":"date","in":"path","required":true,"type":"string","format":"date-time"},{"name":"value","in":"body","required":false,"schema":{"format":"double","type":"number"}}],"responses":{"200":{"description":"Success","schema":{"format":"int64","type":"integer"}}},"deprecated":false}}},"definitions":{"Category":{"type":"object","properties":{"categoryId":{"format":"int32","type":"integer"},"name":{"type":"string"}}},"Metric":{"type":"object","properties":{"metricId":{"format":"int32","type":"integer"},"name":{"type":"string"},"categoryId":{"format":"int32","type":"integer"},"type":{"type":"string"},"text":{"type":"string"}}}},"securityDefinitions":{}}

Command line used for generation

generate -l typescript-angular2 -o src/services/api/ -i http://localhost:5000/swagger/v1/swagger.json

Steps to reproduce

Generate the client then call the method "apiValueByDateByMetricIdPutWithHttpInfo" within TrackApi.

Related issues
Suggest a Fix

The problem is being caused by how a date-time is formatted within the generated code. So for the example above, the client looks like this:

public apiValueByDateByMetricIdPutWithHttpInfo(metricId: number, date: Date, value?: number, extraHttpRequestParams?: any): Observable<Response> {
        const path = this.basePath + `/api/value/${date}/${metricId}`;

The problems is that ${date} returns the human readable string. What we want is the machine readable string format which can be obtained with ${date.toISOString()}.

richwinstanley commented 7 years ago

I am also seeing this issue. Is there currently any plan to fix it?