-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[typescript] Dates are reported as Date type in model but not serialized #926
Comments
@Fredx87 you are right, dates should be deserialized or the type should be string. <configuration>
<language>typescript-angular</language>
...
<typeMappings>
<typeMapping>DateTime=string</typeMapping>
</typeMappings>
</configuration> But I think the type should be changed to string by default. Or maybe there is an easy way to deserialize the string into |
I added support for this in my fork on #569 today. It serializes and deserializes dates based on I think any work in #802 should make use of date format specifiers and allow a wider range of date strings to work, as well as a flag to disable automatic date handling (i.e. use strings instead) for users with complex use-cases. |
fixed with #569 |
@macjohnny, the original issue reported here mentions both |
With typescript-angular there is no serialization/deserialization, so you need to add a typemapping and map it to strong, as mentioned above. |
I believe the typemapping for date / date-time must be |
@amakhrov I agree, only generators that implement a conversion should use Date |
This issue is still not fixed if you use withoutRuntimeChecks in typescript-fetch. |
We are using |
I still have the issue with |
This issue still seems to persist for arrays of date-time formatted strings. (Using the docker version 6.2.1). Should anyone else stumble upon this issue using the CLI version instead of maven, you can still "fix" this by appending |
This remains a problem!! I have an object definition as follows: {
"required": [
"summary",
"dates"
],
"type": "object",
"properties": {
"summary": {
"title": "Summary",
"type": "string",
"minLength": 1
},
"dates": {
"type": "array",
"items": {
"type": "string",
"format": "date"
}
}
}
} The resulting export function NoteSummarizationEntryFromJSONTyped(
json: any,
ignoreDiscriminator: boolean
): NoteSummarizationEntry {
if (json === undefined || json === null) {
return json;
}
return {
summary: json["summary"],
dates: json["dates"],
};
} It should instead do something along the lines of... export function NoteSummarizationEntryFromJSONTyped(
json: any,
ignoreDiscriminator: boolean
): NoteSummarizationEntry {
if (json === undefined || json === null) {
return json;
}
return {
summary: json["summary"],
dates: json["dates"].map((date: string) => new Date(date)),
};
} |
I just ran into this problem myself, so it's still not fixed. Dates in my responses were throwing errors because they were actually strings. |
Description
When the format of a string property of a model is "date-time" or "date", the generated model in Typescript have that property of
Date
type, but no conversion is performed after the fetch of the response, so that property is actually astring
. I've tried both withtypescript-angular
andtypescript-fetch
.openapi-generator version
3.2.2
OpenAPI declaration file content or url
Command line used for generation
Suggest a fix/enhancement
There are two possible solutions:
javascript
generator (with the functionconvertToType
)string
as a type fordate-time
anddate
propertiesI think that the first solution is the most convenient for the end user, but it is no very simple to implement. I would implement it once for every typescript generator (issue #802). For now, the second solution should be used.
The text was updated successfully, but these errors were encountered: