Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bin/configs/dart-dio-binary-response.yaml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,17 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
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";
}
}
Comment on lines +673 to +682
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a previous iteration I implemented the same logic as the built_value serialization method, where both parameter and return types are considered Uint8List

In an effort to keep this change slightly less impactful, I've opted to just change the return type when the response is a file

I'm open to input on this change, whether we want parity with built_value (both parameters and return types are Uint8List) or are ok with what I have here


resultImports.addAll(rewriteImports(op.imports, false));

if (SERIALIZATION_LIBRARY_BUILT_VALUE.equals(library)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
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}}
16 changes: 16 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/issue_20682.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.14.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -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



Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)

Original file line number Diff line number Diff line change
@@ -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';


Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading
Loading