swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
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()}.
Description
The generated client does not format any date-time that is part of an operation path.
For an endpoint with this path:
An example request (as generated by the client) would look like this:
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:
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()}
.