Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 23.9 #82

Merged
merged 14 commits into from
Sep 22, 2023
6 changes: 3 additions & 3 deletions codegen/Templates/dart/README.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Aspose.BarCode Cloud SDK for Dart

[![Dart test](https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-dart/actions/workflows/dart-compile.yml/badge.svg?branch=main)](https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-dart/actions/workflows/dart-compile.yml)
[![Dart test](https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-dart/actions/workflows/dart.yml/badge.svg?branch=main)](https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-dart/actions/workflows/dart.yml)

- API version: {{appVersion}}
- SDK version: {{pubVersion}}
Expand Down Expand Up @@ -44,7 +44,7 @@ dependencies:
The examples below show how you can generate QR barcode and save it into a local file and then recognize using **{{pubName}}**:

```dart
import 'package:aspose_barcode_cloud/api.dart' as barcode;
import 'package:aspose_barcode_cloud/aspose_barcode_cloud.dart' as barcode;

import 'dart:typed_data';
import 'dart:io';
Expand All @@ -65,7 +65,7 @@ Future<void> main() async {
Uint8List? generated =
await api.getBarcodeGenerate("QR", "text", textLocation: "None");
// Save generated image to file
await new File(fileName).writeAsBytes(generated!);
await File(fileName).writeAsBytes(generated!);
print("Generated image saved to " + fileName);

// Recognize generated image
Expand Down
16 changes: 10 additions & 6 deletions codegen/Templates/dart/api.mustache
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
part of {{pubName}}.api;
import 'dart:typed_data' show Uint8List;

{{#operations}}
import 'package:http/http.dart' show MultipartFile, MultipartRequest;

import '../../aspose_barcode_cloud.dart';
import '../api_helper.dart';

{{#operations}}

class {{classname}} {
{{classname}}(this.apiClient) {}
Expand Down Expand Up @@ -30,7 +34,7 @@ class {{classname}} {
{{^required}}
if({{paramName}} != null) {
{{/required}}
queryParams.addAll(_convertParametersForCollectionFormat("{{collectionFormat}}", "{{baseName}}", {{paramName}}));
queryParams.addAll(convertParametersForCollectionFormat("{{collectionFormat}}", "{{baseName}}", {{paramName}}));
{{^required}}
}
{{/required}}
Expand All @@ -53,7 +57,7 @@ class {{classname}} {
mp.fields['{{baseName}}'] = parameterToString({{paramName}});
}
{{/notFile}}{{#isFile}}
mp = new MultipartRequest('{{httpMethod}}', Uri.parse(requestPath));
mp = MultipartRequest('{{httpMethod}}', Uri.parse(requestPath));
// ignore: unnecessary_null_comparison
if ({{paramName}} != null) {
hasFields = true;
Expand Down Expand Up @@ -83,15 +87,15 @@ class {{classname}} {
authNames);

if(response.statusCode >= 400) {
throw new ApiException(response.statusCode, response.body);
throw ApiException(response.statusCode, response.body);
} else {
return
{{#isListContainer}}
{{#returnType}}(apiClient.deserialize(response.body, '{{{returnType}}}') as List).map((item) => item as {{returnBaseType}}).toList();{{/returnType}}
{{/isListContainer}}
{{^isListContainer}}
{{#isMapContainer}}
{{#returnType}}new {{{returnType}}}.from(apiClient.deserialize(response.body, '{{{returnType}}}')) {{/returnType}};
{{#returnType}}{{{returnType}}}.from(apiClient.deserialize(response.body, '{{{returnType}}}')) {{/returnType}};
{{/isMapContainer}}
{{^isMapContainer}}
{{#isResponseFile}}
Expand Down
82 changes: 44 additions & 38 deletions codegen/Templates/dart/api_client.mustache
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
part of {{pubName}}.api;
import 'dart:convert' show json;

class QueryParam {
String name;
String value;
import 'package:http/http.dart' as Http show Client, MultipartRequest, Response;

QueryParam(this.name, this.value);
}
import '../aspose_barcode_cloud.dart';
import 'api_helper.dart';
import 'auth/authentication.dart';
import 'auth/oauth.dart';

const String SDK_VERSION = "{{pubVersion}}";

class ApiClient {

String basePath;
final client = new {{#browserClient}}Browser{{/browserClient}}Client();
late final String basePath;
final httpClient = Http.Client();

static const String API_SDK_HEADER = "x-aspose-client";
static const String SDK_NAME = "dart sdk";
static const String API_CLIENT_VERSION_HEADER = "x-aspose-client-version";

Map<String, String> _defaultHeaderMap = {
API_SDK_HEADER: SDK_NAME,
API_CLIENT_VERSION_HEADER: SDK_VERSION,
};

Map<String, String> _defaultHeaderMap = {};
late Authentication _authentication;

final _regList = new RegExp(r'^List<(.*)>$');
final _regMap = new RegExp(r'^Map<String,(.*)>$');

ApiClient(
{String? clientId,
String? clientSecret,
String? accessToken,
tokenUrl = "https://api.aspose.cloud/connect/token",
this.basePath = "https://api.aspose.cloud/v3.0"}) {
_authentication = new OAuth(
clientId: clientId,
clientSecret: clientSecret,
accessToken: accessToken,
tokenUrl: tokenUrl);
final _regList = RegExp(r'^List<(.*)>$');
final _regMap = RegExp(r'^Map<String,(.*)>$');

ApiClient(Configuration config) {
this.basePath = config.basePath;
_authentication = OAuth(
clientId: config.clientId,
clientSecret: config.clientSecret,
accessToken: config.accessToken,
tokenUrl: config.tokenUrl);
}

void addDefaultHeader(String key, String value) {
Expand All @@ -50,10 +56,10 @@ class ApiClient {
{{#model}}
case '{{classname}}':
{{#isEnum}}
return new {{classname}}.fromJson(value);
return {{classname}}.fromJson(value);
{{/isEnum}}
{{^isEnum}}
return new {{classname}}.fromJson(value);
return {{classname}}.fromJson(value);
{{/isEnum}}
{{/model}}
{{/models}}
Expand All @@ -67,15 +73,15 @@ class ApiClient {
} else if (value is Map &&
(match = _regMap.firstMatch(targetType)) != null) {
final newTargetType = match![1];
return new Map.fromIterables(value.keys,
return Map.fromIterables(value.keys,
value.values.map((v) => _deserialize(v, newTargetType!)));
}
}
}
} on Exception catch (e, stack) {
throw new ApiException.withInner(0, 'Exception during deserialization.', e, stack);
throw ApiException.withInner(0, 'Exception during deserialization.', e, stack);
}
throw new ApiException(0, 'Could not find a suitable class for deserialization');
throw ApiException(0, 'Could not find a suitable class for deserialization');
}

dynamic deserialize(String jsonVal, String targetType) {
Expand All @@ -102,7 +108,7 @@ class ApiClient {

// We don't use a Map<String, String> for queryParams.
// If collectionFormat is 'multi' a key might appear multiple times.
Future<Response> invokeAPI(String path,
Future<Http.Response> invokeAPI(String path,
String method,
List<QueryParam> queryParams,
Object? body,
Expand All @@ -123,27 +129,27 @@ class ApiClient {
headerParams.addAll(_defaultHeaderMap);
headerParams['Content-Type'] = contentType;

if(body is MultipartRequest) {
final request = new MultipartRequest(method, Uri.parse(url));
if(body is Http.MultipartRequest) {
final request = Http.MultipartRequest(method, Uri.parse(url));
request.fields.addAll(body.fields);
request.files.addAll(body.files);
request.headers.addAll(body.headers);
request.headers.addAll(headerParams);
final response = await client.send(request);
return Response.fromStream(response);
final response = await httpClient.send(request);
return Http.Response.fromStream(response);
} else {
final msgBody = contentType == "application/x-www-form-urlencoded" ? formParams : serialize(body);
switch(method) {
case "POST":
return client.post(Uri.parse(url), headers: headerParams, body: msgBody);
return httpClient.post(Uri.parse(url), headers: headerParams, body: msgBody);
case "PUT":
return client.put(Uri.parse(url), headers: headerParams, body: msgBody);
return httpClient.put(Uri.parse(url), headers: headerParams, body: msgBody);
case "DELETE":
return client.delete(Uri.parse(url), headers: headerParams);
return httpClient.delete(Uri.parse(url), headers: headerParams);
case "PATCH":
return client.patch(Uri.parse(url), headers: headerParams, body: msgBody);
return httpClient.patch(Uri.parse(url), headers: headerParams, body: msgBody);
default:
return client.get(Uri.parse(url), headers: headerParams);
return httpClient.get(Uri.parse(url), headers: headerParams);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions codegen/Templates/dart/api_doc.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## Load the API package
```dart
import 'package:{{pubName}}/api.dart';
import 'package:{{pubName}}/aspose_barcode_cloud.dart';
```

All URIs are relative to *{{basePath}}*
Expand All @@ -24,7 +24,7 @@ Method | HTTP request | Description

### Example
```dart
import 'package:{{pubName}}/api.dart';
import 'package:{{pubName}}/aspose_barcode_cloud.dart';
{{#hasAuthMethods}}
{{#authMethods}}
{{#isBasic}}
Expand All @@ -45,9 +45,9 @@ import 'package:{{pubName}}/api.dart';
{{/authMethods}}
{{/hasAuthMethods}}

final api_instance = new {{classname}}();
final api_instance = {{classname}}();
{{#allParams}}
final {{paramName}} = {{#isListContainer}}[{{/isListContainer}}{{#isBodyParam}}new {{dataType}}(){{/isBodyParam}}{{^isBodyParam}}{{{example}}}{{/isBodyParam}}{{#isListContainer}}]{{/isListContainer}}; // {{{dataType}}} | {{{description}}}
final {{paramName}} = {{#isListContainer}}[{{/isListContainer}}{{#isBodyParam}}{{dataType}}(){{/isBodyParam}}{{^isBodyParam}}{{{example}}}{{/isBodyParam}}{{#isListContainer}}]{{/isListContainer}}; // {{{dataType}}} | {{{description}}}
{{/allParams}}

try {
Expand Down
2 changes: 0 additions & 2 deletions codegen/Templates/dart/api_exception.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
part of {{pubName}}.api;

class ApiException implements Exception {
int code = 0;
String? message = null;
Expand Down
17 changes: 12 additions & 5 deletions codegen/Templates/dart/api_helper.mustache
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
part of {{pubName}}.api;
import '../aspose_barcode_cloud.dart';

const _delimiters = const {'csv': ',', 'ssv': ' ', 'tsv': '\t', 'pipes': '|'};

class QueryParam {
String name;
String value;

QueryParam(this.name, this.value);
}

// port from Java version
Iterable<QueryParam> _convertParametersForCollectionFormat(
Iterable<QueryParam> convertParametersForCollectionFormat(
String collectionFormat, String name, dynamic value) {
final params = <QueryParam>[];

Expand All @@ -13,7 +20,7 @@ Iterable<QueryParam> _convertParametersForCollectionFormat(
}

if (value is! List) {
params.add(new QueryParam(name, parameterToString(value)));
params.add(QueryParam(name, parameterToString(value)));
return params;
}

Expand All @@ -23,12 +30,12 @@ Iterable<QueryParam> _convertParametersForCollectionFormat(
collectionFormat = collectionFormat.isEmpty ? "csv" : collectionFormat; // default: csv

if (collectionFormat == "multi") {
return values.map((v) => new QueryParam(name, parameterToString(v)));
return values.map((v) => QueryParam(name, parameterToString(v)));
}

final String delimiter = _delimiters[collectionFormat] ?? ",";

params.add(new QueryParam(name, values.map((v) => parameterToString(v)).join(delimiter)));
params.add(QueryParam(name, values.map((v) => parameterToString(v)).join(delimiter)));
return params;
}

Expand Down
18 changes: 5 additions & 13 deletions codegen/Templates/dart/apilib.mustache
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
library {{pubName}}.api;

import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';{{#browserClient}}
import 'package:http/browser_client.dart';{{/browserClient}}
import 'package:http/http.dart';
export 'src/configuration.dart' show Configuration;
export 'src/api_client.dart' show ApiClient, SDK_VERSION;
export 'src/api_exception.dart' show ApiException;

part 'api_client.dart';
part 'api_helper.dart';
part 'api_exception.dart';
part 'auth/authentication.dart';
part 'auth/oauth.dart';

{{#apiInfo}}{{#apis}}part 'api/{{classFilename}}.dart';
{{#apiInfo}}{{#apis}}export 'src/api/{{classFilename}}.dart' show {{classname}};
{{/apis}}{{/apiInfo}}
{{#models}}{{#model}}part 'model/{{classFilename}}.dart';
{{#models}}{{#model}}export 'src/model/{{classFilename}}.dart' show {{classname}};
{{/model}}{{/models}}
4 changes: 1 addition & 3 deletions codegen/Templates/dart/auth/api_key_auth.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
part of {{pubName}}.api;

class ApiKeyAuth implements Authentication {

final String location;
Expand All @@ -19,7 +17,7 @@ class ApiKeyAuth implements Authentication {
}

if (location == 'query' && value != null) {
queryParams.add(new QueryParam(paramName, value));
queryParams.add(QueryParam(paramName, value));
} else if (location == 'header' && value != null) {
headerParams[paramName] = value;
}
Expand Down
2 changes: 1 addition & 1 deletion codegen/Templates/dart/auth/authentication.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of {{pubName}}.api;
import '../api_helper.dart';

abstract class Authentication {

Expand Down
2 changes: 0 additions & 2 deletions codegen/Templates/dart/auth/http_basic_auth.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
part of {{pubName}}.api;

class HttpBasicAuth implements Authentication {

String? username;
Expand Down
12 changes: 9 additions & 3 deletions codegen/Templates/dart/auth/oauth.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
part of {{pubName}}.api;
import 'dart:convert' show jsonDecode;

import 'package:http/http.dart' show MultipartRequest;

import '../api_exception.dart';
import '../api_helper.dart';
import 'authentication.dart';

class OAuth implements Authentication {
String? clientId;
Expand All @@ -25,12 +31,12 @@ class OAuth implements Authentication {
if (clientId != null && clientSecret != null) {
await fetchToken(clientId!, clientSecret!);
} else {
throw new ApiException(0, "clientId or clientSecret not defined");
throw ApiException(0, "clientId or clientSecret not defined");
}
}

if (accessToken == null) {
throw new ApiException(0, "accessToken is null");
throw ApiException(0, "accessToken is null");
}
headerParams["Authorization"] = "Bearer " + accessToken!;
}
Expand Down
Loading