openapi_generator 4.13.0 copy "openapi_generator: ^4.13.0" to clipboard
openapi_generator: ^4.13.0 copied to clipboard

Generator for openapi client sdk inspired by the npm implementation of openapi-generator-cli.

pub package

This library is the dart/flutter implementation of openapi client sdk code generation.

With this library, you can generate openapi client sdk libraries from your openapi specification right in your flutter/dart projects. (see example)

To be used together with openapi-generator-annotations

Usage #

Include openapi-generator-annotations as a dependency in the dependencies section of your pubspec.yaml file :

dependencies:
  openapi_generator_annotations: ^4.11.0

Add openapi-generator in the dev dependencies section of your pubspec.yaml file:

dev_dependencies:
  openapi_generator: ^4.11.0

Annotate a dart class with @Openapi() annotation

@Openapi(
    additionalProperties:
    AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep'),
    inputSpecFile: 'example/openapi-spec.yaml',
    generatorName: Generator.dart,
    outputDirectory: 'api/petstore_api')
class Example extends OpenapiGeneratorConfig {}

Run command below to generate open api client sdk from spec file specified in annotation.

flutter pub run build_runner build --delete-conflicting-outputs

The api sdk will be generated in the folder specified in the annotation. See examples for more details

Known Issues #

Dependency issues/conflicts #

This is not an issue with this library but with flutter/dart in general. If you are having issues with dependencies, what you can do is make use of dependency overrides. This is added to the pubspec.yaml of the generated package and then the pubspec must be added to the .openapi-generator-ignore of the generated package. For example, let's assume you want to override the analyzer package for the generated source

in generatedsource/pubspec.yaml add the following

dependency_overrides:
  analyzer: 1.0.0

Then in generatedsources/.openapi-generator-ignore, add the below so that the pubspec is not overwritten next time you run source gen

pubspec.yaml

The above steps are useful when you have issues with dependency conflicts, clashes. You can even use it to upgrade the library packages in the generated source.

FAQ #

Q: I run source gen (flutter pub run build_runner build --delete-conflicting-outputs), The api generator does not run.

A: The source generator of flutter only runs when there are changes to the file that has the annotation. If this ever happens, just go to the file that has the @openapi annotation and edit something in the file.

Q: How do I prevent files from being generated e.g tests

A: To prevent any files from being generated, you need to add it to .openapi-generator-ignore. This file is in the root of the generated code. For example, to prevent generating tests, add test/* to the file.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Running Tests #

Requirements:

Buy Me A Coffee

98
likes
0
pub points
89%
popularity

Publisher

verified publisherdevappliance.com

Generator for openapi client sdk inspired by the npm implementation of openapi-generator-cli.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

analyzer, build, build_runner, http, logging, openapi_generator_annotations, openapi_generator_cli, path, source_gen, yaml

More

Packages that depend on openapi_generator