You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a reusable definition for an array of dates, the Dart code generator interprets the schema as a custom type and incorrectly generates the following code:
This is generated even when the schema references an array definition meant to represent an array of date strings. The expected generated code should ideally convert a list of date-time formatted strings into DateTime objects similar to:
Ensure the schema is used by the generator (via Swagger or similar tooling that feeds into the Dart generator).
Run the code generation process.
Observed Behavior:
The generator outputs conversion code that calls a non-existent static method DateTime.listFromJson and falls back to a generic Iterable cast:
This behavior is problematic because it does not parse the strings into DateTime objects as expected. Expected Behavior:
The generator should interpret the schema correctly, especially when the items are defined as date-time formatted strings, and generate conversion code that transforms each item via DateTime.parse(e as String). Workarounds Tried:
Changing the item type definition explicitly to a string with a date-time format:
Adding vendor extensions like x-dart-type with List<DateTime> as its value.
Neither approach resulted in the expected code generation. Environment:
Generator Tool Version: (specify your version, if applicable)
Dart version: (specify)
Project: FeathersJS/Swagger setup
Relevant Schema and Service Code: (as described above)
Additional Context:
This issue affects our ability to rely on the generated code to correctly convert date strings into DateTime objects. If the generator's behavior could be modified—either through improved schema inference, vendor extensions, or customization of templates—it would significantly ease integration for users expecting proper DateTime parsing.
Any guidance or fixes for this scenario would be greatly appreciated!
Steps to reproduce
Steps to Reproduce:
Define the JSON schema for a model with an array property as follows:
Create a reusable definition for ArrayOfDates with:
The generator should interpret the schema correctly, especially when the items are defined as date-time formatted strings, and generate conversion code that transforms each item via DateTime.parse(e as String).
The expected generated code should ideally convert a list of date-time formatted strings into DateTime objects similar to:
GianlucaCesari
changed the title
"ArrayOfDates":{"title":"ArrayOfDates","type":"array","items":{"type":"string","format":"date-time"}}
Incorrect Code Generation for DateTime Arrays Using $ref Definition
Apr 7, 2025
It is known issue of openapi-generator OpenAPITools/openapi-generator#13432
You can wait they fix it or simple use Generator.dio which use built_value with so much more powerful.
Description of the bug
When using a reusable definition for an array of dates, the Dart code generator interprets the schema as a custom type and incorrectly generates the following code:
This is generated even when the schema references an array definition meant to represent an array of date strings. The expected generated code should ideally convert a list of date-time formatted strings into DateTime objects similar to:
Steps to Reproduce:
ArrayOfDates
with:Observed Behavior:
The generator outputs conversion code that calls a non-existent static method
DateTime.listFromJson
and falls back to a generic Iterable cast:This behavior is problematic because it does not parse the strings into DateTime objects as expected.
Expected Behavior:
The generator should interpret the schema correctly, especially when the items are defined as date-time formatted strings, and generate conversion code that transforms each item via
DateTime.parse(e as String)
.Workarounds Tried:
x-dart-type
withList<DateTime>
as its value.Neither approach resulted in the expected code generation.
Environment:
Additional Context:
This issue affects our ability to rely on the generated code to correctly convert date strings into DateTime objects. If the generator's behavior could be modified—either through improved schema inference, vendor extensions, or customization of templates—it would significantly ease integration for users expecting proper DateTime parsing.
Any guidance or fixes for this scenario would be greatly appreciated!
Steps to reproduce
Steps to Reproduce:
ArrayOfDates
with:Minimal openapi specification
Annotation used
Expected behavior
The generator should interpret the schema correctly, especially when the items are defined as date-time formatted strings, and generate conversion code that transforms each item via
DateTime.parse(e as String)
.The expected generated code should ideally convert a list of date-time formatted strings into DateTime objects similar to:
Logs
Screenshots
No response
Platform
macOS
Library version
5.0.2
Flutter version
3.19.6
Flutter channel
stable
Additional context
The text was updated successfully, but these errors were encountered: