diff --git a/.github/workflows/samples-dart-build-test.yaml b/.github/workflows/samples-dart-build-test.yaml index 0855925cc552..bbf50e7cb93b 100644 --- a/.github/workflows/samples-dart-build-test.yaml +++ b/.github/workflows/samples-dart-build-test.yaml @@ -9,6 +9,7 @@ on: #- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/** - samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/** - samples/openapi3/client/petstore/dart-dio/oneof/** + - samples/openapi3/client/petstore/dart-dio/anyof/** - samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/** - samples/openapi3/client/petstore/dart-dio/binary_response/** - samples/openapi3/client/petstore/dart-dio/petstore-timemachine/** @@ -19,6 +20,7 @@ on: #- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/** - samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/** - samples/openapi3/client/petstore/dart-dio/oneof/** + - samples/openapi3/client/petstore/dart-dio/anyof/** - samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/** - samples/openapi3/client/petstore/dart-dio/binary_response/** - samples/openapi3/client/petstore/dart-dio/petstore-timemachine/** @@ -36,6 +38,7 @@ jobs: #- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/ - samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/ - samples/openapi3/client/petstore/dart-dio/oneof/ + - samples/openapi3/client/petstore/dart-dio/anyof/ - samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/ - samples/openapi3/client/petstore/dart-dio/binary_response/ - samples/openapi3/client/petstore/dart-dio/petstore-timemachine/ diff --git a/bin/configs/dart-dio-anyof.yaml b/bin/configs/dart-dio-anyof.yaml new file mode 100644 index 000000000000..8685bb0ad6a7 --- /dev/null +++ b/bin/configs/dart-dio-anyof.yaml @@ -0,0 +1,11 @@ +generatorName: dart-dio +outputDir: samples/openapi3/client/petstore/dart-dio/anyof +inputSpec: modules/openapi-generator/src/test/resources/3_0/dart-dio/built_value_anyof_primitive.yaml +templateDir: modules/openapi-generator/src/main/resources/dart/libraries/dio +typeMappings: + Client: "ModelClient" + File: "ModelFile" + EnumClass: "ModelEnumClass" +additionalProperties: + hideGenerationTimestamp: "true" + enumUnknownDefaultCase: "true" diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/.gitignore b/samples/openapi3/client/petstore/dart-dio/anyof/.gitignore new file mode 100644 index 000000000000..4298cdcbd1a2 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/.gitignore @@ -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 diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/.openapi-generator-ignore b/samples/openapi3/client/petstore/dart-dio/anyof/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/.openapi-generator-ignore @@ -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 diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/.openapi-generator/FILES b/samples/openapi3/client/petstore/dart-dio/anyof/.openapi-generator/FILES new file mode 100644 index 000000000000..65e37daf39f8 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/.openapi-generator/FILES @@ -0,0 +1,19 @@ +.gitignore +README.md +analysis_options.yaml +doc/DefaultApi.md +doc/FieldValue.md +lib/openapi.dart +lib/src/api.dart +lib/src/api/default_api.dart +lib/src/api_util.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/date_serializer.dart +lib/src/model/date.dart +lib/src/model/field_value.dart +lib/src/serializers.dart +pubspec.yaml diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/.openapi-generator/VERSION b/samples/openapi3/client/petstore/dart-dio/anyof/.openapi-generator/VERSION new file mode 100644 index 000000000000..8fc8df61083a --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.25.0-SNAPSHOT diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/README.md b/samples/openapi3/client/petstore/dart-dio/anyof/README.md new file mode 100644 index 000000000000..8b6f70a7d139 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/README.md @@ -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.25.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) + +## 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.getFieldValue(); + print(response); +} on DioException catch (e) { + print("Exception when calling DefaultApi->getFieldValue: $e\n"); +} + +``` + +## Documentation for API Endpoints + +All URIs are relative to *http://localhost* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +[*DefaultApi*](doc/DefaultApi.md) | [**getFieldValue**](doc/DefaultApi.md#getfieldvalue) | **GET** /field-value | + + +## Documentation For Models + + - [FieldValue](doc/FieldValue.md) + + +## Documentation For Authorization + +Endpoints do not require authorization. + + +## Author + + + diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/analysis_options.yaml b/samples/openapi3/client/petstore/dart-dio/anyof/analysis_options.yaml new file mode 100644 index 000000000000..16a95850087a --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/analysis_options.yaml @@ -0,0 +1,9 @@ +analyzer: + language: + strict-inference: true + strict-raw-types: true + strict-casts: false + exclude: + - test/*.dart + errors: + deprecated_member_use_from_same_package: ignore diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/doc/DefaultApi.md b/samples/openapi3/client/petstore/dart-dio/anyof/doc/DefaultApi.md new file mode 100644 index 000000000000..f1e16cc44fc1 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/doc/DefaultApi.md @@ -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 +------------- | ------------- | ------------- +[**getFieldValue**](DefaultApi.md#getfieldvalue) | **GET** /field-value | + + +# **getFieldValue** +> FieldValue getFieldValue() + + + +### Example +```dart +import 'package:openapi/api.dart'; + +final api = Openapi().getDefaultApi(); + +try { + final response = api.getFieldValue(); + print(response); +} on DioException catch (e) { + print('Exception when calling DefaultApi->getFieldValue: $e\n'); +} +``` + +### Parameters +This endpoint does not need any parameter. + +### Return type + +[**FieldValue**](FieldValue.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + +[[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) + diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/doc/FieldValue.md b/samples/openapi3/client/petstore/dart-dio/anyof/doc/FieldValue.md new file mode 100644 index 000000000000..ac2909f535de --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/doc/FieldValue.md @@ -0,0 +1,14 @@ +# openapi.model.FieldValue + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/lib/openapi.dart b/samples/openapi3/client/petstore/dart-dio/anyof/lib/openapi.dart new file mode 100644 index 000000000000..4d92db5987d3 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/lib/openapi.dart @@ -0,0 +1,16 @@ +// +// 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/serializers.dart'; +export 'package:openapi/src/model/date.dart'; + +export 'package:openapi/src/api/default_api.dart'; + +export 'package:openapi/src/model/field_value.dart'; + diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/api.dart b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/api.dart new file mode 100644 index 000000000000..3951a530bcd6 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/api.dart @@ -0,0 +1,113 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// + +import 'package:dio/dio.dart'; +import 'package:built_value/serializer.dart'; +import 'package:openapi/src/serializers.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; + final Serializers serializers; + + Openapi({ + Dio? dio, + Serializers? serializers, + String? basePathOverride, + List? interceptors, + }) : this.serializers = serializers ?? standardSerializers, + 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; + } + } + + /// Removes the OAuth token associated with the given [name]. + /// + /// If no [OAuthInterceptor] is registered or no token exists for the given + /// [name], this method has no effect. + void removeOAuthToken(String name) { + if (this.dio.interceptors.any((i) => i is OAuthInterceptor)) { + (this.dio.interceptors.firstWhere((i) => i is OAuthInterceptor) as OAuthInterceptor).tokens.remove(name); + } + } + + 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; + } + } + + /// Removes the bearer authentication token associated with the given [name]. + /// + /// If no [BearerAuthInterceptor] is registered or no token exists for the + /// given [name], this method has no effect. + void removeBearerAuth(String name) { + if (this.dio.interceptors.any((i) => i is BearerAuthInterceptor)) { + (this.dio.interceptors.firstWhere((i) => i is BearerAuthInterceptor) as BearerAuthInterceptor).tokens.remove(name); + } + } + + 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); + } + } + + /// Removes the basic authentication credentials associated with the given [name]. + /// + /// If no [BasicAuthInterceptor] is registered or no credentials exist for the + /// given [name], this method has no effect. + void removeBasicAuth(String name) { + if (this.dio.interceptors.any((i) => i is BasicAuthInterceptor)) { + (this.dio.interceptors.firstWhere((i) => i is BasicAuthInterceptor) as BasicAuthInterceptor).authInfo.remove(name); + } + } + + 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; + } + } + + /// Removes the API key associated with the given [name]. + /// + /// If no [ApiKeyAuthInterceptor] is registered or no API key exists for the + /// given [name], this method has no effect. + void removeApiKey(String name) { + if (this.dio.interceptors.any((i) => i is ApiKeyAuthInterceptor)) { + (this.dio.interceptors.firstWhere((element) => element is ApiKeyAuthInterceptor) as ApiKeyAuthInterceptor).apiKeys.remove(name); + } + } + + /// 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, serializers); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/api/default_api.dart b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/api/default_api.dart new file mode 100644 index 000000000000..b01c7b38f28d --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/api/default_api.dart @@ -0,0 +1,94 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// + +import 'dart:async'; + +import 'package:built_value/json_object.dart'; +import 'package:built_value/serializer.dart'; +import 'package:dio/dio.dart'; + +import 'package:openapi/src/model/field_value.dart'; + +class DefaultApi { + + final Dio _dio; + + final Serializers _serializers; + + const DefaultApi(this._dio, this._serializers); + + /// getFieldValue + /// + /// + /// 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 [FieldValue] as data + /// Throws [DioException] if API call or serialization fails + Future> getFieldValue({ + CancelToken? cancelToken, + Map? headers, + Map? extra, + ValidateStatus? validateStatus, + ProgressCallback? onSendProgress, + ProgressCallback? onReceiveProgress, + }) async { + final _path = r'/field-value'; + final _options = Options( + method: r'GET', + headers: { + ...?headers, + }, + extra: { + 'secure': >[], + ...?extra, + }, + validateStatus: validateStatus, + ); + + final _response = await _dio.request( + _path, + options: _options, + cancelToken: cancelToken, + onSendProgress: onSendProgress, + onReceiveProgress: onReceiveProgress, + ); + + FieldValue? _responseData; + + try { + final rawResponse = _response.data; + _responseData = rawResponse == null ? null : _serializers.deserialize( + rawResponse, + specifiedType: const FullType(FieldValue), + ) as FieldValue; + + } catch (error, stackTrace) { + throw DioException( + requestOptions: _response.requestOptions, + response: _response, + type: DioExceptionType.unknown, + error: error, + stackTrace: stackTrace, + ); + } + + return Response( + data: _responseData, + headers: _response.headers, + isRedirect: _response.isRedirect, + requestOptions: _response.requestOptions, + redirects: _response.redirects, + statusCode: _response.statusCode, + statusMessage: _response.statusMessage, + extra: _response.extra, + ); + } + +} diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/api_util.dart b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/api_util.dart new file mode 100644 index 000000000000..ed3bb12f25b8 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/api_util.dart @@ -0,0 +1,77 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// + +import 'dart:convert'; +import 'dart:typed_data'; + +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/serializer.dart'; +import 'package:dio/dio.dart'; + +/// Format the given form parameter object into something that Dio can handle. +/// Returns primitive or String. +/// Returns List/Map if the value is BuildList/BuiltMap. +dynamic encodeFormParameter(Serializers serializers, dynamic value, FullType type) { + if (value == null) { + return ''; + } + if (value is String || value is num || value is bool) { + return value; + } + final serialized = serializers.serialize( + value as Object, + specifiedType: type, + ); + if (serialized is String) { + return serialized; + } + if (value is BuiltList || value is BuiltSet || value is BuiltMap) { + return serialized; + } + return json.encode(serialized); +} + +dynamic encodeQueryParameter( + Serializers serializers, + dynamic value, + FullType type, +) { + if (value == null) { + return ''; + } + if (value is String || value is num || value is bool) { + return value; + } + if (value is Uint8List) { + // Currently not sure how to serialize this + return value; + } + final serialized = serializers.serialize( + value as Object, + specifiedType: type, + ); + if (serialized == null) { + return ''; + } + if (serialized is String) { + return serialized; + } + return serialized; +} + +ListParam encodeCollectionQueryParameter( + Serializers serializers, + dynamic value, + FullType type, { + ListFormat format = ListFormat.multi, +}) { + final serialized = serializers.serialize( + value as Object, + specifiedType: type, + ); + if (value is BuiltList || value is BuiltSet) { + return ListParam(List.of((serialized as Iterable).cast()), format); + } + throw ArgumentError('Invalid value passed to encodeCollectionQueryParameter'); +} diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/auth/api_key_auth.dart b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/auth/api_key_auth.dart new file mode 100644 index 000000000000..ee16e3f0f92f --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/auth/api_key_auth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/auth/auth.dart b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/auth/auth.dart new file mode 100644 index 000000000000..f7ae9bf3f11e --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/auth/auth.dart @@ -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> getAuthInfo(RequestOptions route, bool Function(Map secure) handles) { + if (route.extra.containsKey('secure')) { + final auth = route.extra['secure'] as List>; + return auth.where((secure) => handles(secure)).toList(); + } + return []; + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/auth/basic_auth.dart b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/auth/basic_auth.dart new file mode 100644 index 000000000000..b65ccb5b71f7 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/auth/basic_auth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/auth/bearer_auth.dart b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/auth/bearer_auth.dart new file mode 100644 index 000000000000..8f46678761b2 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/auth/bearer_auth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/auth/oauth.dart b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/auth/oauth.dart new file mode 100644 index 000000000000..337cf762b0ce --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/auth/oauth.dart @@ -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 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); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/date_serializer.dart b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/date_serializer.dart new file mode 100644 index 000000000000..db3c5c437db1 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/date_serializer.dart @@ -0,0 +1,31 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// + +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/serializer.dart'; +import 'package:openapi/src/model/date.dart'; + +class DateSerializer implements PrimitiveSerializer { + + const DateSerializer(); + + @override + Iterable get types => BuiltList.of([Date]); + + @override + String get wireName => 'Date'; + + @override + Date deserialize(Serializers serializers, Object serialized, + {FullType specifiedType = FullType.unspecified}) { + final parsed = DateTime.parse(serialized as String); + return Date(parsed.year, parsed.month, parsed.day); + } + + @override + Object serialize(Serializers serializers, Date date, + {FullType specifiedType = FullType.unspecified}) { + return date.toString(); + } +} diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/model/date.dart b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/model/date.dart new file mode 100644 index 000000000000..b21c7f544bee --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/model/date.dart @@ -0,0 +1,70 @@ +/// A gregorian calendar date generated by +/// OpenAPI generator to differentiate +/// between [DateTime] and [Date] formats. +class Date implements Comparable { + final int year; + + /// January is 1. + final int month; + + /// First day is 1. + final int day; + + Date(this.year, this.month, this.day); + + /// The current date + static Date now({bool utc = false}) { + var now = DateTime.now(); + if (utc) { + now = now.toUtc(); + } + return now.toDate(); + } + + /// Convert to a [DateTime]. + DateTime toDateTime({bool utc = false}) { + if (utc) { + return DateTime.utc(year, month, day); + } else { + return DateTime(year, month, day); + } + } + + @override + int compareTo(Date other) { + int d = year.compareTo(other.year); + if (d != 0) { + return d; + } + d = month.compareTo(other.month); + if (d != 0) { + return d; + } + return day.compareTo(other.day); + } + + @override + bool operator ==(Object other) => + identical(this, other) || + other is Date && + runtimeType == other.runtimeType && + year == other.year && + month == other.month && + day == other.day; + + @override + int get hashCode => year.hashCode ^ month.hashCode ^ day.hashCode; + + @override + String toString() { + final yyyy = year.toString(); + final mm = month.toString().padLeft(2, '0'); + final dd = day.toString().padLeft(2, '0'); + + return '$yyyy-$mm-$dd'; + } +} + +extension DateTimeToDate on DateTime { + Date toDate() => Date(year, month, day); +} diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/model/field_value.dart b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/model/field_value.dart new file mode 100644 index 000000000000..50601f853da6 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/model/field_value.dart @@ -0,0 +1,69 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// + +// ignore_for_file: unused_element +import 'dart:core'; +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; +import 'package:one_of/any_of.dart'; + +part 'field_value.g.dart'; + +/// FieldValue +@BuiltValue() +abstract class FieldValue implements Built { + /// Any Of [String], [int] + AnyOf get anyOf; + + FieldValue._(); + + factory FieldValue([void updates(FieldValueBuilder b)]) = _$FieldValue; + + @BuiltValueHook(initializeBuilder: true) + static void _defaults(FieldValueBuilder b) => b; + + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$FieldValueSerializer(); +} + +class _$FieldValueSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [FieldValue, _$FieldValue]; + + @override + final String wireName = r'FieldValue'; + + Iterable _serializeProperties( + Serializers serializers, + FieldValue object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + } + + @override + Object serialize( + Serializers serializers, + FieldValue object, { + FullType specifiedType = FullType.unspecified, + }) { + final anyOf = object.anyOf; + return serializers.serialize(anyOf, specifiedType: FullType(AnyOf, anyOf.types.map((type) => FullType(type)).toList()))!; + } + + @override + FieldValue deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = FieldValueBuilder(); + Object? anyOfDataSrc; + final targetType = const FullType(AnyOf, [FullType(int), FullType(String), ]); + anyOfDataSrc = serialized; + result.anyOf = serializers.deserialize(anyOfDataSrc, specifiedType: targetType) as AnyOf; + return result.build(); + } +} + + diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/serializers.dart b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/serializers.dart new file mode 100644 index 000000000000..705fc5d7d3c0 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/lib/src/serializers.dart @@ -0,0 +1,32 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// + +// ignore_for_file: unused_import + +import 'package:one_of_serializer/any_of_serializer.dart'; +import 'package:one_of_serializer/one_of_serializer.dart'; +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/json_object.dart'; +import 'package:built_value/serializer.dart'; +import 'package:built_value/standard_json_plugin.dart'; +import 'package:built_value/iso_8601_date_time_serializer.dart'; +import 'package:openapi/src/date_serializer.dart'; +import 'package:openapi/src/model/date.dart'; + +import 'package:openapi/src/model/field_value.dart'; + +part 'serializers.g.dart'; + +@SerializersFor([ + FieldValue, +]) +Serializers serializers = (_$serializers.toBuilder() + ..add(const OneOfSerializer()) + ..add(const AnyOfSerializer()) + ..add(const DateSerializer()) + ..add(Iso8601DateTimeSerializer()) + ).build(); + +Serializers standardSerializers = + (serializers.toBuilder()..addPlugin(StandardJsonPlugin())).build(); diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/pubspec.yaml b/samples/openapi3/client/petstore/dart-dio/anyof/pubspec.yaml new file mode 100644 index 000000000000..d4121509b909 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/pubspec.yaml @@ -0,0 +1,20 @@ +name: openapi +version: 1.0.0 +description: OpenAPI API client +homepage: homepage + + +environment: + sdk: '>=2.18.0 <4.0.0' + +dependencies: + dio: '^5.7.0' + one_of: '>=1.5.0 <2.0.0' + one_of_serializer: '>=1.5.0 <2.0.0' + built_value: '>=8.4.0 <9.0.0' + built_collection: '>=5.1.1 <6.0.0' + +dev_dependencies: + built_value_generator: '>=8.4.0 <9.0.0' + build_runner: any + test: '^1.16.0' diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/test/default_api_test.dart b/samples/openapi3/client/petstore/dart-dio/anyof/test/default_api_test.dart new file mode 100644 index 000000000000..1982fd46d794 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/test/default_api_test.dart @@ -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 getFieldValue() async + test('test getFieldValue', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/anyof/test/field_value_test.dart b/samples/openapi3/client/petstore/dart-dio/anyof/test/field_value_test.dart new file mode 100644 index 000000000000..1cf26b058782 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/anyof/test/field_value_test.dart @@ -0,0 +1,11 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for FieldValue +void main() { + final instance = FieldValueBuilder(); + // TODO add properties to the builder and call build() + + group(FieldValue, () { + }); +}