swagger_parser
2.3.0, released 4 days ago by carapacik.dev
Generate Dart models and HTTP clients from Swagger and OpenAPI schemas.
What it does
Parses Swagger 2.0 and OpenAPI 3.x specifications to generate Dart models and HTTP clients. Supports json_serializable, Freezed, dart_mappable, Retrofit, Dio, and package:http.
AI-written summary of version 2.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You have a Swagger or OpenAPI specification and want to automatically generate Dart code for it.
- You want to standardize API requests and responses using Retrofit, Dio, or package:http.
Skip it when
- You prefer writing your API client and models entirely by hand.
- You use backend technologies or schemas not supported by Swagger or OpenAPI.
Strengths
- Supports multiple client and serializer options including Retrofit, Dio, Freezed, and dart_mappable.
- Provides CLI commands to validate schemas and check files without writing.
Weaknesses
- Requires updating to Dart ^3.13.0 for version 2.0.0.
- Breaking changes in v2.0.0 require migrating v1 configurations.
Setup
- Kind
- Pure Dart
- Effort
- Medium
- Code generation
- Yes (build_runner)
- Direct dependencies
- 7
Requires adding swagger_parser and related builder dependencies, then running build_runner if using serializers.
import 'package:dio/dio.dart';
import 'generated/api.dart';
final api = Api(Dio(BaseOptions(baseUrl: 'https://example.com')));
final station = await api.stations.getStation(id: '42');Alternatives
Packages that do the same job and could replace swagger_parser.
- retrofit_generator
Generates Dio client code from Retrofit‑style annotations.
89Compare - chopper_generator
Generates type‑safe Chopper client code from annotated service interfaces.
78Compare - tonik
Pure Dart OpenAPI 3.0/3.1 code generator for type-safe API client packages.
74Compare - openapi_generator_annotations
Annotation package for configuring openapi_generator client SDKs.
66Compare
Works with
Packages commonly used together with swagger_parser: ones it builds on, ones built on it, and its own family.
- yamlswagger_parser depends on itA Dart library for parsing YAML documents into Dart data structures.
- pub_semverswagger_parser depends on itVersions and version constraints implementing pub's versioning policy.
- dart_styleswagger_parser depends on itProvides an API and CLI to format Dart source code automatically.
- argsswagger_parser depends on itLibrary for parsing raw command-line arguments into options and values using GNU and POSIX styles.
- code_builderswagger_parser depends on itA fluent, builder-based library for generating valid Dart code programmatically.