dart_openapi_generator
Native-Dart, zero-Java OpenAPI 3.x → Dart code generator for Flutter and Dart.
Reads an OpenAPI 3.x spec (YAML or JSON, local file or HTTPS URL) and generates idiomatic
Dio-based model classes and API client services via build_runner. No JVM. No Mustache.
Generated code looks like a developer wrote it by hand.
Features
- Generates
final classmodel classes withfromJson,toJson,copyWith,==, andhashCode - Generates Dart
enumtypes withfromJson/toJsonswitch expressions - Generates
sealed classhierarchies foroneOfschemas with a discriminator - Flattens
allOfschemas into a single merged class - Handles
additionalProperties(typed or untyped) - Generates Dio-based service classes from OpenAPI paths — one file per tag
- Generates an aggregator client class with static auth-helper factories (Bearer, API key header/query, HTTP Basic)
- Supports
LocalSpec(local YAML/JSON file) andRemoteSpec(HTTPS URL with optional request headers) - MD5-keyed cache — skips unchanged specs for fast incremental builds
- Supports OpenAPI 3.0, 3.1, and 3.2 (including
in: querystringandadditionalOperations) - Zero runtime dependencies in the consumer's tree —
dart_openapi_generatoris a dev dependency
Installation
pubspec.yaml
dependencies:
dart_openapi_generator_annotations: ^0.1.0
dio: ^5.0.0
dev_dependencies:
dart_openapi_generator: ^0.1.0
build_runner: ^2.4.0
Get Started
Follow the Getting Started guide to go from zero to a working API client.
See the Annotation Reference for every @OpenApiGenerator field.