OpenAPI Common Library for Dart Client Code Generator #
This library forms the core reusable library for the Maven plugin.
It is intended to allow you to generate a single client library from an OpenAPI file, and allow you to reuse it across multiple clients - Flutter for Web (browser), Flutter and Dart CLI (such as when using Ogurets for e2e testing).
How to use #
This library contains all of the necessary parts required to wire up your generated code from the Maven plugin.
Add these to your
pubspec.yaml and then combine them together.
dependencies: openapi_dart_common: ^1.0.0 your_generated_lib: path: ../your_generated_lib
In your application, each of the generated Services will require an ApiClient. To construct this you will need to chose
apiClientDelegate depending on whether you are using the Browser (such as Flutter for Web)
or the CLI or Flutter Mobile
It also needs to know how to deserialize specific models and enums - those from your generated code, so a typical creation could look like this:
_apiClient = ApiClient( basePath: "http://localhost:8903", deserializeDelegate: LocalApiClient(), apiClientDelegate: CliApiClientDelegate());
and then you can use your _apiClient instance in your models, consistently across all platforms:
_personService = PersonServiceApi(_apiClient);
You can also override the
BaseClient that is passed into the
ApiClient if you need to customise it, but be
careful not to mix those requiring
dart:html (which only exists in the browser) with
dart:io (everywhere else).
If you don't have Maven installed, you can install it fairly easily on Linux and Mac (its in brew), it will require a JDK implementation so if you don't have done get one from https://adoptopenjdk.net/.
- http code 204 returns a null json response which caused a crash
- breaking change, generated code needs to know how to serialize
- allow content-type header to be empty
- Feedback from release process
- Initial release tested and working with existing Flutter for Web and e2e Ogurets code.
Use this package as a library
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies: openapi_dart_common: ^1.1.1
2. Install it
You can install packages from the command line:
$ pub get
Alternatively, your editor might support
Check the docs for your editor to learn more.
3. Import it
Now in your Dart code, you can use:
import 'package:openapi_dart_common/api_client.dart'; import 'package:openapi_dart_common/api_exception.dart'; import 'package:openapi_dart_common/api_helper.dart'; import 'package:openapi_dart_common/auth/api_key_auth.dart'; import 'package:openapi_dart_common/auth/authentication.dart'; import 'package:openapi_dart_common/auth/http_basic_auth.dart'; import 'package:openapi_dart_common/auth/oauth.dart'; import 'package:openapi_dart_common/openapi.dart'; import 'package:openapi_dart_common/openapi_browser_api.dart'; import 'package:openapi_dart_common/openapi_cli_api.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
We analyzed this package on Oct 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
- Dart: 2.5.1
- pana: 0.12.21
Detected platforms: web
Platform components identified in package:
dartfmt to format
Maintain an example. (-10 points)
Create a short demo in the
example/ directory to show how to use this package.
Common filename patterns include
openapi_dart_common.dart. Packages with multiple examples should provide
For more information see the pub package layout conventions.
|Dart SDK||>=2.2.0 <3.0.0|