Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenApi string field with format date has bad path in generated typescript #117

Closed
bhoudu opened this issue May 26, 2020 · 2 comments · Fixed by #131
Closed

OpenApi string field with format date has bad path in generated typescript #117

bhoudu opened this issue May 26, 2020 · 2 comments · Fixed by #131
Labels
bug Something isn't working good first issue Good for newcomers language: typescript 2.0 Typescript language template for Swagger 2.0 spec language: typescript 3.0 Typescript language template for OpenAPI 3.0 spec

Comments

@bhoudu
Copy link

bhoudu commented May 26, 2020

There is an error on the path generated :

import { DateFromISODateStringIO } from '../utils/utils';

And it should be :

import { DateFromISODateStringIO } from '../../utils/utils';
@bhoudu
Copy link
Author

bhoudu commented May 26, 2020

After toying with quick fixes, it seems, DateFromISODateStringIO should not be generated at all in utils.

I feel the io-ts implementation is what is required :

import { DateFromISOString } from 'io-ts-types/lib/DateFromISOString'

@raveclassic raveclassic added bug Something isn't working language: typescript 2.0 Typescript language template for Swagger 2.0 spec language: typescript 3.0 Typescript language template for OpenAPI 3.0 spec good first issue Good for newcomers labels Jun 9, 2020
@Lonelind
Copy link
Contributor

Lonelind commented Sep 10, 2020

After toying with quick fixes, it seems, DateFromISODateStringIO should not be generated at all in utils.

I feel the io-ts implementation is what is required :

import { DateFromISOString } from 'io-ts-types/lib/DateFromISOString'

The DateFromISODateStringIO codec was made to accommodate the specified date data type instead of date-time which is covered by io-ts's DateFromISOString.

The reason is that the Date object in JS always represents date-time. There is no specific object which would work with dates separately but there is a Date(year, month, day) constructor which omits the time information that will always be present if you try to create a Date instance using ISO string constructor. Specifically, if you don't specify the time it will be set as 00:00 UTC which is not the desired behavior when you work with dates only.

The DateFromISOString codec, on the other hand, always uses ISO constructor and can't be used to represent the date data type because of the described behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers language: typescript 2.0 Typescript language template for Swagger 2.0 spec language: typescript 3.0 Typescript language template for OpenAPI 3.0 spec
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants