Skip to content
pubscout

swagger_parser

2.3.0, released 4 days ago by carapacik.dev

Generate Dart models and HTTP clients from Swagger and OpenAPI schemas.

$ flutter pub add swagger_parser
Source repository

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.

Works with

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