Im using OpenApi Generator to create services and models for my angular project.
This is an example of my Json:
"uploadDate" : {
"type" : "string",
"description" : "Data caricamento",
"format" : "date-time"
},
When I generate the files uploadDate is converted to String instead of Date.
See:
/**
* Data caricamento
*/
uploadDate?: string;
Is there a way to add a configuration and create models with Date as a type where format is date-time?
This is the script that I use to launch the generation:
"generate": "openapi-generator-cli generate -g typescript-angular -i openapi.json -o ./generated-sources/client"
Fixed by adding: --type-mappings=DateTime=Date
You need to specify the type mapping: it lets you use alternative Date libraries. You either provide this argument to your command:
$ openapi-generator-cli generate -g typescript \
--type-mappings=DateTime=Date \
--config openapi.config.json
Or add it to your config JSON:
{
// ...
"typeMappings": {
"DateTime": "Date"
}
}
There is, however, an issue here: your models would say field: Date, but they will contain a string. OpenAPI-generator won't construct Date objects :(
See issues:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With