openapi_dart_common 3.1.0

  • Readme
  • Changelog
  • Installing
  • 87

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.

  openapi_dart_common: ^3.1.0

(for example)

In your application, each of the generated Services will require an ApiClient. As of version 2.0 we have swapped to Dio, which takes care of browser vs CLI, so you only need to specify DioClientDelegate() if you wish to override the Dio instance (providing extra options, etc).

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",
      apiClientDelegate: DioClientDelegate());

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

3.1.0 #

removing LocalClientApi and QueryParamHelper from api to make it simpler to use. Introducion of Rich Response for extension methods.

3.0.1 #

fix for dio content headers

3.0.0 #

significant refactoring to co-incide with the 3.x release of the Dart plugin cleanup.

2.0.1 #

  • swapping to Dio introduced a subtle bug in DELETE for browser. A DELETE with a browser would cause an exception that couldn't be caught and only showed up in the browser as a Bad Element.

2.0.0 #

  • swap to Dio from the http package. Dio has extensive support for all sorts of features, particularly including client side certificate pinning.

1.1.1 #

  • http code 204 returns a null json response which caused a crash

1.1.0 #

  • breaking change, generated code needs to know how to serialize

1.0.2 #

  • allow content-type header to be empty

1.0.1 #

  • Feedback from release process

1.0.0 #

  • 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:

  openapi_dart_common: ^3.1.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. 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_delegates.dart';
import 'package:openapi_dart_common/api_dio_client_delegate.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';
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]
Learn more about scoring.

We analyzed this package on Jul 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Health suggestions

Fix lib/api_dio_client_delegate.dart. (-1 points)

Analysis of lib/api_dio_client_delegate.dart reported 2 hints:

line 42 col 18: The target expression uses '?.', so its value can be null.

line 58 col 7: Use rethrow to rethrow a caught exception.

Fix lib/api_helper.dart. (-0.50 points)

Analysis of lib/api_helper.dart reported 1 hint:

line 3 col 21: Avoid const keyword.

Format lib/api_client.dart.

Run dartfmt to format lib/api_client.dart.

Format lib/api_delegates.dart.

Run dartfmt to format lib/api_delegates.dart.

Format lib/openapi.dart.

Run dartfmt to format lib/openapi.dart.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and openapi_dart_common.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
dio >=3.0.3 <4.0.0 3.0.9
Transitive dependencies
charcode 1.1.3
collection 1.14.13
http_parser 3.1.4
meta 1.2.1
path 1.7.0
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0
Dev dependencies
pedantic ^1.9.0
test ^1.3.0