패키지, 저장소 및 앱 카테고리 검색

패키지 상세v7.0.0

openapi_generator_cli

Node 구현을 참고한 openapi-generator용 Dart 래퍼입니다.

macOSWindowsLinux
30일 다운로드
2만
좋아요
21
Pub 점수
160

패키지 설치

flutter pub add openapi_generator_cli

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Node.js 버전에 영감을 받은 OpenAPI Generator용 Dart 래퍼로, OpenAPI 사양에서 Dart 코드를 원활하게 생성할 수 있게 해줍니다. macOS, Windows, Linux 등 여러 플랫폼을 지원하여 API 클라이언트 생성을 자동화해야 하는 개발자에게 이상적입니다. OpenAPI 3.x 사양을 기반으로 타입 안정성과 잘 정리된 Dart 모델 및 서비스를 생성함으로써 RESTful API와의 통합을 간소화합니다. API 계약을 자주 업데이트해야 하는 프로젝트에서 특히 유용합니다.

사용 사례

  • API 클라이언트 생성 자동화
  • CI/CD 파이프라인과의 통합
  • 최신 API 클라이언트 유지
  • OpenAPI 사양에서 모델 및 서비스 생성
  • API 계약에서 팀 협업 지원

주요 기능

  • 크로스 플랫폼 지원
  • OpenAPI 3.x와의 통합
  • 타입 안전한 Dart 출력
  • 명령줄 인터페이스
  • 사용자 정의 가능한 코드 생성 템플릿

적합한 대상

  • OpenAPI 사양을 사용하는 Dart 개발자
  • 자동화된 API 클라이언트 업데이트가 필요한 팀
  • 진화하는 REST API를 갖춘 프로젝트
  • API 변경을 포함하는 CI/CD 워크플로우
  • openapi-generator에 익숙한 개발자

고려 사항

  • openapi-generator의 로컬 설치가 필요합니다
  • 사용자 지정 템플릿에 대한 구성이 필요할 수 있습니다
  • OpenAPI 사양의 품질에 따라 다름
  • 런타임 라이브러리가 아니라 코드 생성기입니다
  • CLI를 제외한 IDE 통합은 제한적

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

openapi-generator-dart

pub package Pub Likes Pub Points Pub Popularity GitHub Repo stars codecov

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) pub package
openapi-generator-annotations Annotations for configuring OpenAPI client SDK generation (usage) pub package
openapi-generator-cli CLI wrapper for OpenAPI code generation (usage) pub package

Quick Start

1. Add Dependencies

Add the annotations package to your pubspec.yaml:

dependencies:
  openapi_generator_annotations: ^<latest-version>

Add the generator as a dev dependency:

dev_dependencies:
  openapi_generator: ^<latest-version>

Beta Features:
For beta features, use the beta branch:

dependencies:
  openapi_generator_annotations:
    git:
      url: https://github.com/gibahjoe/openapi-generator-dart.git
      ref: beta
      path: openapi-generator-annotations

dev_dependencies:
  openapi_generator:
    git:
      url: https://github.com/gibahjoe/openapi-generator-dart.git
      ref: beta
      path: openapi-generator
2. Annotate Your Dart Class

Annotate a Dart class with @Openapi() to configure code generation:

import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';

@Openapi(
  additionalProperties: DioProperties(pubName: 'petstore_api', pubAuthor: 'Johnny Depp'),
  inputSpec: RemoteSpec(path: 'https://petstore3.swagger.io/api/v3/openapi.json'),
  typeMappings: {'Pet': 'ExamplePet'},
  generatorName: Generator.dio,
  runSourceGenOnOutput: true,
  outputDirectory: 'api/petstore_api',
)
class Example {}
3. Generate the SDK

Run the build command:

dart run build_runner build --delete-conflicting-outputs
# or, for Flutter projects:
flutter pub run build_runner build --delete-conflicting-outputs

The generated SDK will appear in the specified output directory.


Next Generation Features (v5.0+)

  • Spec Caching: Automatically caches your OpenAPI spec for faster incremental builds.
  • Remote Spec Support: Pulls and caches remote specs; always fetches the latest version unless using a local copy.
  • Smart Generation: Skips code generation if there are no changes in the spec or based on flags.
  • All previous features remain available.

Example:

@Openapi(
  additionalProperties: DioProperties(pubName: 'petstore_api', pubAuthor: 'Johnny Depp'),
  inputSpec: RemoteSpec(path: 'https://petstore3.swagger.io/api/v3/openapi.json'),
  typeMappings: {'Pet': 'ExamplePet'},
  generatorName: Generator.dio,
  runSourceGenOnOutput: true,
  outputDirectory: 'api/petstore_api',
)
class Example {}

Advanced Configuration

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.

Example:

@Openapi(
  additionalProperties: DioProperties(pubName: 'custom_api', pubAuthor: 'Jane Doe'),
  inputSpec: InputSpec(path: 'openapi-spec.yaml'),
  generatorName: Generator.dio,
  templateDirectory: 'templates/dart',
  typeMappings: {'date': 'DateTime'},
  importMappings: {'DateTime': 'package:my_project/date_time.dart'},
  reservedWordsMappings: {'class': 'clazz'},
  outputDirectory: 'api/custom_api',
)
class CustomApi {}

Troubleshooting

Common Issues
  • 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

카테고리

의존성

의존성 목록 4 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.