swagger_dart_generator 1.2.0 copy "swagger_dart_generator: ^1.2.0" to clipboard
swagger_dart_generator: ^1.2.0 copied to clipboard

A Dart code generator that creates complete Data Layer a Package for Flutter project structure from Swagger/OpenAPI JSON files

🧬 Swagger Dart Generator #

Pub Version Null Safety GitHub Stars

You run the generator once and you instantly get a package you can import in any Flutter / Dart project to call your backend.


✨ Features #

  • Clean Architecture: Generates the data layer components (DataSources, Repositories, Models) for maintainability.
  • Singleton Pattern: Creates a central (<package_name>.dart) using lazy singletons access to all generated, You can Custom this just not use <package_name>.init().
  • Model Generation: Creates Dart classes for API Request and Response models You can update only dtos With mg_tools for gen Freezed DTOs from json.
  • Testing: Generates ready-to-use Integration Tests for all endpoints With Singletons default.

πŸ’» Installation #

Install the package globally using the Dart package manager. This makes the swagger_dart_generator command available anywhere on your system.

dart pub global activate swagger_dart_generator

Usage #

Run the command with the path to your swagger.json. The tool will generate a Dart package structure.

swagger_dart_generator

πŸš€ Working with the Generated Package #

Import and use in your app:

import 'package:dio/dio.dart';
import 'package:example/example.dart';
import 'package:example/data/models/auth/requests/authlogin_req.dart';

void main() async {
final dio = Dio(BaseOptions(baseUrl: 'https://api.example.com'));
final api = Example.init(dio);
final loginResult = await api.repository.auth.authlogin(AuthloginReq());
loginResult.fold(
 (failure) => print('❌ ${failure.message}'),
 (success) => print('βœ… Logged in: $success'),
);
}

🧰 Dependencies Generated #

dependencies:
  dio:
  dartz:
  freezed_annotation:
  json_annotation:
  get_it:
  logger:

dev_dependencies:
  build_runner:
  freezed:
  json_serializable:
  mg_tools:
  test:

πŸ“‚ Folder Structure Generated #

example
 ┣ .dart_tool
 ┃ ┣ pub
 ┃ ┃ β”— bin
 ┃ ┃ ┃ β”— mg_tools
 ┃ ┃ ┃ ┃ β”— mg_tools.dart-3.9.2.snapshot
 ┃ ┣ package_config.json
 ┃ β”— package_graph.json
 ┣ lib
 ┃ ┣ data
 ┃ ┃ ┣ datasources
 ┃ ┃ ┃ ┣ auth
 ┃ ┃ ┃ ┃ ┣ auth.dart
 ┃ ┃ ┃ ┃ β”— auth_remote_datasource_impl.dart
 ┃ ┃ ┃ ┣ product
 ┃ ┃ ┃ ┃ ┣ product.dart
 ┃ ┃ ┃ ┃ β”— product_remote_datasource_impl.dart
 ┃ ┃ ┃ β”— user
 ┃ ┃ ┃ ┃ ┣ user.dart
 ┃ ┃ ┃ ┃ β”— user_remote_datasource_impl.dart
 ┃ ┃ ┣ models
 ┃ ┃ ┃ ┣ auth
 ┃ ┃ ┃ ┃ ┣ requests
 ┃ ┃ ┃ ┃ ┃ ┣ auth_
 ┃ ┃ ┃ ┃ ┃ ┣ authlogin_req.dart
 ┃ ┃ ┃ ┃ ┃ ┣ authlogin_req.dto.json
 ┃ ┃ ┃ ┃ ┃ ┣ authlogin_req.freezed.dart
 ┃ ┃ ┃ ┃ ┃ β”— authlogin_req.g.dart
 ┃ ┃ ┃ ┃ β”— responses
 ┃ ┃ ┃ ┃ ┃ ┣ authlogin_res.dart
 ┃ ┃ ┃ ┃ ┃ ┣ authlogin_res.dto.json
 ┃ ┃ ┃ ┃ ┃ ┣ authlogin_res.freezed.dart
 ┃ ┃ ┃ ┃ ┃ β”— authlogin_res.g.dart
 ┃ ┃ ┃ ┣ product
 ┃ ┃ ┃ ┃ ┣ requests
 ┃ ┃ ┃ ┃ ┃ ┣ products_req.dart
 ┃ ┃ ┃ ┃ ┃ ┣ products_req.dto.json
 ┃ ┃ ┃ ┃ ┃ ┣ products_req.freezed.dart
 ┃ ┃ ┃ ┃ ┃ ┣ products_req.g.dart
 ┃ ┃ ┃ ┃ ┃ ┣ productsid_req.dart
 ┃ ┃ ┃ ┃ ┃ ┣ productsid_req.dto.json
 ┃ ┃ ┃ ┃ ┃ ┣ productsid_req.freezed.dart
 ┃ ┃ ┃ ┃ ┃ β”— productsid_req.g.dart
 ┃ ┃ ┃ ┃ β”— responses
 ┃ ┃ ┃ ┃ ┃ ┣ products_res.dart
 ┃ ┃ ┃ ┃ ┃ ┣ products_res.dto.json
 ┃ ┃ ┃ ┃ ┃ ┣ products_res.freezed.dart
 ┃ ┃ ┃ ┃ ┃ ┣ products_res.g.dart
 ┃ ┃ ┃ ┃ ┃ ┣ productsid_res.dart
 ┃ ┃ ┃ ┃ ┃ ┣ productsid_res.dto.json
 ┃ ┃ ┃ ┃ ┃ ┣ productsid_res.freezed.dart
 ┃ ┃ ┃ ┃ ┃ β”— productsid_res.g.dart
 ┃ ┃ ┃ β”— user
 ┃ ┃ ┃ ┃ ┣ requests
 ┃ ┃ ┃ ┃ ┃ ┣ useruser_id_req.dart
 ┃ ┃ ┃ ┃ ┃ ┣ useruser_id_req.dto.json
 ┃ ┃ ┃ ┃ ┃ ┣ useruser_id_req.freezed.dart
 ┃ ┃ ┃ ┃ ┃ β”— useruser_id_req.g.dart
 ┃ ┃ ┃ ┃ β”— responses
 ┃ ┃ ┃ ┃ ┃ ┣ useruser_id_res.dart
 ┃ ┃ ┃ ┃ ┃ ┣ useruser_id_res.dto.json
 ┃ ┃ ┃ ┃ ┃ ┣ useruser_id_res.freezed.dart
 ┃ ┃ ┃ ┃ ┃ β”— useruser_id_res.g.dart
 ┃ ┃ β”— repositories
 ┃ ┃ ┃ ┣ auth
 ┃ ┃ ┃ ┃ ┣ auth.dart
 ┃ ┃ ┃ ┃ β”— auth_repository_impl.dart
 ┃ ┃ ┃ ┣ product
 ┃ ┃ ┃ ┃ ┣ product.dart
 ┃ ┃ ┃ ┃ β”— product_repository_impl.dart
 ┃ ┃ ┃ β”— user
 ┃ ┃ ┃ ┃ ┣ user.dart
 ┃ ┃ ┃ ┃ β”— user_repository_impl.dart
 ┃ ┣ end_points.dart
 ┃ ┣ example.dart
 ┃ β”— failure.dart
 ┣ test
 ┃ ┣ auth_test.dart
 ┃ ┣ product_test.dart
 ┃ β”— user_test.dart
 ┣ .gitignore
 ┣ CHANGELOG.md
 ┣ README.md
 ┣ analysis_options.yaml
 ┣ pubspec.lock
 ┣ pubspec.yaml
 β”— swagger.json

🀝 Contributing #

Pull requests, issues and feature‑requests are welcome!
If you find bugs or want to support new features (e.g., custom headers, caching, plugin support) open an issue.


πŸ“„ License #

MIT Β© 2025 Mohamad Alghanem

2
likes
150
points
698
downloads
screenshot

Publisher

verified publisheralghanem.de

Weekly Downloads

A Dart code generator that creates complete Data Layer a Package for Flutter project structure from Swagger/OpenAPI JSON files

Repository (GitHub)
View/report issues

Topics

#cli #clean #codegen #swagger #openapi

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

path

More

Packages that depend on swagger_dart_generator