OpenAPI 사양에서 클라이언트 SDK를 생성하는 플러터/다트 패키지로, npm의 openapi-generator-cli에 영감을 받았습니다. API 상호작용을 위한 타입 안전한 다트 코드 생성을 자동화하여 수동 작업과 잠재적인 오류를 줄입니다. 생성된 코드는 안드로이드, iOS, 웹, 맥OS, 윈도우, 리눅스 등 여러 플랫폼을 지원하며 환경 간 일관된 API 클라이언트 사용을 가능하게 합니다. OpenAPI/Swagger 정의에 의존하여 애플리케이션 내에서 강력하고 최신 상태의 API 통합을 유지하는 팀에게 이상적입니다.
사용 사례
OpenAPI 사양에서 API 클라이언트 생성 자동화
타입 안전성으로 REST API 통합
Flutter 앱을 위한 크로스 플랫폼 API 클라이언트
백엔드 변경사항과 API 계약을 동기화 유지하기
API 서비스 계층에서 반복 코드 줄이기
주요 기능
OpenAPI 3.x 사양에서 Dart 코드 생성
다중 플랫폼 출력을 지원합니다
형 안전한 API 모델과 서비스를 생성합니다
Flutter pub add를 통해 통합
CLI 유사 워크플로우를 사용
적합한 대상
OpenAPI로 정의된 API를 사용하는 Flutter 개발자
자동화된 API 클라이언트 업데이트가 필요한 팀
다양한 플랫폼에서 일관된 API 통합이 필요한 프로젝트
수동 API 서비스 코드 작성량을 줄이고자 하는 개발자
고려 사항
유효한 OpenAPI 사양 파일이 필요합니다
생성된 코드는 복잡한 엔드포인트에 맞게 사용자 지정이 필요할 수 있습니다
일관성을 위해 CI/CD 파이프라인에서 최적의 사용
런타임 라이브러리가 아님 — 소스 코드만 생성
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
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