api_generator 0.2.0 copy "api_generator: ^0.2.0" to clipboard
api_generator: ^0.2.0 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 can also scaffold a Clean Architecture Flutter feature by combining Swagger/OpenAPI analysis with Figma metadata.

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
  • Figma file URLs and selected Figma node URLs for feature scaffolding

The generator writes:

  • OpenAPI Generator dart-dio output to lib/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
  • feature reports, request/response models, repositories, use cases, Cubits, pages, and widgets for generate-feature

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

Feature Scaffolding #

Generate a Flutter feature from Swagger and Figma:

api_generator generate-feature \
  --swagger-url https://example.com/swagger.json \
  --figma-url https://www.figma.com/file/FILE_KEY/Auth?node-id=1%3A2 \
  --feature-name auth \
  --project-name agro_cosmos \
  --output /path/to/flutter_app/lib

Optional Figma access:

export FIGMA_ACCESS_TOKEN=your-token

Or pass it directly:

api_generator generate-feature \
  --swagger-url https://example.com/swagger.json \
  --figma-url https://www.figma.com/file/FILE_KEY/Auth \
  --feature-name auth \
  --project-name agro_cosmos \
  --figma-token your-token

The feature generator:

  • reuses the generated OpenAPI Dio client in lib/core/generated/openapi
  • detects endpoints related to the feature name
  • inspects the selected Figma node when node-id is present
  • falls back to Swagger-driven screens when Figma metadata is not accessible
  • writes a feature_generation_report.md with mapping, assumptions, and integration notes

Notes #

  • application/json request 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.dart uses retrofit, dio, and flutter/foundation.dart.
  • After generation, run your Flutter app's Retrofit build step for api_client.g.dart.
  • generate-feature also expects your Flutter app to provide get_it, flutter_bloc, freezed_annotation, and json_annotation, then run build_runner.
1
likes
0
points
107
downloads

Publisher

unverified uploader

Weekly Downloads

Generate Flutter-friendly Dio clients and repository layers from Swagger/OpenAPI sources.

Repository (GitLab)
View/report issues

Topics

#openapi #swagger #codegen #flutter

License

unknown (license)

Dependencies

args, path, yaml

More

Packages that depend on api_generator