Use case
I'm working with an API where some fields use type: string, format: date (date only) and others use type: string, format: date-time (full timestamp). The issue is that the parser maps both to DateTime in Dart.
This is causing a real problem in requests: whether it's a request body, path param, or query param. When I pass a DateTime for a date field, it serializes with time and timezone info (e.g. 2026-06-07T00:00:00.000Z), but the backend strictly expects yyyy-MM-dd. This leads to backend validation failures.
The OpenAPI spec explicitly defines date and date-time as separate formats for this exact reason, but the generated client treats them the same. I don't want to fork the package or run post-processing scripts on generated files just to handle this.
What I need is a way to override the Dart type on specific fields so I can point date fields to a custom class that serializes correctly.
Proposal
Support a vendor extension x-dart-type on schema properties that overrides the generated Dart type for that field. For example:
birthDate:
type: string
format: date
x-dart-type: LocalDate
Would generate:
final LocalDate birthDate;
From what I can see in the code, the implementation should be fairly minimal: in _findType inside open_api_parser.dart, check for map['x-dart-type'] and if present, use it as the type in UniversalType. The toDartType() method already has a _ => this fallthrough for unrecognized types, so it would pass the custom type through cleanly without needing changes elsewhere.
I'm happy to implement this and open a PR if this direction looks good.
Use case
I'm working with an API where some fields use
type: string, format: date(date only) and others usetype: string, format: date-time(full timestamp). The issue is that the parser maps both toDateTimein Dart.This is causing a real problem in requests: whether it's a request body, path param, or query param. When I pass a
DateTimefor adatefield, it serializes with time and timezone info (e.g.2026-06-07T00:00:00.000Z), but the backend strictly expectsyyyy-MM-dd. This leads to backend validation failures.The OpenAPI spec explicitly defines
dateanddate-timeas separate formats for this exact reason, but the generated client treats them the same. I don't want to fork the package or run post-processing scripts on generated files just to handle this.What I need is a way to override the Dart type on specific fields so I can point
datefields to a custom class that serializes correctly.Proposal
Support a vendor extension
x-dart-typeon schema properties that overrides the generated Dart type for that field. For example:Would generate:
From what I can see in the code, the implementation should be fairly minimal: in
_findTypeinsideopen_api_parser.dart, check formap['x-dart-type']and if present, use it as the type inUniversalType. ThetoDartType()method already hasa _ => thisfallthrough for unrecognized types, so it would pass the custom type through cleanly without needing changes elsewhere.I'm happy to implement this and open a PR if this direction looks good.