Description
We are using the JavaScript code generator in combination with browserify. It brings us some benefits to have some "static code"-generation for JavaScript. The problem is that the date parsing function is not working for all browsers. Not all browsers have proper ISO-8601 parsing capabilities. Only Chrome parses the dates correctly.
|
{{/emitJSDoc}} exports.parseDate = function(str) { |
Swagger-codegen version
2.1.6
Swagger declaration file content or url
Any date-time parameter. e.g. http://petstore.swagger.io/#!/store/getOrderById
Command line used for generation
java -jar swagger-codegen.jar generate -i http://petstore.swagger.io/v2/swagger.json -l JavaScript - o jsclient
cd jsclient
npm install
cd ..
browserify jsclient\src\index.js -o client.js --standalone PetStoreClient
Steps to reproduce
- Generate the client
- Use the client.js in the browser to make a call to
getOrderById
- Inspect the shipDate
Related issues
No
Suggest a Fix
One solution could be to use moment.js to parse the date. An other solution might be to parse the ISO date manually with some regex.
https://www.safaribooksonline.com/library/view/javascript-cookbook/9781449390211/ch03s05.html
Considering only IE9 and higher all browsers support out of the box ISO8601 parsing. This means even new Date(str) would work.
Description
We are using the JavaScript code generator in combination with browserify. It brings us some benefits to have some "static code"-generation for JavaScript. The problem is that the date parsing function is not working for all browsers. Not all browsers have proper ISO-8601 parsing capabilities. Only Chrome parses the dates correctly.
swagger-codegen/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache
Line 413 in 8f258b9
Swagger-codegen version
2.1.6
Swagger declaration file content or url
Any date-time parameter. e.g. http://petstore.swagger.io/#!/store/getOrderById
Command line used for generation
swagger-codegen/samples/client/petstore/javascript/src/ApiClient.js
Line 397 in 8f258b9
Steps to reproduce
getOrderByIdRelated issues
No
Suggest a Fix
One solution could be to use moment.js to parse the date. An other solution might be to parse the ISO date manually with some regex.
https://www.safaribooksonline.com/library/view/javascript-cookbook/9781449390211/ch03s05.html
Considering only IE9 and higher all browsers support out of the box ISO8601 parsing. This means even
new Date(str)would work.