OpenAPITools / OpenAPITools/openapi-generator
[BUG][Dart] ApiException 500: Exception during deserialization.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Issue:
When generating num.parse in native_class.mustache for a nullable num type, the following error occurs during deserialization:
Error while fetching
ApiException 500: Exception during deserialization. (Inner exception: FormatException: null)
A type is also nullable when "required" and "defaultValue" is false:
The problem is that this is not taken into account for num.parse:
Suggestion:
Change Lines:
{{{name}}}: {{#isNullable}}json[r'{{{baseName}}}'] == null
? {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}
: {{/isNullable}}{{{datatypeWithEnum}}}.parse('${json[r'{{{baseName}}}']}'),
With Lines:
{{{name}}}: {{#isNullable}}json[r'{{{baseName}}}'] == null
? {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}
: {{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}json[r'{{{baseName}}}'] == null
? {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}
: {{/defaultValue}}{{/required}}{{/isNullable}}{{{datatypeWithEnum}}}.parse('${json[r'{{{baseName}}}']}'),
openapi-generator version
7.10.0
OpenAPI declaration file content or url
{
"openapi": "3.0.1",
"components": {
"schemas": {
"Test": {
"required": [
"number",
"subNumber"
],
"type": "object",
"properties": {
"id": {
"type": "string",
"readOnly": true
},
"problem": {
"type": "number"
}
}
}
}
}
}
Steps to reproduce
Try to deserialize the object Test with OpenAPI and get Error for "problem" with type "number".
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 the num deserialization in native_class.mustache and reproduce the issue using the provided OpenAPI declaration, focusing on the nullable problem number field. Compare the generated Dart handling with the reported suggestion; done means deserializing an omitted nullable number no longer raises a FormatException.
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
- Mostly clear
- Newbie friendliness
- 45/100