mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-06 15:40:54 +00:00
[dart-dio] Fix json_serializable response for type:string format:binary (#21379)
* fixed inconsistencies with the dart-dio json_serializable string binary response types * update deserialize template to handle responseFile * regenerate samples * only convert return_type to Uint8List * remove unused imports from previous changes * fixed issues where import wouldn't get included * specific unit test for binary response * reverted changes to nested generators * removed 2 additional php modifications * regen samples
This commit is contained in:
parent
a5f638fefd
commit
7c57c55194
8
bin/configs/dart-dio-binary-response.yaml
Normal file
8
bin/configs/dart-dio-binary-response.yaml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
generatorName: dart-dio
|
||||||
|
outputDir: samples/openapi3/client/petstore/dart-dio/binary_response
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_20682.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/dart/libraries/dio
|
||||||
|
additionalProperties:
|
||||||
|
hideGenerationTimestamp: "true"
|
||||||
|
enumUnknownDefaultCase: "true"
|
||||||
|
serializationLibrary: "json_serializable"
|
@ -670,6 +670,17 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
|
|||||||
op.imports.remove("Uint8List");
|
op.imports.remove("Uint8List");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SERIALIZATION_LIBRARY_JSON_SERIALIZABLE.equals(library)) {
|
||||||
|
// built_value serialization uses Uint8List for all MultipartFile types
|
||||||
|
// in json_serialization, MultipartFile is used as the file parameter type, but
|
||||||
|
// MultipartFile isn't readable, instead we convert this to a Uin8List
|
||||||
|
if (op.isResponseFile) {
|
||||||
|
op.imports.add("Uint8List");
|
||||||
|
op.returnType = "Uint8List";
|
||||||
|
op.returnBaseType = "Uint8List";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
resultImports.addAll(rewriteImports(op.imports, false));
|
resultImports.addAll(rewriteImports(op.imports, false));
|
||||||
|
|
||||||
if (SERIALIZATION_LIBRARY_BUILT_VALUE.equals(library)) {
|
if (SERIALIZATION_LIBRARY_BUILT_VALUE.equals(library)) {
|
||||||
|
@ -1,2 +1,7 @@
|
|||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<{{{returnType}}}, {{{returnBaseType}}}>(rawData, '{{{returnType}}}', growable: true);
|
{{#isResponseFile}}
|
||||||
|
_responseData = rawData == null ? null : rawData as {{{returnType}}};
|
||||||
|
{{/isResponseFile}}
|
||||||
|
{{^isResponseFile}}
|
||||||
|
_responseData = rawData == null ? null : deserialize<{{{returnType}}}, {{{returnBaseType}}}>(rawData, '{{{returnType}}}', growable: true);
|
||||||
|
{{/isResponseFile}}
|
@ -0,0 +1,16 @@
|
|||||||
|
openapi: 3.0.0
|
||||||
|
info:
|
||||||
|
version: 1.0.0
|
||||||
|
title: Binary response
|
||||||
|
paths:
|
||||||
|
/limits:
|
||||||
|
get:
|
||||||
|
operationId: binaryResponse
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: OK
|
||||||
|
content:
|
||||||
|
application/zip:
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
format: binary
|
41
samples/openapi3/client/petstore/dart-dio/binary_response/.gitignore
vendored
Normal file
41
samples/openapi3/client/petstore/dart-dio/binary_response/.gitignore
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# See https://dart.dev/guides/libraries/private-files
|
||||||
|
|
||||||
|
# Files and directories created by pub
|
||||||
|
.dart_tool/
|
||||||
|
.buildlog
|
||||||
|
.packages
|
||||||
|
.project
|
||||||
|
.pub/
|
||||||
|
build/
|
||||||
|
**/packages/
|
||||||
|
|
||||||
|
# Files created by dart2js
|
||||||
|
# (Most Dart developers will use pub build to compile Dart, use/modify these
|
||||||
|
# rules if you intend to use dart2js directly
|
||||||
|
# Convention is to use extension '.dart.js' for Dart compiled to Javascript to
|
||||||
|
# differentiate from explicit Javascript files)
|
||||||
|
*.dart.js
|
||||||
|
*.part.js
|
||||||
|
*.js.deps
|
||||||
|
*.js.map
|
||||||
|
*.info.json
|
||||||
|
|
||||||
|
# Directory created by dartdoc
|
||||||
|
doc/api/
|
||||||
|
|
||||||
|
# Don't commit pubspec lock file
|
||||||
|
# (Library packages only! Remove pattern if developing an application package)
|
||||||
|
pubspec.lock
|
||||||
|
|
||||||
|
# Don’t commit files and directories created by other development environments.
|
||||||
|
# For example, if your development environment creates any of the following files,
|
||||||
|
# consider putting them in a global ignore file:
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Mac
|
||||||
|
.DS_Store
|
@ -0,0 +1,23 @@
|
|||||||
|
# OpenAPI Generator Ignore
|
||||||
|
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||||
|
|
||||||
|
# Use this file to prevent files from being overwritten by the generator.
|
||||||
|
# The patterns follow closely to .gitignore or .dockerignore.
|
||||||
|
|
||||||
|
# As an example, the C# client generator defines ApiClient.cs.
|
||||||
|
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||||
|
#ApiClient.cs
|
||||||
|
|
||||||
|
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||||
|
#foo/*/qux
|
||||||
|
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||||
|
#foo/**/qux
|
||||||
|
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can also negate patterns with an exclamation (!).
|
||||||
|
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||||
|
#docs/*.md
|
||||||
|
# Then explicitly reverse the ignore rule for a single file:
|
||||||
|
#!docs/README.md
|
@ -0,0 +1,15 @@
|
|||||||
|
.gitignore
|
||||||
|
README.md
|
||||||
|
analysis_options.yaml
|
||||||
|
build.yaml
|
||||||
|
doc/DefaultApi.md
|
||||||
|
lib/openapi.dart
|
||||||
|
lib/src/api.dart
|
||||||
|
lib/src/api/default_api.dart
|
||||||
|
lib/src/auth/api_key_auth.dart
|
||||||
|
lib/src/auth/auth.dart
|
||||||
|
lib/src/auth/basic_auth.dart
|
||||||
|
lib/src/auth/bearer_auth.dart
|
||||||
|
lib/src/auth/oauth.dart
|
||||||
|
lib/src/deserialize.dart
|
||||||
|
pubspec.yaml
|
@ -0,0 +1 @@
|
|||||||
|
7.14.0-SNAPSHOT
|
@ -0,0 +1,83 @@
|
|||||||
|
# openapi (EXPERIMENTAL)
|
||||||
|
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
|
||||||
|
This Dart package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
||||||
|
|
||||||
|
- API version: 1.0.0
|
||||||
|
- Generator version: 7.14.0-SNAPSHOT
|
||||||
|
- Build package: org.openapitools.codegen.languages.DartDioClientCodegen
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
* Dart 2.15.0+ or Flutter 2.8.0+
|
||||||
|
* Dio 5.0.0+ (https://pub.dev/packages/dio)
|
||||||
|
* JSON Serializable 6.1.5+ (https://pub.dev/packages/json_serializable)
|
||||||
|
|
||||||
|
## Installation & Usage
|
||||||
|
|
||||||
|
### pub.dev
|
||||||
|
To use the package from [pub.dev](https://pub.dev), please include the following in pubspec.yaml
|
||||||
|
```yaml
|
||||||
|
dependencies:
|
||||||
|
openapi: 1.0.0
|
||||||
|
```
|
||||||
|
|
||||||
|
### Github
|
||||||
|
If this Dart package is published to Github, please include the following in pubspec.yaml
|
||||||
|
```yaml
|
||||||
|
dependencies:
|
||||||
|
openapi:
|
||||||
|
git:
|
||||||
|
url: https://github.com/GIT_USER_ID/GIT_REPO_ID.git
|
||||||
|
#ref: main
|
||||||
|
```
|
||||||
|
|
||||||
|
### Local development
|
||||||
|
To use the package from your local drive, please include the following in pubspec.yaml
|
||||||
|
```yaml
|
||||||
|
dependencies:
|
||||||
|
openapi:
|
||||||
|
path: /path/to/openapi
|
||||||
|
```
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Please follow the [installation procedure](#installation--usage) and then run the following:
|
||||||
|
|
||||||
|
```dart
|
||||||
|
import 'package:openapi/openapi.dart';
|
||||||
|
|
||||||
|
|
||||||
|
final api = Openapi().getDefaultApi();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final response = await api.binaryResponse();
|
||||||
|
print(response);
|
||||||
|
} catch on DioException (e) {
|
||||||
|
print("Exception when calling DefaultApi->binaryResponse: $e\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Documentation for API Endpoints
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost*
|
||||||
|
|
||||||
|
Class | Method | HTTP request | Description
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
[*DefaultApi*](doc/DefaultApi.md) | [**binaryResponse**](doc/DefaultApi.md#binaryresponse) | **GET** /limits |
|
||||||
|
|
||||||
|
|
||||||
|
## Documentation For Models
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Documentation For Authorization
|
||||||
|
|
||||||
|
Endpoints do not require authorization.
|
||||||
|
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
analyzer:
|
||||||
|
language:
|
||||||
|
strict-inference: true
|
||||||
|
strict-raw-types: true
|
||||||
|
strict-casts: false
|
||||||
|
exclude:
|
||||||
|
- test/*.dart
|
||||||
|
- lib/src/model/*.g.dart
|
||||||
|
errors:
|
||||||
|
deprecated_member_use_from_same_package: ignore
|
@ -0,0 +1,18 @@
|
|||||||
|
targets:
|
||||||
|
$default:
|
||||||
|
builders:
|
||||||
|
json_serializable:
|
||||||
|
options:
|
||||||
|
# Options configure how source code is generated for every
|
||||||
|
# `@JsonSerializable`-annotated class in the package.
|
||||||
|
#
|
||||||
|
# The default value for each is listed.
|
||||||
|
any_map: false
|
||||||
|
checked: true
|
||||||
|
create_factory: true
|
||||||
|
create_to_json: true
|
||||||
|
disallow_unrecognized_keys: true
|
||||||
|
explicit_to_json: true
|
||||||
|
field_rename: none
|
||||||
|
ignore_unannotated: false
|
||||||
|
include_if_null: false
|
@ -0,0 +1,51 @@
|
|||||||
|
# openapi.api.DefaultApi
|
||||||
|
|
||||||
|
## Load the API package
|
||||||
|
```dart
|
||||||
|
import 'package:openapi/api.dart';
|
||||||
|
```
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost*
|
||||||
|
|
||||||
|
Method | HTTP request | Description
|
||||||
|
------------- | ------------- | -------------
|
||||||
|
[**binaryResponse**](DefaultApi.md#binaryresponse) | **GET** /limits |
|
||||||
|
|
||||||
|
|
||||||
|
# **binaryResponse**
|
||||||
|
> Uint8List binaryResponse()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Example
|
||||||
|
```dart
|
||||||
|
import 'package:openapi/api.dart';
|
||||||
|
|
||||||
|
final api = Openapi().getDefaultApi();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final response = api.binaryResponse();
|
||||||
|
print(response);
|
||||||
|
} catch on DioException (e) {
|
||||||
|
print('Exception when calling DefaultApi->binaryResponse: $e\n');
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
This endpoint does not need any parameter.
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
[**Uint8List**](Uint8List.md)
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: application/zip
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||||
|
|
@ -0,0 +1,14 @@
|
|||||||
|
//
|
||||||
|
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||||
|
//
|
||||||
|
|
||||||
|
export 'package:openapi/src/api.dart';
|
||||||
|
export 'package:openapi/src/auth/api_key_auth.dart';
|
||||||
|
export 'package:openapi/src/auth/basic_auth.dart';
|
||||||
|
export 'package:openapi/src/auth/bearer_auth.dart';
|
||||||
|
export 'package:openapi/src/auth/oauth.dart';
|
||||||
|
|
||||||
|
|
||||||
|
export 'package:openapi/src/api/default_api.dart';
|
||||||
|
|
||||||
|
|
@ -0,0 +1,68 @@
|
|||||||
|
//
|
||||||
|
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||||
|
//
|
||||||
|
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:openapi/src/auth/api_key_auth.dart';
|
||||||
|
import 'package:openapi/src/auth/basic_auth.dart';
|
||||||
|
import 'package:openapi/src/auth/bearer_auth.dart';
|
||||||
|
import 'package:openapi/src/auth/oauth.dart';
|
||||||
|
import 'package:openapi/src/api/default_api.dart';
|
||||||
|
|
||||||
|
class Openapi {
|
||||||
|
static const String basePath = r'http://localhost';
|
||||||
|
|
||||||
|
final Dio dio;
|
||||||
|
Openapi({
|
||||||
|
Dio? dio,
|
||||||
|
String? basePathOverride,
|
||||||
|
List<Interceptor>? interceptors,
|
||||||
|
}) :
|
||||||
|
this.dio = dio ??
|
||||||
|
Dio(BaseOptions(
|
||||||
|
baseUrl: basePathOverride ?? basePath,
|
||||||
|
connectTimeout: const Duration(milliseconds: 5000),
|
||||||
|
receiveTimeout: const Duration(milliseconds: 3000),
|
||||||
|
)) {
|
||||||
|
if (interceptors == null) {
|
||||||
|
this.dio.interceptors.addAll([
|
||||||
|
OAuthInterceptor(),
|
||||||
|
BasicAuthInterceptor(),
|
||||||
|
BearerAuthInterceptor(),
|
||||||
|
ApiKeyAuthInterceptor(),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
this.dio.interceptors.addAll(interceptors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setOAuthToken(String name, String token) {
|
||||||
|
if (this.dio.interceptors.any((i) => i is OAuthInterceptor)) {
|
||||||
|
(this.dio.interceptors.firstWhere((i) => i is OAuthInterceptor) as OAuthInterceptor).tokens[name] = token;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBearerAuth(String name, String token) {
|
||||||
|
if (this.dio.interceptors.any((i) => i is BearerAuthInterceptor)) {
|
||||||
|
(this.dio.interceptors.firstWhere((i) => i is BearerAuthInterceptor) as BearerAuthInterceptor).tokens[name] = token;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBasicAuth(String name, String username, String password) {
|
||||||
|
if (this.dio.interceptors.any((i) => i is BasicAuthInterceptor)) {
|
||||||
|
(this.dio.interceptors.firstWhere((i) => i is BasicAuthInterceptor) as BasicAuthInterceptor).authInfo[name] = BasicAuthInfo(username, password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setApiKey(String name, String apiKey) {
|
||||||
|
if (this.dio.interceptors.any((i) => i is ApiKeyAuthInterceptor)) {
|
||||||
|
(this.dio.interceptors.firstWhere((element) => element is ApiKeyAuthInterceptor) as ApiKeyAuthInterceptor).apiKeys[name] = apiKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get DefaultApi instance, base route and serializer can be overridden by a given but be careful,
|
||||||
|
/// by doing that all interceptors will not be executed
|
||||||
|
DefaultApi getDefaultApi() {
|
||||||
|
return DefaultApi(dio);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
//
|
||||||
|
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||||
|
//
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
// ignore: unused_import
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'package:openapi/src/deserialize.dart';
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
class DefaultApi {
|
||||||
|
|
||||||
|
final Dio _dio;
|
||||||
|
|
||||||
|
const DefaultApi(this._dio);
|
||||||
|
|
||||||
|
/// binaryResponse
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// Parameters:
|
||||||
|
/// * [cancelToken] - A [CancelToken] that can be used to cancel the operation
|
||||||
|
/// * [headers] - Can be used to add additional headers to the request
|
||||||
|
/// * [extras] - Can be used to add flags to the request
|
||||||
|
/// * [validateStatus] - A [ValidateStatus] callback that can be used to determine request success based on the HTTP status of the response
|
||||||
|
/// * [onSendProgress] - A [ProgressCallback] that can be used to get the send progress
|
||||||
|
/// * [onReceiveProgress] - A [ProgressCallback] that can be used to get the receive progress
|
||||||
|
///
|
||||||
|
/// Returns a [Future] containing a [Response] with a [Uint8List] as data
|
||||||
|
/// Throws [DioException] if API call or serialization fails
|
||||||
|
Future<Response<Uint8List>> binaryResponse({
|
||||||
|
CancelToken? cancelToken,
|
||||||
|
Map<String, dynamic>? headers,
|
||||||
|
Map<String, dynamic>? extra,
|
||||||
|
ValidateStatus? validateStatus,
|
||||||
|
ProgressCallback? onSendProgress,
|
||||||
|
ProgressCallback? onReceiveProgress,
|
||||||
|
}) async {
|
||||||
|
final _path = r'/limits';
|
||||||
|
final _options = Options(
|
||||||
|
method: r'GET',
|
||||||
|
responseType: ResponseType.bytes,
|
||||||
|
headers: <String, dynamic>{
|
||||||
|
...?headers,
|
||||||
|
},
|
||||||
|
extra: <String, dynamic>{
|
||||||
|
'secure': <Map<String, String>>[],
|
||||||
|
...?extra,
|
||||||
|
},
|
||||||
|
validateStatus: validateStatus,
|
||||||
|
);
|
||||||
|
|
||||||
|
final _response = await _dio.request<Object>(
|
||||||
|
_path,
|
||||||
|
options: _options,
|
||||||
|
cancelToken: cancelToken,
|
||||||
|
onSendProgress: onSendProgress,
|
||||||
|
onReceiveProgress: onReceiveProgress,
|
||||||
|
);
|
||||||
|
|
||||||
|
Uint8List? _responseData;
|
||||||
|
|
||||||
|
try {
|
||||||
|
final rawData = _response.data;
|
||||||
|
_responseData = rawData == null ? null : rawData as Uint8List;
|
||||||
|
|
||||||
|
} catch (error, stackTrace) {
|
||||||
|
throw DioException(
|
||||||
|
requestOptions: _response.requestOptions,
|
||||||
|
response: _response,
|
||||||
|
type: DioExceptionType.unknown,
|
||||||
|
error: error,
|
||||||
|
stackTrace: stackTrace,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response<Uint8List>(
|
||||||
|
data: _responseData,
|
||||||
|
headers: _response.headers,
|
||||||
|
isRedirect: _response.isRedirect,
|
||||||
|
requestOptions: _response.requestOptions,
|
||||||
|
redirects: _response.redirects,
|
||||||
|
statusCode: _response.statusCode,
|
||||||
|
statusMessage: _response.statusMessage,
|
||||||
|
extra: _response.extra,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:openapi/src/auth/auth.dart';
|
||||||
|
|
||||||
|
class ApiKeyAuthInterceptor extends AuthInterceptor {
|
||||||
|
final Map<String, String> apiKeys = {};
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
||||||
|
final authInfo = getAuthInfo(options, (secure) => secure['type'] == 'apiKey');
|
||||||
|
for (final info in authInfo) {
|
||||||
|
final authName = info['name'] as String;
|
||||||
|
final authKeyName = info['keyName'] as String;
|
||||||
|
final authWhere = info['where'] as String;
|
||||||
|
final apiKey = apiKeys[authName];
|
||||||
|
if (apiKey != null) {
|
||||||
|
if (authWhere == 'query') {
|
||||||
|
options.queryParameters[authKeyName] = apiKey;
|
||||||
|
} else {
|
||||||
|
options.headers[authKeyName] = apiKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onRequest(options, handler);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||||
|
//
|
||||||
|
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
|
||||||
|
abstract class AuthInterceptor extends Interceptor {
|
||||||
|
/// Get auth information on given route for the given type.
|
||||||
|
/// Can return an empty list if type is not present on auth data or
|
||||||
|
/// if route doesn't need authentication.
|
||||||
|
List<Map<String, String>> getAuthInfo(RequestOptions route, bool Function(Map<String, String> secure) handles) {
|
||||||
|
if (route.extra.containsKey('secure')) {
|
||||||
|
final auth = route.extra['secure'] as List<Map<String, String>>;
|
||||||
|
return auth.where((secure) => handles(secure)).toList();
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
//
|
||||||
|
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||||
|
//
|
||||||
|
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:openapi/src/auth/auth.dart';
|
||||||
|
|
||||||
|
class BasicAuthInfo {
|
||||||
|
final String username;
|
||||||
|
final String password;
|
||||||
|
|
||||||
|
const BasicAuthInfo(this.username, this.password);
|
||||||
|
}
|
||||||
|
|
||||||
|
class BasicAuthInterceptor extends AuthInterceptor {
|
||||||
|
final Map<String, BasicAuthInfo> authInfo = {};
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onRequest(
|
||||||
|
RequestOptions options,
|
||||||
|
RequestInterceptorHandler handler,
|
||||||
|
) {
|
||||||
|
final metadataAuthInfo = getAuthInfo(options, (secure) => (secure['type'] == 'http' && secure['scheme']?.toLowerCase() == 'basic') || secure['type'] == 'basic');
|
||||||
|
for (final info in metadataAuthInfo) {
|
||||||
|
final authName = info['name'] as String;
|
||||||
|
final basicAuthInfo = authInfo[authName];
|
||||||
|
if (basicAuthInfo != null) {
|
||||||
|
final basicAuth = 'Basic ${base64Encode(utf8.encode('${basicAuthInfo.username}:${basicAuthInfo.password}'))}';
|
||||||
|
options.headers['Authorization'] = basicAuth;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onRequest(options, handler);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
//
|
||||||
|
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||||
|
//
|
||||||
|
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:openapi/src/auth/auth.dart';
|
||||||
|
|
||||||
|
class BearerAuthInterceptor extends AuthInterceptor {
|
||||||
|
final Map<String, String> tokens = {};
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onRequest(
|
||||||
|
RequestOptions options,
|
||||||
|
RequestInterceptorHandler handler,
|
||||||
|
) {
|
||||||
|
final authInfo = getAuthInfo(options, (secure) => secure['type'] == 'http' && secure['scheme']?.toLowerCase() == 'bearer');
|
||||||
|
for (final info in authInfo) {
|
||||||
|
final token = tokens[info['name']];
|
||||||
|
if (token != null) {
|
||||||
|
options.headers['Authorization'] = 'Bearer ${token}';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onRequest(options, handler);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
//
|
||||||
|
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||||
|
//
|
||||||
|
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:openapi/src/auth/auth.dart';
|
||||||
|
|
||||||
|
class OAuthInterceptor extends AuthInterceptor {
|
||||||
|
final Map<String, String> tokens = {};
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onRequest(
|
||||||
|
RequestOptions options,
|
||||||
|
RequestInterceptorHandler handler,
|
||||||
|
) {
|
||||||
|
final authInfo = getAuthInfo(options, (secure) => secure['type'] == 'oauth' || secure['type'] == 'oauth2');
|
||||||
|
for (final info in authInfo) {
|
||||||
|
final token = tokens[info['name']];
|
||||||
|
if (token != null) {
|
||||||
|
options.headers['Authorization'] = 'Bearer ${token}';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onRequest(options, handler);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
final _regList = RegExp(r'^List<(.*)>$');
|
||||||
|
final _regSet = RegExp(r'^Set<(.*)>$');
|
||||||
|
final _regMap = RegExp(r'^Map<String,(.*)>$');
|
||||||
|
|
||||||
|
ReturnType deserialize<ReturnType, BaseType>(dynamic value, String targetType, {bool growable= true}) {
|
||||||
|
switch (targetType) {
|
||||||
|
case 'String':
|
||||||
|
return '$value' as ReturnType;
|
||||||
|
case 'int':
|
||||||
|
return (value is int ? value : int.parse('$value')) as ReturnType;
|
||||||
|
case 'bool':
|
||||||
|
if (value is bool) {
|
||||||
|
return value as ReturnType;
|
||||||
|
}
|
||||||
|
final valueString = '$value'.toLowerCase();
|
||||||
|
return (valueString == 'true' || valueString == '1') as ReturnType;
|
||||||
|
case 'double':
|
||||||
|
return (value is double ? value : double.parse('$value')) as ReturnType;
|
||||||
|
default:
|
||||||
|
RegExpMatch? match;
|
||||||
|
|
||||||
|
if (value is List && (match = _regList.firstMatch(targetType)) != null) {
|
||||||
|
targetType = match![1]!; // ignore: parameter_assignments
|
||||||
|
return value
|
||||||
|
.map<BaseType>((dynamic v) => deserialize<BaseType, BaseType>(v, targetType, growable: growable))
|
||||||
|
.toList(growable: growable) as ReturnType;
|
||||||
|
}
|
||||||
|
if (value is Set && (match = _regSet.firstMatch(targetType)) != null) {
|
||||||
|
targetType = match![1]!; // ignore: parameter_assignments
|
||||||
|
return value
|
||||||
|
.map<BaseType>((dynamic v) => deserialize<BaseType, BaseType>(v, targetType, growable: growable))
|
||||||
|
.toSet() as ReturnType;
|
||||||
|
}
|
||||||
|
if (value is Map && (match = _regMap.firstMatch(targetType)) != null) {
|
||||||
|
targetType = match![1]!.trim(); // ignore: parameter_assignments
|
||||||
|
return Map<String, BaseType>.fromIterables(
|
||||||
|
value.keys as Iterable<String>,
|
||||||
|
value.values.map((dynamic v) => deserialize<BaseType, BaseType>(v, targetType, growable: growable)),
|
||||||
|
) as ReturnType;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
throw Exception('Cannot deserialize');
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
name: openapi
|
||||||
|
version: 1.0.0
|
||||||
|
description: OpenAPI API client
|
||||||
|
homepage: homepage
|
||||||
|
|
||||||
|
|
||||||
|
environment:
|
||||||
|
sdk: '>=3.5.0 <4.0.0'
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
dio: '^5.7.0'
|
||||||
|
json_annotation: '^4.9.0'
|
||||||
|
|
||||||
|
dev_dependencies:
|
||||||
|
build_runner: any
|
||||||
|
json_serializable: '^6.9.3'
|
||||||
|
test: '^1.16.0'
|
@ -0,0 +1,16 @@
|
|||||||
|
import 'package:test/test.dart';
|
||||||
|
import 'package:openapi/openapi.dart';
|
||||||
|
|
||||||
|
|
||||||
|
/// tests for DefaultApi
|
||||||
|
void main() {
|
||||||
|
final instance = Openapi().getDefaultApi();
|
||||||
|
|
||||||
|
group(DefaultApi, () {
|
||||||
|
//Future<Uint8List> binaryResponse() async
|
||||||
|
test('test binaryResponse', () async {
|
||||||
|
// TODO
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
@ -84,6 +84,7 @@ _bodyData=jsonEncode(modelClient);
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<ModelClient, ModelClient>(rawData, 'ModelClient', growable: true);
|
_responseData = rawData == null ? null : deserialize<ModelClient, ModelClient>(rawData, 'ModelClient', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
|
@ -64,6 +64,7 @@ class DefaultApi {
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<FooGetDefaultResponse, FooGetDefaultResponse>(rawData, 'FooGetDefaultResponse', growable: true);
|
_responseData = rawData == null ? null : deserialize<FooGetDefaultResponse, FooGetDefaultResponse>(rawData, 'FooGetDefaultResponse', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
|
@ -74,6 +74,7 @@ class FakeApi {
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<FakeBigDecimalMap200Response, FakeBigDecimalMap200Response>(rawData, 'FakeBigDecimalMap200Response', growable: true);
|
_responseData = rawData == null ? null : deserialize<FakeBigDecimalMap200Response, FakeBigDecimalMap200Response>(rawData, 'FakeBigDecimalMap200Response', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
@ -143,6 +144,7 @@ _responseData = rawData == null ? null : deserialize<FakeBigDecimalMap200Respons
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<HealthCheckResult, HealthCheckResult>(rawData, 'HealthCheckResult', growable: true);
|
_responseData = rawData == null ? null : deserialize<HealthCheckResult, HealthCheckResult>(rawData, 'HealthCheckResult', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
@ -314,6 +316,7 @@ _bodyData=jsonEncode(body);
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<bool, bool>(rawData, 'bool', growable: true);
|
_responseData = rawData == null ? null : deserialize<bool, bool>(rawData, 'bool', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
@ -403,6 +406,7 @@ _bodyData=jsonEncode(outerComposite);
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<OuterComposite, OuterComposite>(rawData, 'OuterComposite', growable: true);
|
_responseData = rawData == null ? null : deserialize<OuterComposite, OuterComposite>(rawData, 'OuterComposite', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
@ -492,6 +496,7 @@ _bodyData=jsonEncode(body);
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<num, num>(rawData, 'num', growable: true);
|
_responseData = rawData == null ? null : deserialize<num, num>(rawData, 'num', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
@ -581,6 +586,7 @@ _bodyData=jsonEncode(body);
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<String, String>(rawData, 'String', growable: true);
|
_responseData = rawData == null ? null : deserialize<String, String>(rawData, 'String', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
@ -670,6 +676,7 @@ _bodyData=jsonEncode(outerObjectWithEnumProperty);
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<OuterObjectWithEnumProperty, OuterObjectWithEnumProperty>(rawData, 'OuterObjectWithEnumProperty', growable: true);
|
_responseData = rawData == null ? null : deserialize<OuterObjectWithEnumProperty, OuterObjectWithEnumProperty>(rawData, 'OuterObjectWithEnumProperty', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
@ -1027,6 +1034,7 @@ _bodyData=jsonEncode(modelClient);
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<ModelClient, ModelClient>(rawData, 'ModelClient', growable: true);
|
_responseData = rawData == null ? null : deserialize<ModelClient, ModelClient>(rawData, 'ModelClient', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
|
@ -91,6 +91,7 @@ _bodyData=jsonEncode(modelClient);
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<ModelClient, ModelClient>(rawData, 'ModelClient', growable: true);
|
_responseData = rawData == null ? null : deserialize<ModelClient, ModelClient>(rawData, 'ModelClient', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
|
@ -202,6 +202,7 @@ _bodyData=jsonEncode(pet);
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<List<Pet>, Pet>(rawData, 'List<Pet>', growable: true);
|
_responseData = rawData == null ? null : deserialize<List<Pet>, Pet>(rawData, 'List<Pet>', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
@ -284,6 +285,7 @@ _responseData = rawData == null ? null : deserialize<List<Pet>, Pet>(rawData, 'L
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<Set<Pet>, Pet>(rawData, 'Set<Pet>', growable: true);
|
_responseData = rawData == null ? null : deserialize<Set<Pet>, Pet>(rawData, 'Set<Pet>', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
@ -362,6 +364,7 @@ _responseData = rawData == null ? null : deserialize<Set<Pet>, Pet>(rawData, 'Se
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<Pet, Pet>(rawData, 'Pet', growable: true);
|
_responseData = rawData == null ? null : deserialize<Pet, Pet>(rawData, 'Pet', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
@ -604,6 +607,7 @@ _bodyData=jsonEncode(pet);
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<ApiResponse, ApiResponse>(rawData, 'ApiResponse', growable: true);
|
_responseData = rawData == null ? null : deserialize<ApiResponse, ApiResponse>(rawData, 'ApiResponse', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
@ -702,6 +706,7 @@ _responseData = rawData == null ? null : deserialize<ApiResponse, ApiResponse>(r
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<ApiResponse, ApiResponse>(rawData, 'ApiResponse', growable: true);
|
_responseData = rawData == null ? null : deserialize<ApiResponse, ApiResponse>(rawData, 'ApiResponse', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
|
@ -118,6 +118,7 @@ class StoreApi {
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<Map<String, int>, int>(rawData, 'Map<String, int>', growable: true);
|
_responseData = rawData == null ? null : deserialize<Map<String, int>, int>(rawData, 'Map<String, int>', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
@ -189,6 +190,7 @@ _responseData = rawData == null ? null : deserialize<Map<String, int>, int>(rawD
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<Order, Order>(rawData, 'Order', growable: true);
|
_responseData = rawData == null ? null : deserialize<Order, Order>(rawData, 'Order', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
@ -278,6 +280,7 @@ _bodyData=jsonEncode(order);
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<Order, Order>(rawData, 'Order', growable: true);
|
_responseData = rawData == null ? null : deserialize<Order, Order>(rawData, 'Order', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
|
@ -308,6 +308,7 @@ _bodyData=jsonEncode(user);
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<User, User>(rawData, 'User', growable: true);
|
_responseData = rawData == null ? null : deserialize<User, User>(rawData, 'User', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
@ -387,6 +388,7 @@ _responseData = rawData == null ? null : deserialize<User, User>(rawData, 'User'
|
|||||||
try {
|
try {
|
||||||
final rawData = _response.data;
|
final rawData = _response.data;
|
||||||
_responseData = rawData == null ? null : deserialize<String, String>(rawData, 'String', growable: true);
|
_responseData = rawData == null ? null : deserialize<String, String>(rawData, 'String', growable: true);
|
||||||
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
throw DioException(
|
throw DioException(
|
||||||
requestOptions: _response.requestOptions,
|
requestOptions: _response.requestOptions,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user