api_generator 0.1.2
api_generator: ^0.1.2 copied to clipboard
Generate Flutter-friendly Dio clients and repository layers from Swagger/OpenAPI sources.
api_generator #
api_generator is a Dart CLI package that turns Swagger/OpenAPI sources into a Flutter-friendly data layer.
It supports:
- raw OpenAPI JSON or YAML URLs
- Swagger docs URLs
- local
openapi.json - local
swagger-ui-init.js - no auth, basic auth, and bearer auth
The generator writes:
- OpenAPI Generator
dart-diooutput tolib/core/generated/openapi - API constants to
lib/core/api_constants.dart - Retrofit API client to
lib/core/network/api_client.dart - feature models to
lib/features/<feature>/data/model - repository interfaces by tag to
lib/features/<feature>/domain/repositories - repository implementations by tag to
lib/features/<feature>/data/repositories - per-operation cubits to
lib/features/<feature>/presentation/cubits
Install #
dart pub global activate api_generator
Install openapi-generator-cli separately and make sure it is available on your PATH.
Usage #
api_generator generate https://example.com/swagger-ui/index.html
Run it from your Flutter project root and output defaults to ./lib.
Custom output:
api_generator generate https://example.com/docs /path/to/flutter_app/lib
If the Swagger page is protected with basic auth, the CLI prompts for username and password automatically.
Advanced non-interactive auth:
api_generator generate \
--input https://example.com/docs \
--output /path/to/flutter_app/lib \
--auth-type bearer \
--token your-token
Notes #
application/jsonrequest bodies are mapped first.- Multipart request handling is designed to be extended later.
- Repository methods are grouped by OpenAPI tags and named from
operationId. - Generated
api_client.dartusesretrofit,dio, andflutter/foundation.dart. - After generation, run your Flutter app's Retrofit build step for
api_client.g.dart.