Package selection guidance compiled from public package information, community data, and project usage.
A Dart annotation package designed to work with the openapi_generator tool, enabling developers to generate Dart models and API clients directly from OpenAPI specifications. It simplifies the integration of RESTful APIs into Flutter and other Dart applications by automating code generation based on standardized API definitions. The annotations guide the generator to produce clean, type-safe code that aligns with OpenAPI 3.0+ standards. This package is ideal for teams following API-first development practices.
Use cases
Generating client code from OpenAPI specs
Automating API model creation
Enabling API-first development workflows
Integrating REST APIs in Flutter apps
Streamlining backend-frontend synchronization
Key features
Annotations for OpenAPI schema definition
Integration with openapi_generator tool
Support for OpenAPI 3.0+
Type-safe generated code
Cross-platform compatibility
Suitable for
API-first development teams
Flutter apps consuming REST APIs
Projects using OpenAPI specifications
Developers seeking automated code generation
Teams requiring consistent API contracts
Considerations
Requires openapi_generator tool setup
Dependent on accurate OpenAPI specification
Generated code may need manual adjustments
Not suitable for runtime API modifications
Limited to static code generation
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
openapi-generator-dart
Like this library? Give us a star or a like!
⚠️ Java Requirement
Java is required to use this library.
The OpenAPI Generator CLI is a Java application.
Please ensure you have Java (version 8 or higher) installed and available in your system PATH.
You can check your Java installation with:
java -version
If you do not have Java installed, download it from Adoptium or Oracle.
⚠️ Deprecation & Breaking Change Notice
skipIfSpecIsUnchanged is Deprecated
The skipIfSpecIsUnchanged option is now deprecated and will be removed in the next major release.
Local OpenAPI specs are now automatically watched for changes.
If your spec file is in the lib/ folder, this works out of the box.
If your spec file is outside lib/, you must update or add a build.yaml to include your spec file as a source.
Example:
targets:$default:sources:-$package$-lib/**-openapi.yaml# or your spec file path
Remote specs:
Use the forceAlwaysRun (defaults to false) option to ensure the generator always runs.
This option is ignored for local specs.
When enabled, it modifies the annotated file to force regeneration. This might cause issues such as merge conflicts
Overview
This repository provides Dart/Flutter libraries for generating OpenAPI client SDKs directly from your OpenAPI specification. Inspired by Openapi Generator Cli (npm), it enables seamless integration into Dart and Flutter projects.
Libraries
Library
Description
Latest Version
openapi-generator
Dev dependency for generating OpenAPI client SDK via Dart source gen (usage)
openapi-generator-annotations
Annotations for configuring OpenAPI client SDK generation (usage)
If you are having issues with the generated code, this is not an problem with this package and creating an issue here will not help solve it. Its best to create the issue in the base OpenApi library since this package is a wrapper around that library for ease of use with Flutter/dart.
Below are some advanced configurations you may try.
Custom Templates:
Use the templateDirectory parameter to specify a custom code generation template.
Type & Import Mappings:
Use typeMappings and importMappings to control how OpenAPI types and models are mapped in Dart.
Reserved Words:
Use reservedWordsMappings to avoid conflicts with Dart reserved words.
Dependency Conflicts:
Use dependency_overrides in the generated package's pubspec.yaml and add pubspec.yaml to .openapi-generator-ignore to prevent overwrites.
Incorrect Generated Code:
Fix your OpenAPI spec (preferred).
Manually edit the generated code and add the files to .openapi-generator-ignore to prevent them from being overwritten.
.openapi-generator-ignore Example:
# Ignore all test files
test/*
# Ignore pubspec.yaml to preserve manual changes
pubspec.yaml