Skip to content
pubscout

swagger_dart_code_generator

4.1.1, released 11 months ago by mobilepeople.dev

Generates Dart models and Chopper API client code from Swagger and OpenAPI schemas.

$ flutter pub add swagger_dart_code_generator
Source repository

What it does

Parses Swagger or OpenAPI JSON/YAML schema files to automatically generate Dart data models, enums, converter mappings, and Chopper client request methods. It integrates with build_runner and json_serializable for serialization.

AI-written summary of version 4.1.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You are working with a backend that provides a Swagger or OpenAPI specification.
  • You use Chopper as your HTTP client and want to automate API boilerplate creation.

Skip it when

  • You prefer writing your network requests and data models manually.
  • Your backend does not provide an OpenAPI or Swagger schema file.

Strengths

  • Automates creation of extensive models and API requests from schemas.
  • Highly configurable through build.yaml (supports custom scalars, default values, paths filtering).

Weaknesses

  • Requires maintaining and running build_runner for code generation.
  • Tight coupling with Chopper and json_serializable.

Setup

Kind
Pure Dart
Effort
Medium
Code generation
Yes (build_runner)
Direct dependencies
11

Add chopper, json_annotation, build_runner, chopper_generator, json_serializable, and swagger_dart_code_generator to pubspec.yaml, then configure build.yaml and run dart run build_runner build.

targets:
  $default:
    builders:
      swagger_dart_code_generator:
        options:
          input_folder: 'lib/swaggers'
          output_folder: 'lib/generated_code/'

Alternatives

Packages that do the same job and could replace swagger_dart_code_generator.

Works with

Packages commonly used together with swagger_dart_code_generator: ones it builds on, ones built on it, and its own family.