swagger-api / swagger-api/swagger-codegen
[DART] Parsing null DateTime to JSON
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I'm not sure yet if this is a bug, or if I'm doing something wrong.
I've checked the dart/class.mustache file, and I think there lies the problem. When parsing a null DateTime property to json, it sets as an empty String. If I try to parse the generated json string, I get an exception when trying to DateTime.parse because the empty string is not an valid date.
Swagger-codegen version
2.4.2
Swagger declaration file content or url
{
"type": "object",
"properties": {
"dateExample": {
"type": "string",
"format": "date-time",
"description": "DateExample",
"allowEmptyValue": false
}
},
"title": "ExampleModel",
"description": "Response model"
}
Command line used for generation
java -jar /swagger-codegen-cli.jar generate -i swagger.json -l dart -o sdk/dart -c deploy/swagger-generator.json -DbrowserClient=false
Steps to reproduce
- Generate a dart client having a model with a date property
- Parse the example model to json
- Parse the given json back to the model. The error should occur now, as mentioned before, from a "DateTime.parse"
Related issues/PRs
Suggest a fix/enhancement
to:
{{#isDateTime}}'{{name}}': {{name}} == null ? null : {{name}}.toUtc().toIso8601String(){{^-last}},{{/-last}}{{/isDateTime}}{{^isDateTime}}'{{name}}': {{name}}{{^-last}},{{/-last}}{{/isDateTime}}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with modules/swagger-codegen/src/main/resources/dart/class.mustache at the referenced line and generate a Dart client using the provided command and schema. Reproduce the null DateTime serialization and round-trip described in the issue; done means the generated JSON preserves a null date-time value and can be parsed back without a DateTime.parse exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100