diff --git a/.github/.test/samples.json b/.github/.test/samples.json index 7c1fa1e23353841b8db1fc30d5be48db40b63617..4683eb01986b5f41006d59b07f816536e3386dc3 100644 --- a/.github/.test/samples.json +++ b/.github/.test/samples.json @@ -151,6 +151,12 @@ "Client: Dart" ] }, + { + "input": "dart-dio-petstore.sh", + "matches": [ + "Client: Dart" + ] + }, { "input": "dart-petstore.sh", "matches": [ diff --git a/bin/utils/ensure-up-to-date b/bin/utils/ensure-up-to-date index 3251835821d072e2346bce6316fb02ca7942ab19..19ae855e6f52007425ecfc219507621bd298f447 100755 --- a/bin/utils/ensure-up-to-date +++ b/bin/utils/ensure-up-to-date @@ -65,6 +65,7 @@ declare -a scripts=( "./bin/apex-petstore.sh" "./bin/perl-petstore-all.sh" "./bin/dart-jaguar-petstore.sh" +"./bin/dart-dio-petstore.sh" "./bin/dart-petstore.sh" "./bin/dart2-petstore.sh" "./bin/java-play-framework-petstore-server-all.sh" diff --git a/docs/generators.md b/docs/generators.md index 262a9355c5ec914fe82879afd30595b5d6856d94..734fbfbf37d4c411d64b641a85d1d22a1af7f34b 100644 --- a/docs/generators.md +++ b/docs/generators.md @@ -6,6 +6,7 @@ title: Generators List The following generators are available: ## CLIENT generators + * [ada](generators/ada) * [android](generators/android) * [apex](generators/apex) diff --git a/docs/generators/README.md b/docs/generators/README.md index 6c3328cc0725958615bc379943a28eb7d455fe75..070ef96c15e216d9490ae8f2ac8db32e5b7c68c7 100644 --- a/docs/generators/README.md +++ b/docs/generators/README.md @@ -14,6 +14,7 @@ The following generators are available: - [csharp-dotnet2](csharp-dotnet2.md) - [csharp-refactor](csharp-refactor.md) - [dart](dart.md) + - [dart-dio](dart-dio.md) - [dart-jaguar](dart-jaguar.md) - [eiffel](eiffel.md) - [elixir](elixir.md) diff --git a/docs/generators/dart-dio.md b/docs/generators/dart-dio.md new file mode 100644 index 0000000000000000000000000000000000000000..dde7792b29435f516942e66ca6e457e874dc0c41 --- /dev/null +++ b/docs/generators/dart-dio.md @@ -0,0 +1,21 @@ + +--- +id: generator-opts-client-dart-dio +title: Config Options for dart-dio +sidebar_label: dart-dio +--- + +| Option | Description | Values | Default | +| ------ | ----------- | ------ | ------- | +|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| +|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false| +|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false| +|browserClient|Is the client browser based (for Dart 1.x only)| |null| +|pubName|Name in generated pubspec| |null| +|pubVersion|Version in generated pubspec| |null| +|pubDescription|Description in generated pubspec| |null| +|useEnumExtension|Allow the 'x-enum-values' extension for enums| |null| +|sourceFolder|Source folder for generated code| |null| +|supportDart2|Support Dart 2.x (Dart 1.x support has been deprecated)| |true| +|nullableFields|Is the null fields should be in the JSON payload| |null| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java new file mode 100644 index 0000000000000000000000000000000000000000..5bc9c83280807931484d043aff07e49640fbe04f --- /dev/null +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java @@ -0,0 +1,277 @@ +/* + * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openapitools.codegen.languages; + +import org.apache.commons.lang3.StringUtils; +import org.openapitools.codegen.CliOption; +import org.openapitools.codegen.CodegenConstants; +import org.openapitools.codegen.CodegenModel; +import org.openapitools.codegen.CodegenOperation; +import org.openapitools.codegen.CodegenParameter; +import org.openapitools.codegen.CodegenProperty; +import org.openapitools.codegen.SupportingFile; +import org.openapitools.codegen.utils.ModelUtils; +import org.openapitools.codegen.utils.ProcessUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import io.swagger.v3.oas.models.media.Schema; + +import static org.openapitools.codegen.utils.StringUtils.underscore; + +public class DartDioClientCodegen extends DartClientCodegen { + private static final Logger LOGGER = LoggerFactory.getLogger(DartDioClientCodegen.class); + + private static final String NULLABLE_FIELDS = "nullableFields"; + private static final String IS_FORMAT_JSON = "jsonFormat"; + private static final String CLIENT_NAME = "clientName"; + + private static Set<String> modelToIgnore = new HashSet<>(); + + static { + modelToIgnore.add("datetime"); + modelToIgnore.add("map"); + modelToIgnore.add("object"); + modelToIgnore.add("list"); + modelToIgnore.add("file"); + modelToIgnore.add("uint8list"); + } + + private static final String SERIALIZATION_JSON = "json"; + + private boolean nullableFields = true; + private String serialization = SERIALIZATION_JSON; + + public DartDioClientCodegen() { + super(); + browserClient = false; + outputFolder = "generated-code/dart-dio"; + embeddedTemplateDir = templateDir = "dart-dio"; + + //no tests at this time + modelTestTemplateFiles.clear(); + apiTestTemplateFiles.clear(); + + cliOptions.add(new CliOption(NULLABLE_FIELDS, "Is the null fields should be in the JSON payload")); + + typeMapping.put("file", "Uint8List"); + typeMapping.put("binary", "Uint8List"); + + importMapping.put("BuiltList", "built_collection/built_collection"); + importMapping.put("BuiltMap", "built_collection/built_collection"); + } + + @Override + public String getName() { + return "dart-dio"; + } + + @Override + public String getHelp() { + return "Generates a Dart Dio client library."; + } + + @Override + public String toDefaultValue(Schema p) { + if (ModelUtils.isMapSchema(p)) { + return "const {}"; + } else if (ModelUtils.isArraySchema(p)) { + return "const []"; + } + return super.toDefaultValue(p); + } + + @Override + public void processOpts() { + if (StringUtils.isEmpty(System.getenv("DART_POST_PROCESS_FILE"))) { + LOGGER.info("Environment variable DART_POST_PROCESS_FILE not defined so the Dart code may not be properly formatted. To define it, try `export DART_POST_PROCESS_FILE=\"/usr/local/bin/dartfmt -w\"` (Linux/Mac)"); + LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI)."); + } + + if (additionalProperties.containsKey(NULLABLE_FIELDS)) { + nullableFields = convertPropertyToBooleanAndWriteBack(NULLABLE_FIELDS); + } else { + //not set, use to be passed to template + additionalProperties.put(NULLABLE_FIELDS, nullableFields); + } + + additionalProperties.put(IS_FORMAT_JSON, true); + + if (additionalProperties.containsKey(PUB_NAME)) { + this.setPubName((String) additionalProperties.get(PUB_NAME)); + } else { + //not set, use to be passed to template + additionalProperties.put(PUB_NAME, pubName); + } + + if (!additionalProperties.containsKey(CLIENT_NAME)) { + additionalProperties.put(CLIENT_NAME, org.openapitools.codegen.utils.StringUtils.camelize(pubName)); + } + + if (additionalProperties.containsKey(PUB_VERSION)) { + this.setPubVersion((String) additionalProperties.get(PUB_VERSION)); + } else { + //not set, use to be passed to template + additionalProperties.put(PUB_VERSION, pubVersion); + } + + if (additionalProperties.containsKey(PUB_DESCRIPTION)) { + this.setPubDescription((String) additionalProperties.get(PUB_DESCRIPTION)); + } else { + //not set, use to be passed to template + additionalProperties.put(PUB_DESCRIPTION, pubDescription); + } + + if (additionalProperties.containsKey(USE_ENUM_EXTENSION)) { + this.setUseEnumExtension(convertPropertyToBooleanAndWriteBack(USE_ENUM_EXTENSION)); + } else { + // Not set, use to be passed to template. + additionalProperties.put(USE_ENUM_EXTENSION, useEnumExtension); + } + + if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) { + this.setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER)); + } + + // make api and model doc path available in mustache template + additionalProperties.put("apiDocPath", apiDocPath); + additionalProperties.put("modelDocPath", modelDocPath); + + final String libFolder = sourceFolder + File.separator + "lib"; + supportingFiles.add(new SupportingFile("pubspec.mustache", "", "pubspec.yaml")); + supportingFiles.add(new SupportingFile("analysis_options.mustache", "", "analysis_options.yaml")); + supportingFiles.add(new SupportingFile("apilib.mustache", libFolder, "api.dart")); + supportingFiles.add(new SupportingFile("serializers.mustache", libFolder, "serializers.dart")); + + supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore")); + supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); + } + + @Override + public Map<String, Object> postProcessModels(Map<String, Object> objs) { + objs = super.postProcessModels(objs); + List<Object> models = (List<Object>) objs.get("models"); + ProcessUtils.addIndexToProperties(models, 1); + for (Object _mo : models) { + Map<String, Object> mo = (Map<String, Object>) _mo; + Set<String> modelImports = new HashSet<>(); + CodegenModel cm = (CodegenModel) mo.get("model"); + for (String modelImport : cm.imports) { + if (importMapping.containsKey(modelImport)) { + modelImports.add(importMapping.get(modelImport)); + } else { + if (!modelToIgnore.contains(modelImport.toLowerCase(Locale.ROOT))) { + modelImports.add(pubName + "/model/" + underscore(modelImport)); + } + } + } + + cm.imports = modelImports; + cm.vendorExtensions.put("hasVars", cm.vars.size() > 0); + } + return objs; + } + + @Override + public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { + if (nullableFields) { + property.isNullable = true; + } + + if (property.isListContainer) { + //Updates any List properties on a model to a BuiltList. This happens in post processing rather + //than type mapping as we only want this to apply to models, not every other class. + if ("List".equals(property.baseType)) { + property.setDatatype(property.dataType.replaceAll(property.baseType, "BuiltList")); + property.setBaseType("BuiltList"); + model.imports.add("BuiltList"); + } + } + if (property.isMapContainer) { + //Updates any List properties on a model to a BuiltList. This happens in post processing rather + //than type mapping as we only want this to apply to models, not every other class. + if ("Map".equals(property.baseType)) { + property.setDatatype(property.dataType.replaceAll(property.baseType, "BuiltMap")); + property.setBaseType("BuiltMap"); + model.imports.add("BuiltMap"); + } + } + + } + + @Override + public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) { + objs = super.postProcessOperationsWithModels(objs, allModels); + Map<String, Object> operations = (Map<String, Object>) objs.get("operations"); + List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation"); + + Set<String> modelImports = new HashSet<>(); + Set<String> fullImports = new HashSet<>(); + + for (CodegenOperation op : operationList) { + op.httpMethod = op.httpMethod.toLowerCase(Locale.ROOT); + boolean isJson = true; //default to JSON + boolean isForm = false; + boolean isMultipart = false; + if (op.consumes != null) { + for (Map<String, String> consume : op.consumes) { + if (consume.containsKey("mediaType")) { + String type = consume.get("mediaType"); + isJson = type.equalsIgnoreCase("application/json"); + isForm = type.equalsIgnoreCase("application/x-www-form-urlencoded"); + isMultipart = type.equalsIgnoreCase("multipart/form-data"); + break; + } + } + } + + for (CodegenParameter param : op.bodyParams) { + if (param.baseType != null && param.baseType.equalsIgnoreCase("Uint8List") && isMultipart) { + param.baseType = "MultipartFile"; + param.dataType = "MultipartFile"; + } + } + + op.vendorExtensions.put("isJson", isJson); + op.vendorExtensions.put("isForm", isForm); + op.vendorExtensions.put("isMultipart", isMultipart); + + Set<String> imports = new HashSet<>(); + for (String item : op.imports) { + if (!modelToIgnore.contains(item.toLowerCase(Locale.ROOT))) { + imports.add(underscore(item)); + } else if (item.equalsIgnoreCase("Uint8List")) { + fullImports.add("dart:typed_data"); + } + } + modelImports.addAll(imports); + op.imports = imports; + } + + objs.put("modelImports", modelImports); + objs.put("fullImports", fullImports); + + return objs; + } +} diff --git a/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig b/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig index 67c0f473b506bc5035a33125925c6494961e2991..3313be307ce839fc5f952f6e1adb2c0c3ef6564f 100644 --- a/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig +++ b/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig @@ -20,6 +20,7 @@ org.openapitools.codegen.languages.CSharpNetCoreClientCodegen org.openapitools.codegen.languages.CSharpDotNet2ClientCodegen org.openapitools.codegen.languages.CSharpNancyFXServerCodegen org.openapitools.codegen.languages.DartClientCodegen +org.openapitools.codegen.languages.DartDioClientCodegen org.openapitools.codegen.languages.DartJaguarClientCodegen org.openapitools.codegen.languages.EiffelClientCodegen org.openapitools.codegen.languages.ElixirClientCodegen diff --git a/modules/openapi-generator/src/main/resources/dart-dio/README.mustache b/modules/openapi-generator/src/main/resources/dart-dio/README.mustache new file mode 100644 index 0000000000000000000000000000000000000000..1367a32a5daf7aa3cd16c23bdea86461beeb81e4 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart-dio/README.mustache @@ -0,0 +1,110 @@ +# {{pubName}} +{{#appDescription}} +{{{appDescription}}} +{{/appDescription}} + +This Dart package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: + +- API version: {{appVersion}} +{{#artifactVersion}} +- Package version: {{artifactVersion}} +{{/artifactVersion}} +{{^hideGenerationTimestamp}} +- Build date: {{generatedDate}} +{{/hideGenerationTimestamp}} +- Build package: {{generatorClass}} +{{#infoUrl}} +For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) +{{/infoUrl}} + +## Requirements + +Dart 1.20.0 or later OR Flutter 0.0.20 or later + +## Installation & Usage + +### Github +If this Dart package is published to Github, please include the following in pubspec.yaml +``` +name: {{pubName}} +version: {{pubVersion}} +description: {{pubDescription}} +dependencies: + {{pubName}}: + git: https://github.com/{{gitUserId}}/{{gitRepoId}}.git + version: 'any' +``` + +### Local +To use the package in your local drive, please include the following in pubspec.yaml +``` +dependencies: + {{pubName}}: + path: /path/to/{{pubName}} +``` + +## Getting Started + +Please follow the [installation procedure](#installation--usage) and then run the following: + +```dart +import 'package:{{pubName}}/api.dart'; +{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}} + +var api_instance = new {{classname}}(); +{{#allParams}} +var {{paramName}} = {{#isListContainer}}[{{/isListContainer}}{{#isBodyParam}}new {{dataType}}(){{/isBodyParam}}{{^isBodyParam}}{{{example}}}{{/isBodyParam}}{{#isListContainer}}]{{/isListContainer}}; // {{{dataType}}} | {{{description}}} +{{/allParams}} + +try { + {{#returnType}}var result = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + {{#returnType}} + print(result); + {{/returnType}} +} catch (e) { + print("Exception when calling {{classname}}->{{operationId}}: $e\n"); +} +{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}} +``` + +## Documentation for API Endpoints + +All URIs are relative to *{{basePath}}* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}/{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}} +{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} + +## Documentation For Models + +{{#models}}{{#model}} - [{{{classname}}}]({{modelDocPath}}/{{{classname}}}.md) +{{/model}}{{/models}} + +## Documentation For Authorization + +{{^authMethods}} All endpoints do not require authorization. +{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}} +{{#authMethods}}## {{{name}}} + +{{#isApiKey}}- **Type**: API key +- **API key parameter name**: {{{keyParamName}}} +- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} +{{/isApiKey}} +{{#isBasic}}- **Type**: HTTP basic authentication +{{/isBasic}} +{{#isOAuth}}- **Type**: OAuth +- **Flow**: {{{flow}}} +- **Authorization URL**: {{{authorizationUrl}}} +- **Scopes**: {{^scopes}}N/A{{/scopes}} +{{#scopes}} - **{{{scope}}}**: {{{description}}} +{{/scopes}} +{{/isOAuth}} + +{{/authMethods}} + +## Author + +{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}} +{{/hasMore}}{{/apis}}{{/apiInfo}} + diff --git a/modules/openapi-generator/src/main/resources/dart-dio/analysis_options.mustache b/modules/openapi-generator/src/main/resources/dart-dio/analysis_options.mustache new file mode 100644 index 0000000000000000000000000000000000000000..655cb67bd88809bb78a85952657680a1d763b6a8 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart-dio/analysis_options.mustache @@ -0,0 +1 @@ +analyzer: \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart-dio/api.mustache b/modules/openapi-generator/src/main/resources/dart-dio/api.mustache new file mode 100644 index 0000000000000000000000000000000000000000..b190d66395702ee677f0c3ef1f6e89034fa0efe9 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart-dio/api.mustache @@ -0,0 +1,94 @@ +import 'dart:async'; +import 'dart:io'; +import 'dart:convert'; +import 'package:dio/dio.dart'; +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/serializer.dart'; + +{{#operations}} +{{#modelImports}}import 'package:{{pubName}}/model/{{.}}.dart'; +{{/modelImports}} +{{#fullImports}}import '{{.}}'; +{{/fullImports}} + +class {{classname}} { + final Dio _dio; + Serializers _serializers; + + {{classname}}(this._dio, this._serializers); + + {{#operation}} + /// {{summary}} + /// + /// {{notes}} + Future<Response{{#returnType}}<{{{returnType}}}>{{/returnType}}>{{nickname}}({{#allParams}}{{#required}}{{{dataType}}} {{paramName}},{{/required}}{{/allParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{paramName}},{{/required}}{{/allParams}}CancelToken cancelToken, Map<String, String> headers,}) async { + + String path = "{{{path}}}"{{#pathParams}}.replaceAll("{" + "{{baseName}}" + "}", {{{paramName}}}.toString()){{/pathParams}}; + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers ?? {}); + Map<String, String> formParams = {}; + + {{#headerParams}} + headerParams["{{baseName}}"] = {{paramName}}; + {{/headerParams}} + {{#queryParams}} + queryParams["{{baseName}}"] = {{paramName}}; + {{/queryParams}} + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = [{{#consumes}} + "{{{mediaType}}}"{{#hasMore}},{{/hasMore}}{{/consumes}}]; + + {{#bodyParam}} + {{#isListContainer}} + final type = const FullType(BuiltList, const [const FullType({{baseType}})]); + var serializedBody = _serializers.serialize(BuiltList<{{baseType}}>.from({{paramName}}), specifiedType: type); + {{/isListContainer}} + {{^isListContainer}} + var serializedBody = _serializers.serialize({{paramName}}); + {{/isListContainer}} + var data = json.encode(serializedBody); + {{/bodyParam}} + + return _dio.request( + path, + queryParameters: queryParams, + {{#bodyParam}} + data: data, + {{/bodyParam}} + options: Options( + method: '{{httpMethod}}'.toUpperCase(), + headers: headerParams, + contentType: contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ){{#returnType}}.then((response) { + + {{#isListContainer}} + final FullType type = const FullType(BuiltList, const [const FullType({{returnBaseType}})]); + BuiltList<{{returnBaseType}}> dataList = _serializers.deserialize(response.data, specifiedType: type); + var data = dataList.toList(); + {{/isListContainer}} + {{^isListContainer}} + var serializer = _serializers.serializerForType({{{returnType}}}); + var data = _serializers.deserializeWith<{{{returnType}}}>(serializer, response.data); + {{/isListContainer}} + + return Response<{{{returnType}}}>( + data: data, + headers: response.headers, + request: response.request, + redirects: response.redirects, + statusCode: response.statusCode, + statusMessage: response.statusMessage, + extra: response.extra, + ); + }){{/returnType}}; + } + {{/operation}} + } +{{/operations}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart-dio/api_doc.mustache b/modules/openapi-generator/src/main/resources/dart-dio/api_doc.mustache new file mode 100644 index 0000000000000000000000000000000000000000..773ee0d562e1eb507f44a30c3ed932f2f6ae0fb3 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart-dio/api_doc.mustache @@ -0,0 +1,86 @@ +# {{pubName}}.api.{{classname}}{{#description}} +{{description}}{{/description}} + +## Load the API package +```dart +import 'package:{{pubName}}/api.dart'; +``` + +All URIs are relative to *{{basePath}}* + +Method | HTTP request | Description +------------- | ------------- | ------------- +{{#operations}}{{#operation}}[**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}} +{{/operation}}{{/operations}} + +{{#operations}} +{{#operation}} +# **{{{operationId}}}** +> {{#returnType}}{{{returnType}}} {{/returnType}}{{{operationId}}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + +{{{summary}}}{{#notes}} + +{{{notes}}}{{/notes}} + +### Example +```dart +import 'package:{{pubName}}/api.dart'; +{{#hasAuthMethods}} +{{#authMethods}} +{{#isBasic}} +// TODO Configure HTTP basic authorization: {{{name}}} +//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').username = 'YOUR_USERNAME' +//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').password = 'YOUR_PASSWORD'; +{{/isBasic}} +{{#isApiKey}} +// TODO Configure API key authorization: {{{name}}} +//defaultApiClient.getAuthentication<ApiKeyAuth>('{{{name}}}').apiKey = 'YOUR_API_KEY'; +// uncomment below to setup prefix (e.g. Bearer) for API key, if needed +//defaultApiClient.getAuthentication<ApiKeyAuth>('{{{name}}}').apiKeyPrefix = 'Bearer'; +{{/isApiKey}} +{{#isOAuth}} +// TODO Configure OAuth2 access token for authorization: {{{name}}} +//defaultApiClient.getAuthentication<OAuth>('{{{name}}}').accessToken = 'YOUR_ACCESS_TOKEN'; +{{/isOAuth}} +{{/authMethods}} +{{/hasAuthMethods}} + +var api_instance = new {{classname}}(); +{{#allParams}} +var {{paramName}} = {{#isListContainer}}[{{/isListContainer}}{{#isBodyParam}}new {{dataType}}(){{/isBodyParam}}{{^isBodyParam}}{{{example}}}{{/isBodyParam}}{{#isListContainer}}]{{/isListContainer}}; // {{{dataType}}} | {{{description}}} +{{/allParams}} + +try { + {{#returnType}}var result = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + {{#returnType}} + print(result); + {{/returnType}} +} catch (e) { + print("Exception when calling {{classname}}->{{operationId}}: $e\n"); +} +``` + +### Parameters +{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}} +Name | Type | Description | Notes +------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}} +{{#allParams}} **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{baseType}}.md){{/isPrimitiveType}}| {{description}} | {{^required}}[optional] {{/required}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} +{{/allParams}} + +### Return type + +{{#returnType}}{{#returnTypeIsPrimitive}}**{{{returnType}}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{{returnType}}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void (empty response body){{/returnType}} + +### Authorization + +{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{{name}}}](../README.md#{{{name}}}){{^-last}}, {{/-last}}{{/authMethods}} + +### HTTP request headers + + - **Content-Type**: {{#consumes}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}} + - **Accept**: {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}{{^produces}}Not defined{{/produces}} + +[[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) + +{{/operation}} +{{/operations}} diff --git a/modules/openapi-generator/src/main/resources/dart-dio/apilib.mustache b/modules/openapi-generator/src/main/resources/dart-dio/apilib.mustache new file mode 100644 index 0000000000000000000000000000000000000000..11690b8c28baaed89b303e97fa6c64cbda1438e8 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart-dio/apilib.mustache @@ -0,0 +1,39 @@ +library {{pubName}}.api; + +import 'package:http/io_client.dart'; +import 'package:dio/dio.dart'; +import 'package:built_value/serializer.dart'; +import 'package:{{pubName}}/serializers.dart'; +{{#apiInfo}}{{#apis}}import 'package:{{pubName}}/api/{{classFilename}}.dart'; +{{/apis}}{{/apiInfo}} + +class {{clientName}} { + + Dio dio; + Serializers serializers; + String basePath = "http://petstore.swagger.io/v2"; + + {{clientName}}({this.dio, Serializers serializers}) { + if (dio == null) { + BaseOptions options = new BaseOptions( + baseUrl: basePath, + connectTimeout: 5000, + receiveTimeout: 3000, + ); + this.dio = new Dio(options); + } + + this.serializers = serializers ?? standardSerializers; +} + +{{#apiInfo}}{{#apis}} + /** + * Get {{classname}} instance, base route and serializer can be overridden by a given but be careful, + * by doing that all interceptors will not be executed + */ + {{classname}} get{{classname}}() { + return {{classname}}(dio, serializers); + } + +{{/apis}}{{/apiInfo}} +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart-dio/class.mustache b/modules/openapi-generator/src/main/resources/dart-dio/class.mustache new file mode 100644 index 0000000000000000000000000000000000000000..41743a4235cb6bfedd104acfb48e60516bb34f09 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart-dio/class.mustache @@ -0,0 +1,28 @@ +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; + +part '{{classFilename}}.g.dart'; + +abstract class {{classname}} implements Built<{{classname}}, {{classname}}Builder> { + +{{#vars}} + {{#description}}/* {{{description}}} */{{/description}} + {{#isNullable}} + @nullable + {{/isNullable}} + + {{#description}}/* {{{description}}} */{{/description}} + @BuiltValueField(wireName: '{{baseName}}') + {{{dataType}}} get {{name}}; + {{#allowableValues}} + {{#min}} // range from {{min}} to {{max}}{{/min}}//{{^min}}enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };{{/min}}{ + {{/allowableValues}} +{{/vars}} + + // Boilerplate code needed to wire-up generated code + {{classname}}._(); + + factory {{classname}}([updates({{classname}}Builder b)]) = _${{classname}}; + static Serializer<{{classname}}> get serializer => _${{classVarName}}Serializer; + +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart-dio/enum.mustache b/modules/openapi-generator/src/main/resources/dart-dio/enum.mustache new file mode 100644 index 0000000000000000000000000000000000000000..d4a4d2b8d111c11a62ef2bf8fa96386feda7f644 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart-dio/enum.mustache @@ -0,0 +1,36 @@ +@Entity() +class {{classname}} { + /// The underlying value of this enum member. + final {{dataType}} value; + + const {{classname}}._internal(this.value); + + {{#allowableValues}} + {{#enumVars}} + {{#description}} + /// {{description}} + {{/description}} + static const {{classname}} {{{name}}} = const {{classname}}._internal({{{value}}}); + {{/enumVars}} + {{/allowableValues}} +} + +class {{classname}}TypeTransformer extends TypeTransformer<{{classname}}> { + + @override + dynamic encode({{classname}} data) { + return data.value; + } + + @override + {{classname}} decode(dynamic data) { + switch (data) { + {{#allowableValues}} + {{#enumVars}} + case {{{value}}}: return {{classname}}.{{{name}}}; + {{/enumVars}} + {{/allowableValues}} + default: throw('Unknown enum value to decode: $data'); + } + } +} diff --git a/modules/openapi-generator/src/main/resources/dart-dio/gitignore.mustache b/modules/openapi-generator/src/main/resources/dart-dio/gitignore.mustache new file mode 100644 index 0000000000000000000000000000000000000000..7c280441649860d99e9df07c398b32012ea8fffd --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart-dio/gitignore.mustache @@ -0,0 +1,27 @@ +# See https://www.dartlang.org/tools/private-files.html + +# Files and directories created by pub +.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 diff --git a/modules/openapi-generator/src/main/resources/dart-dio/model.mustache b/modules/openapi-generator/src/main/resources/dart-dio/model.mustache new file mode 100644 index 0000000000000000000000000000000000000000..da50fb56612593f13439675020cbb69869004a27 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart-dio/model.mustache @@ -0,0 +1,8 @@ +{{#models}} + {{#model}} + {{#imports}} + import 'package:{{.}}.dart'; + {{/imports}} + {{#isEnum}}{{>enum}}{{/isEnum}}{{^isEnum}}{{>class}}{{/isEnum}} + {{/model}} +{{/models}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart-dio/object_doc.mustache b/modules/openapi-generator/src/main/resources/dart-dio/object_doc.mustache new file mode 100644 index 0000000000000000000000000000000000000000..657f84d8905e450e04200259cf3ddad67e4b62ee --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart-dio/object_doc.mustache @@ -0,0 +1,16 @@ +{{#models}}{{#model}}# {{pubName}}.model.{{classname}} + +## Load the model package +```dart +import 'package:{{pubName}}/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} +{{/vars}} + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + +{{/model}}{{/models}} diff --git a/modules/openapi-generator/src/main/resources/dart-dio/pubspec.mustache b/modules/openapi-generator/src/main/resources/dart-dio/pubspec.mustache new file mode 100644 index 0000000000000000000000000000000000000000..d69417f7cbdb244b5dafe9d50483594d4a5e70a3 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart-dio/pubspec.mustache @@ -0,0 +1,13 @@ +name: {{pubName}} +version: {{pubVersion}} +description: {{pubDescription}} +environment: + sdk: ">=2.3.0 <3.0.0" +dependencies: + dio: ^3.0.3 + built_value: 6.7.0 + built_collection: 4.2.2 +dev_dependencies: + built_value_generator: ^6.7.1 + build_runner: ^1.7.1 + test: 1.6.5 \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart-dio/serializers.mustache b/modules/openapi-generator/src/main/resources/dart-dio/serializers.mustache new file mode 100644 index 0000000000000000000000000000000000000000..141eaa307e4ccfe0535cf3073f4838f1b0186493 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart-dio/serializers.mustache @@ -0,0 +1,26 @@ +library serializers; + +import 'package:built_value/serializer.dart'; +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/standard_json_plugin.dart'; + +{{#models}}{{#model}}import 'package:{{pubName}}/model/{{classFilename}}.dart'; +{{/model}}{{/models}} + +part 'serializers.g.dart'; + +@SerializersFor(const [ +{{#models}}{{#model}}{{classname}}, +{{/model}}{{/models}} +]) + +//allow all models to be serialized within a list +Serializers serializers = (_$serializers.toBuilder() +{{#models}}{{#model}}..addBuilderFactory( +const FullType(BuiltList, const [const FullType({{classname}})]), +() => new ListBuilder<{{classname}}>()) +{{/model}}{{/models}} +).build(); + +Serializers standardSerializers = +(serializers.toBuilder()..addPlugin(StandardJsonPlugin())).build(); \ No newline at end of file diff --git a/samples/client/petstore/dart-dio/.gitignore b/samples/client/petstore/dart-dio/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..7c280441649860d99e9df07c398b32012ea8fffd --- /dev/null +++ b/samples/client/petstore/dart-dio/.gitignore @@ -0,0 +1,27 @@ +# See https://www.dartlang.org/tools/private-files.html + +# Files and directories created by pub +.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 diff --git a/samples/client/petstore/dart-dio/.openapi-generator-ignore b/samples/client/petstore/dart-dio/.openapi-generator-ignore new file mode 100644 index 0000000000000000000000000000000000000000..7484ee590a3894506cf063799b885428f95a71be --- /dev/null +++ b/samples/client/petstore/dart-dio/.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/client/petstore/dart-dio/.openapi-generator/VERSION b/samples/client/petstore/dart-dio/.openapi-generator/VERSION new file mode 100644 index 0000000000000000000000000000000000000000..0e97bd19efbf2d199cabc283a2a9a501fbb95333 --- /dev/null +++ b/samples/client/petstore/dart-dio/.openapi-generator/VERSION @@ -0,0 +1 @@ +4.1.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/dart-dio/README.md b/samples/client/petstore/dart-dio/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ded15d6b9238124498f0e719336cab229d75d17f --- /dev/null +++ b/samples/client/petstore/dart-dio/README.md @@ -0,0 +1,116 @@ +# openapi +This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + +This Dart package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: + +- API version: 1.0.0 +- Build date: 2019-10-03T14:20:56.615+13:00[Pacific/Auckland] +- Build package: org.openapitools.codegen.languages.DartDioClientCodegen + +## Requirements + +Dart 1.20.0 or later OR Flutter 0.0.20 or later + +## Installation & Usage + +### Github +If this Dart package is published to Github, please include the following in pubspec.yaml +``` +name: openapi +version: 1.0.0 +description: OpenAPI API client +dependencies: + openapi: + git: https://github.com/GIT_USER_ID/GIT_REPO_ID.git + version: 'any' +``` + +### Local +To use the package in your local drive, please include the following in pubspec.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/api.dart'; + + +var api_instance = new PetApi(); +var body = new Pet(); // Pet | Pet object that needs to be added to the store + +try { + api_instance.addPet(body); +} catch (e) { + print("Exception when calling PetApi->addPet: $e\n"); +} + +``` + +## Documentation for API Endpoints + +All URIs are relative to *http://petstore.swagger.io/v2* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*PetApi* | [**addPet**](docs//PetApi.md#addpet) | **post** /pet | Add a new pet to the store +*PetApi* | [**deletePet**](docs//PetApi.md#deletepet) | **delete** /pet/{petId} | Deletes a pet +*PetApi* | [**findPetsByStatus**](docs//PetApi.md#findpetsbystatus) | **get** /pet/findByStatus | Finds Pets by status +*PetApi* | [**findPetsByTags**](docs//PetApi.md#findpetsbytags) | **get** /pet/findByTags | Finds Pets by tags +*PetApi* | [**getPetById**](docs//PetApi.md#getpetbyid) | **get** /pet/{petId} | Find pet by ID +*PetApi* | [**updatePet**](docs//PetApi.md#updatepet) | **put** /pet | Update an existing pet +*PetApi* | [**updatePetWithForm**](docs//PetApi.md#updatepetwithform) | **post** /pet/{petId} | Updates a pet in the store with form data +*PetApi* | [**uploadFile**](docs//PetApi.md#uploadfile) | **post** /pet/{petId}/uploadImage | uploads an image +*StoreApi* | [**deleteOrder**](docs//StoreApi.md#deleteorder) | **delete** /store/order/{orderId} | Delete purchase order by ID +*StoreApi* | [**getInventory**](docs//StoreApi.md#getinventory) | **get** /store/inventory | Returns pet inventories by status +*StoreApi* | [**getOrderById**](docs//StoreApi.md#getorderbyid) | **get** /store/order/{orderId} | Find purchase order by ID +*StoreApi* | [**placeOrder**](docs//StoreApi.md#placeorder) | **post** /store/order | Place an order for a pet +*UserApi* | [**createUser**](docs//UserApi.md#createuser) | **post** /user | Create user +*UserApi* | [**createUsersWithArrayInput**](docs//UserApi.md#createuserswitharrayinput) | **post** /user/createWithArray | Creates list of users with given input array +*UserApi* | [**createUsersWithListInput**](docs//UserApi.md#createuserswithlistinput) | **post** /user/createWithList | Creates list of users with given input array +*UserApi* | [**deleteUser**](docs//UserApi.md#deleteuser) | **delete** /user/{username} | Delete user +*UserApi* | [**getUserByName**](docs//UserApi.md#getuserbyname) | **get** /user/{username} | Get user by user name +*UserApi* | [**loginUser**](docs//UserApi.md#loginuser) | **get** /user/login | Logs user into the system +*UserApi* | [**logoutUser**](docs//UserApi.md#logoutuser) | **get** /user/logout | Logs out current logged in user session +*UserApi* | [**updateUser**](docs//UserApi.md#updateuser) | **put** /user/{username} | Updated user + + +## Documentation For Models + + - [ApiResponse](docs//ApiResponse.md) + - [Category](docs//Category.md) + - [Order](docs//Order.md) + - [Pet](docs//Pet.md) + - [Tag](docs//Tag.md) + - [User](docs//User.md) + + +## Documentation For Authorization + + +## api_key + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + +## petstore_auth + +- **Type**: OAuth +- **Flow**: implicit +- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog +- **Scopes**: + - **write:pets**: modify pets in your account + - **read:pets**: read your pets + + +## Author + + + + diff --git a/samples/client/petstore/dart-dio/analysis_options.yaml b/samples/client/petstore/dart-dio/analysis_options.yaml new file mode 100644 index 0000000000000000000000000000000000000000..655cb67bd88809bb78a85952657680a1d763b6a8 --- /dev/null +++ b/samples/client/petstore/dart-dio/analysis_options.yaml @@ -0,0 +1 @@ +analyzer: \ No newline at end of file diff --git a/samples/client/petstore/dart-dio/docs/ApiResponse.md b/samples/client/petstore/dart-dio/docs/ApiResponse.md new file mode 100644 index 0000000000000000000000000000000000000000..92422f0f446e19a8ec88c8910053c35be0fd5f04 --- /dev/null +++ b/samples/client/petstore/dart-dio/docs/ApiResponse.md @@ -0,0 +1,17 @@ +# openapi.model.ApiResponse + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**code** | **int** | | [optional] [default to null] +**type** | **String** | | [optional] [default to null] +**message** | **String** | | [optional] [default to null] + +[[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/client/petstore/dart-dio/docs/Category.md b/samples/client/petstore/dart-dio/docs/Category.md new file mode 100644 index 0000000000000000000000000000000000000000..cc0d1633b59ca9d56915a4447f962c03d06a2921 --- /dev/null +++ b/samples/client/petstore/dart-dio/docs/Category.md @@ -0,0 +1,16 @@ +# openapi.model.Category + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | **int** | | [optional] [default to null] +**name** | **String** | | [optional] [default to null] + +[[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/client/petstore/dart-dio/docs/Order.md b/samples/client/petstore/dart-dio/docs/Order.md new file mode 100644 index 0000000000000000000000000000000000000000..310ce6c65be3675e4f4105f35e5ee61d232f901d --- /dev/null +++ b/samples/client/petstore/dart-dio/docs/Order.md @@ -0,0 +1,20 @@ +# openapi.model.Order + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | **int** | | [optional] [default to null] +**petId** | **int** | | [optional] [default to null] +**quantity** | **int** | | [optional] [default to null] +**shipDate** | [**DateTime**](DateTime.md) | | [optional] [default to null] +**status** | **String** | Order Status | [optional] [default to null] +**complete** | **bool** | | [optional] [default to false] + +[[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/client/petstore/dart-dio/docs/Pet.md b/samples/client/petstore/dart-dio/docs/Pet.md new file mode 100644 index 0000000000000000000000000000000000000000..619e45d18483d6e54429ceec18d016cec37b3cef --- /dev/null +++ b/samples/client/petstore/dart-dio/docs/Pet.md @@ -0,0 +1,20 @@ +# openapi.model.Pet + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | **int** | | [optional] [default to null] +**category** | [**Category**](Category.md) | | [optional] [default to null] +**name** | **String** | | [default to null] +**photoUrls** | **BuiltList<String>** | | [default to const []] +**tags** | [**BuiltList<Tag>**](Tag.md) | | [optional] [default to const []] +**status** | **String** | pet status in the store | [optional] [default to null] + +[[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/client/petstore/dart-dio/docs/PetApi.md b/samples/client/petstore/dart-dio/docs/PetApi.md new file mode 100644 index 0000000000000000000000000000000000000000..e781974607c82887c97e1621acc4de2b9b4c2daf --- /dev/null +++ b/samples/client/petstore/dart-dio/docs/PetApi.md @@ -0,0 +1,379 @@ +# openapi.api.PetApi + +## Load the API package +```dart +import 'package:openapi/api.dart'; +``` + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**addPet**](PetApi.md#addPet) | **post** /pet | Add a new pet to the store +[**deletePet**](PetApi.md#deletePet) | **delete** /pet/{petId} | Deletes a pet +[**findPetsByStatus**](PetApi.md#findPetsByStatus) | **get** /pet/findByStatus | Finds Pets by status +[**findPetsByTags**](PetApi.md#findPetsByTags) | **get** /pet/findByTags | Finds Pets by tags +[**getPetById**](PetApi.md#getPetById) | **get** /pet/{petId} | Find pet by ID +[**updatePet**](PetApi.md#updatePet) | **put** /pet | Update an existing pet +[**updatePetWithForm**](PetApi.md#updatePetWithForm) | **post** /pet/{petId} | Updates a pet in the store with form data +[**uploadFile**](PetApi.md#uploadFile) | **post** /pet/{petId}/uploadImage | uploads an image + + +# **addPet** +> addPet(body) + +Add a new pet to the store + +### Example +```dart +import 'package:openapi/api.dart'; +// TODO Configure OAuth2 access token for authorization: petstore_auth +//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; + +var api_instance = new PetApi(); +var body = new Pet(); // Pet | Pet object that needs to be added to the store + +try { + api_instance.addPet(body); +} catch (e) { + print("Exception when calling PetApi->addPet: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**Pet**](Pet.md)| Pet object that needs to be added to the store | + +### Return type + +void (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: application/json, application/xml + - **Accept**: Not defined + +[[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) + +# **deletePet** +> deletePet(petId, apiKey) + +Deletes a pet + +### Example +```dart +import 'package:openapi/api.dart'; +// TODO Configure OAuth2 access token for authorization: petstore_auth +//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; + +var api_instance = new PetApi(); +var petId = 789; // int | Pet id to delete +var apiKey = apiKey_example; // String | + +try { + api_instance.deletePet(petId, apiKey); +} catch (e) { + print("Exception when calling PetApi->deletePet: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **petId** | **int**| Pet id to delete | [default to null] + **apiKey** | **String**| | [optional] [default to null] + +### Return type + +void (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +[[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) + +# **findPetsByStatus** +> List<Pet> findPetsByStatus(status) + +Finds Pets by status + +Multiple status values can be provided with comma separated strings + +### Example +```dart +import 'package:openapi/api.dart'; +// TODO Configure OAuth2 access token for authorization: petstore_auth +//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; + +var api_instance = new PetApi(); +var status = []; // List<String> | Status values that need to be considered for filter + +try { + var result = api_instance.findPetsByStatus(status); + print(result); +} catch (e) { + print("Exception when calling PetApi->findPetsByStatus: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **status** | [**List<String>**](String.md)| Status values that need to be considered for filter | [default to const []] + +### Return type + +[**List<Pet>**](Pet.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/xml, 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) + +# **findPetsByTags** +> List<Pet> findPetsByTags(tags) + +Finds Pets by tags + +Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + +### Example +```dart +import 'package:openapi/api.dart'; +// TODO Configure OAuth2 access token for authorization: petstore_auth +//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; + +var api_instance = new PetApi(); +var tags = []; // List<String> | Tags to filter by + +try { + var result = api_instance.findPetsByTags(tags); + print(result); +} catch (e) { + print("Exception when calling PetApi->findPetsByTags: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **tags** | [**List<String>**](String.md)| Tags to filter by | [default to const []] + +### Return type + +[**List<Pet>**](Pet.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/xml, 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) + +# **getPetById** +> Pet getPetById(petId) + +Find pet by ID + +Returns a single pet + +### Example +```dart +import 'package:openapi/api.dart'; +// TODO Configure API key authorization: api_key +//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKey = 'YOUR_API_KEY'; +// uncomment below to setup prefix (e.g. Bearer) for API key, if needed +//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKeyPrefix = 'Bearer'; + +var api_instance = new PetApi(); +var petId = 789; // int | ID of pet to return + +try { + var result = api_instance.getPetById(petId); + print(result); +} catch (e) { + print("Exception when calling PetApi->getPetById: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **petId** | **int**| ID of pet to return | [default to null] + +### Return type + +[**Pet**](Pet.md) + +### Authorization + +[api_key](../README.md#api_key) + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/xml, 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) + +# **updatePet** +> updatePet(body) + +Update an existing pet + +### Example +```dart +import 'package:openapi/api.dart'; +// TODO Configure OAuth2 access token for authorization: petstore_auth +//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; + +var api_instance = new PetApi(); +var body = new Pet(); // Pet | Pet object that needs to be added to the store + +try { + api_instance.updatePet(body); +} catch (e) { + print("Exception when calling PetApi->updatePet: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**Pet**](Pet.md)| Pet object that needs to be added to the store | + +### Return type + +void (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: application/json, application/xml + - **Accept**: Not defined + +[[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) + +# **updatePetWithForm** +> updatePetWithForm(petId, name, status) + +Updates a pet in the store with form data + +### Example +```dart +import 'package:openapi/api.dart'; +// TODO Configure OAuth2 access token for authorization: petstore_auth +//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; + +var api_instance = new PetApi(); +var petId = 789; // int | ID of pet that needs to be updated +var name = name_example; // String | Updated name of the pet +var status = status_example; // String | Updated status of the pet + +try { + api_instance.updatePetWithForm(petId, name, status); +} catch (e) { + print("Exception when calling PetApi->updatePetWithForm: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **petId** | **int**| ID of pet that needs to be updated | [default to null] + **name** | **String**| Updated name of the pet | [optional] [default to null] + **status** | **String**| Updated status of the pet | [optional] [default to null] + +### Return type + +void (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: application/x-www-form-urlencoded + - **Accept**: Not defined + +[[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) + +# **uploadFile** +> ApiResponse uploadFile(petId, additionalMetadata, file) + +uploads an image + +### Example +```dart +import 'package:openapi/api.dart'; +// TODO Configure OAuth2 access token for authorization: petstore_auth +//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; + +var api_instance = new PetApi(); +var petId = 789; // int | ID of pet to update +var additionalMetadata = additionalMetadata_example; // String | Additional data to pass to server +var file = BINARY_DATA_HERE; // Uint8List | file to upload + +try { + var result = api_instance.uploadFile(petId, additionalMetadata, file); + print(result); +} catch (e) { + print("Exception when calling PetApi->uploadFile: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **petId** | **int**| ID of pet to update | [default to null] + **additionalMetadata** | **String**| Additional data to pass to server | [optional] [default to null] + **file** | **Uint8List**| file to upload | [optional] [default to null] + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **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/client/petstore/dart-dio/docs/StoreApi.md b/samples/client/petstore/dart-dio/docs/StoreApi.md new file mode 100644 index 0000000000000000000000000000000000000000..33896baac9bf84efa58222313d9c631a715e53c6 --- /dev/null +++ b/samples/client/petstore/dart-dio/docs/StoreApi.md @@ -0,0 +1,186 @@ +# openapi.api.StoreApi + +## Load the API package +```dart +import 'package:openapi/api.dart'; +``` + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**deleteOrder**](StoreApi.md#deleteOrder) | **delete** /store/order/{orderId} | Delete purchase order by ID +[**getInventory**](StoreApi.md#getInventory) | **get** /store/inventory | Returns pet inventories by status +[**getOrderById**](StoreApi.md#getOrderById) | **get** /store/order/{orderId} | Find purchase order by ID +[**placeOrder**](StoreApi.md#placeOrder) | **post** /store/order | Place an order for a pet + + +# **deleteOrder** +> deleteOrder(orderId) + +Delete purchase order by ID + +For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + +### Example +```dart +import 'package:openapi/api.dart'; + +var api_instance = new StoreApi(); +var orderId = orderId_example; // String | ID of the order that needs to be deleted + +try { + api_instance.deleteOrder(orderId); +} catch (e) { + print("Exception when calling StoreApi->deleteOrder: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **orderId** | **String**| ID of the order that needs to be deleted | [default to null] + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +[[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) + +# **getInventory** +> Map<String, int> getInventory() + +Returns pet inventories by status + +Returns a map of status codes to quantities + +### Example +```dart +import 'package:openapi/api.dart'; +// TODO Configure API key authorization: api_key +//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKey = 'YOUR_API_KEY'; +// uncomment below to setup prefix (e.g. Bearer) for API key, if needed +//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKeyPrefix = 'Bearer'; + +var api_instance = new StoreApi(); + +try { + var result = api_instance.getInventory(); + print(result); +} catch (e) { + print("Exception when calling StoreApi->getInventory: $e\n"); +} +``` + +### Parameters +This endpoint does not need any parameter. + +### Return type + +**Map<String, int>** + +### Authorization + +[api_key](../README.md#api_key) + +### 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) + +# **getOrderById** +> Order getOrderById(orderId) + +Find purchase order by ID + +For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + +### Example +```dart +import 'package:openapi/api.dart'; + +var api_instance = new StoreApi(); +var orderId = 789; // int | ID of pet that needs to be fetched + +try { + var result = api_instance.getOrderById(orderId); + print(result); +} catch (e) { + print("Exception when calling StoreApi->getOrderById: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **orderId** | **int**| ID of pet that needs to be fetched | [default to null] + +### Return type + +[**Order**](Order.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/xml, 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) + +# **placeOrder** +> Order placeOrder(body) + +Place an order for a pet + +### Example +```dart +import 'package:openapi/api.dart'; + +var api_instance = new StoreApi(); +var body = new Order(); // Order | order placed for purchasing the pet + +try { + var result = api_instance.placeOrder(body); + print(result); +} catch (e) { + print("Exception when calling StoreApi->placeOrder: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**Order**](Order.md)| order placed for purchasing the pet | + +### Return type + +[**Order**](Order.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/xml, 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/client/petstore/dart-dio/docs/Tag.md b/samples/client/petstore/dart-dio/docs/Tag.md new file mode 100644 index 0000000000000000000000000000000000000000..ded7b32ac3d7f5eb8b9f2bd6ff2e829d16f0ca47 --- /dev/null +++ b/samples/client/petstore/dart-dio/docs/Tag.md @@ -0,0 +1,16 @@ +# openapi.model.Tag + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | **int** | | [optional] [default to null] +**name** | **String** | | [optional] [default to null] + +[[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/client/petstore/dart-dio/docs/User.md b/samples/client/petstore/dart-dio/docs/User.md new file mode 100644 index 0000000000000000000000000000000000000000..3761b70cf0b76d9bb1f0025f980d75bbe98acfb5 --- /dev/null +++ b/samples/client/petstore/dart-dio/docs/User.md @@ -0,0 +1,22 @@ +# openapi.model.User + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | **int** | | [optional] [default to null] +**username** | **String** | | [optional] [default to null] +**firstName** | **String** | | [optional] [default to null] +**lastName** | **String** | | [optional] [default to null] +**email** | **String** | | [optional] [default to null] +**password** | **String** | | [optional] [default to null] +**phone** | **String** | | [optional] [default to null] +**userStatus** | **int** | User Status | [optional] [default to null] + +[[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/client/petstore/dart-dio/docs/UserApi.md b/samples/client/petstore/dart-dio/docs/UserApi.md new file mode 100644 index 0000000000000000000000000000000000000000..052dc20aef769e391d0ae3b338e4f6179eec0f6b --- /dev/null +++ b/samples/client/petstore/dart-dio/docs/UserApi.md @@ -0,0 +1,349 @@ +# openapi.api.UserApi + +## Load the API package +```dart +import 'package:openapi/api.dart'; +``` + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**createUser**](UserApi.md#createUser) | **post** /user | Create user +[**createUsersWithArrayInput**](UserApi.md#createUsersWithArrayInput) | **post** /user/createWithArray | Creates list of users with given input array +[**createUsersWithListInput**](UserApi.md#createUsersWithListInput) | **post** /user/createWithList | Creates list of users with given input array +[**deleteUser**](UserApi.md#deleteUser) | **delete** /user/{username} | Delete user +[**getUserByName**](UserApi.md#getUserByName) | **get** /user/{username} | Get user by user name +[**loginUser**](UserApi.md#loginUser) | **get** /user/login | Logs user into the system +[**logoutUser**](UserApi.md#logoutUser) | **get** /user/logout | Logs out current logged in user session +[**updateUser**](UserApi.md#updateUser) | **put** /user/{username} | Updated user + + +# **createUser** +> createUser(body) + +Create user + +This can only be done by the logged in user. + +### Example +```dart +import 'package:openapi/api.dart'; + +var api_instance = new UserApi(); +var body = new User(); // User | Created user object + +try { + api_instance.createUser(body); +} catch (e) { + print("Exception when calling UserApi->createUser: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**User**](User.md)| Created user object | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +[[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) + +# **createUsersWithArrayInput** +> createUsersWithArrayInput(body) + +Creates list of users with given input array + +### Example +```dart +import 'package:openapi/api.dart'; + +var api_instance = new UserApi(); +var body = [new List<User>()]; // List<User> | List of user object + +try { + api_instance.createUsersWithArrayInput(body); +} catch (e) { + print("Exception when calling UserApi->createUsersWithArrayInput: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**List<User>**](User.md)| List of user object | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +[[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) + +# **createUsersWithListInput** +> createUsersWithListInput(body) + +Creates list of users with given input array + +### Example +```dart +import 'package:openapi/api.dart'; + +var api_instance = new UserApi(); +var body = [new List<User>()]; // List<User> | List of user object + +try { + api_instance.createUsersWithListInput(body); +} catch (e) { + print("Exception when calling UserApi->createUsersWithListInput: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**List<User>**](User.md)| List of user object | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +[[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) + +# **deleteUser** +> deleteUser(username) + +Delete user + +This can only be done by the logged in user. + +### Example +```dart +import 'package:openapi/api.dart'; + +var api_instance = new UserApi(); +var username = username_example; // String | The name that needs to be deleted + +try { + api_instance.deleteUser(username); +} catch (e) { + print("Exception when calling UserApi->deleteUser: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **username** | **String**| The name that needs to be deleted | [default to null] + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +[[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) + +# **getUserByName** +> User getUserByName(username) + +Get user by user name + +### Example +```dart +import 'package:openapi/api.dart'; + +var api_instance = new UserApi(); +var username = username_example; // String | The name that needs to be fetched. Use user1 for testing. + +try { + var result = api_instance.getUserByName(username); + print(result); +} catch (e) { + print("Exception when calling UserApi->getUserByName: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **username** | **String**| The name that needs to be fetched. Use user1 for testing. | [default to null] + +### Return type + +[**User**](User.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/xml, 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) + +# **loginUser** +> String loginUser(username, password) + +Logs user into the system + +### Example +```dart +import 'package:openapi/api.dart'; + +var api_instance = new UserApi(); +var username = username_example; // String | The user name for login +var password = password_example; // String | The password for login in clear text + +try { + var result = api_instance.loginUser(username, password); + print(result); +} catch (e) { + print("Exception when calling UserApi->loginUser: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **username** | **String**| The user name for login | [default to null] + **password** | **String**| The password for login in clear text | [default to null] + +### Return type + +**String** + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/xml, 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) + +# **logoutUser** +> logoutUser() + +Logs out current logged in user session + +### Example +```dart +import 'package:openapi/api.dart'; + +var api_instance = new UserApi(); + +try { + api_instance.logoutUser(); +} catch (e) { + print("Exception when calling UserApi->logoutUser: $e\n"); +} +``` + +### Parameters +This endpoint does not need any parameter. + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +[[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) + +# **updateUser** +> updateUser(username, body) + +Updated user + +This can only be done by the logged in user. + +### Example +```dart +import 'package:openapi/api.dart'; + +var api_instance = new UserApi(); +var username = username_example; // String | name that need to be deleted +var body = new User(); // User | Updated user object + +try { + api_instance.updateUser(username, body); +} catch (e) { + print("Exception when calling UserApi->updateUser: $e\n"); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **username** | **String**| name that need to be deleted | [default to null] + **body** | [**User**](User.md)| Updated user object | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +[[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/client/petstore/dart-dio/lib/api.dart b/samples/client/petstore/dart-dio/lib/api.dart new file mode 100644 index 0000000000000000000000000000000000000000..b2575064fbf37575dea33bcb3cabbf6eaf3765ce --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/api.dart @@ -0,0 +1,52 @@ +library openapi.api; + +import 'package:http/io_client.dart'; +import 'package:dio/dio.dart'; +import 'package:built_value/serializer.dart'; +import 'package:openapi/serializers.dart'; +import 'package:openapi/api/pet_api.dart'; +import 'package:openapi/api/store_api.dart'; +import 'package:openapi/api/user_api.dart'; + +class Openapi { + Dio dio; + Serializers serializers; + String basePath = "http://petstore.swagger.io/v2"; + + Openapi({this.dio, Serializers serializers}) { + if (dio == null) { + BaseOptions options = new BaseOptions( + baseUrl: basePath, + connectTimeout: 5000, + receiveTimeout: 3000, + ); + this.dio = new Dio(options); + } + + this.serializers = serializers ?? standardSerializers; + } + + /** + * Get PetApi instance, base route and serializer can be overridden by a given but be careful, + * by doing that all interceptors will not be executed + */ + PetApi getPetApi() { + return PetApi(dio, serializers); + } + + /** + * Get StoreApi instance, base route and serializer can be overridden by a given but be careful, + * by doing that all interceptors will not be executed + */ + StoreApi getStoreApi() { + return StoreApi(dio, serializers); + } + + /** + * Get UserApi instance, base route and serializer can be overridden by a given but be careful, + * by doing that all interceptors will not be executed + */ + UserApi getUserApi() { + return UserApi(dio, serializers); + } +} diff --git a/samples/client/petstore/dart-dio/lib/api/pet_api.dart b/samples/client/petstore/dart-dio/lib/api/pet_api.dart new file mode 100644 index 0000000000000000000000000000000000000000..fee534d8540c3c38ab50be9a0634d918e00df967 --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/api/pet_api.dart @@ -0,0 +1,376 @@ +import 'dart:async'; +import 'dart:io'; +import 'dart:convert'; +import 'package:dio/dio.dart'; +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/serializer.dart'; + +import 'package:openapi/model/pet.dart'; +import 'package:openapi/model/api_response.dart'; +import 'dart:typed_data'; + +class PetApi { + final Dio _dio; + Serializers _serializers; + + PetApi(this._dio, this._serializers); + + /// Add a new pet to the store + /// + /// + Future<Response> addPet( + Pet body, { + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = "/pet"; + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = ["application/json", "application/xml"]; + + var serializedBody = _serializers.serialize(body); + var data = json.encode(serializedBody); + + return _dio.request( + path, + queryParameters: queryParams, + data: data, + options: Options( + method: 'post'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ); + } + + /// Deletes a pet + /// + /// + Future<Response> deletePet( + int petId, { + String apiKey, + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = + "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString()); + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + headerParams["api_key"] = apiKey; + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + return _dio.request( + path, + queryParameters: queryParams, + options: Options( + method: 'delete'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ); + } + + /// Finds Pets by status + /// + /// Multiple status values can be provided with comma separated strings + Future<Response<List<Pet>>> findPetsByStatus( + List<String> status, { + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = "/pet/findByStatus"; + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams["status"] = status; + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + return _dio + .request( + path, + queryParameters: queryParams, + options: Options( + method: 'get'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ) + .then((response) { + final FullType type = + const FullType(BuiltList, const [const FullType(Pet)]); + BuiltList<Pet> dataList = + _serializers.deserialize(response.data, specifiedType: type); + var data = dataList.toList(); + + return Response<List<Pet>>( + data: data, + headers: response.headers, + request: response.request, + redirects: response.redirects, + statusCode: response.statusCode, + statusMessage: response.statusMessage, + extra: response.extra, + ); + }); + } + + /// Finds Pets by tags + /// + /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + Future<Response<List<Pet>>> findPetsByTags( + List<String> tags, { + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = "/pet/findByTags"; + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams["tags"] = tags; + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + return _dio + .request( + path, + queryParameters: queryParams, + options: Options( + method: 'get'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ) + .then((response) { + final FullType type = + const FullType(BuiltList, const [const FullType(Pet)]); + BuiltList<Pet> dataList = + _serializers.deserialize(response.data, specifiedType: type); + var data = dataList.toList(); + + return Response<List<Pet>>( + data: data, + headers: response.headers, + request: response.request, + redirects: response.redirects, + statusCode: response.statusCode, + statusMessage: response.statusMessage, + extra: response.extra, + ); + }); + } + + /// Find pet by ID + /// + /// Returns a single pet + Future<Response<Pet>> getPetById( + int petId, { + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = + "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString()); + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + return _dio + .request( + path, + queryParameters: queryParams, + options: Options( + method: 'get'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ) + .then((response) { + var serializer = _serializers.serializerForType(Pet); + var data = _serializers.deserializeWith<Pet>(serializer, response.data); + + return Response<Pet>( + data: data, + headers: response.headers, + request: response.request, + redirects: response.redirects, + statusCode: response.statusCode, + statusMessage: response.statusMessage, + extra: response.extra, + ); + }); + } + + /// Update an existing pet + /// + /// + Future<Response> updatePet( + Pet body, { + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = "/pet"; + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = ["application/json", "application/xml"]; + + var serializedBody = _serializers.serialize(body); + var data = json.encode(serializedBody); + + return _dio.request( + path, + queryParameters: queryParams, + data: data, + options: Options( + method: 'put'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ); + } + + /// Updates a pet in the store with form data + /// + /// + Future<Response> updatePetWithForm( + int petId, { + String name, + String status, + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = + "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString()); + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = ["application/x-www-form-urlencoded"]; + + return _dio.request( + path, + queryParameters: queryParams, + options: Options( + method: 'post'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ); + } + + /// uploads an image + /// + /// + Future<Response<ApiResponse>> uploadFile( + int petId, { + String additionalMetadata, + Uint8List file, + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = "/pet/{petId}/uploadImage" + .replaceAll("{" + "petId" + "}", petId.toString()); + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = ["multipart/form-data"]; + + return _dio + .request( + path, + queryParameters: queryParams, + options: Options( + method: 'post'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ) + .then((response) { + var serializer = _serializers.serializerForType(ApiResponse); + var data = + _serializers.deserializeWith<ApiResponse>(serializer, response.data); + + return Response<ApiResponse>( + data: data, + headers: response.headers, + request: response.request, + redirects: response.redirects, + statusCode: response.statusCode, + statusMessage: response.statusMessage, + extra: response.extra, + ); + }); + } +} diff --git a/samples/client/petstore/dart-dio/lib/api/store_api.dart b/samples/client/petstore/dart-dio/lib/api/store_api.dart new file mode 100644 index 0000000000000000000000000000000000000000..440dcd604b8a2ac86c1e738fc7c6790b34f8bcae --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/api/store_api.dart @@ -0,0 +1,180 @@ +import 'dart:async'; +import 'dart:io'; +import 'dart:convert'; +import 'package:dio/dio.dart'; +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/serializer.dart'; + +import 'package:openapi/model/order.dart'; + +class StoreApi { + final Dio _dio; + Serializers _serializers; + + StoreApi(this._dio, this._serializers); + + /// Delete purchase order by ID + /// + /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + Future<Response> deleteOrder(String orderId, { CancelToken cancelToken, Map<String, String> headers,}) async { + String path = "/store/order/{orderId}".replaceAll("{" + "orderId" + "}", orderId.toString()); + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + + return _dio.request( + path, + queryParameters: queryParams, + options: Options( + method: 'delete'.toUpperCase(), + headers: headerParams, + contentType: contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ); + } + /// Returns pet inventories by status + /// + /// Returns a map of status codes to quantities + Future<Response<Map<String, int>>>getInventory({ CancelToken cancelToken, Map<String, String> headers,}) async { + + String path = "/store/inventory"; + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + + return _dio.request( + path, + queryParameters: queryParams, + options: Options( + method: 'get'.toUpperCase(), + headers: headerParams, + contentType: contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ).then((response) { + + var serializer = _serializers.serializerForType(Map<String, int>); + var data = _serializers.deserializeWith<Map<String, int>>(serializer, response.data); + + return Response<Map<String, int>>( + data: data, + headers: response.headers, + request: response.request, + redirects: response.redirects, + statusCode: response.statusCode, + statusMessage: response.statusMessage, + extra: response.extra, + ); + }); + } + /// Find purchase order by ID + /// + /// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + Future<Response<Order>>getOrderById(int orderId,{ CancelToken cancelToken, Map<String, String> headers,}) async { + + String path = "/store/order/{orderId}".replaceAll("{" + "orderId" + "}", orderId.toString()); + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + + return _dio.request( + path, + queryParameters: queryParams, + options: Options( + method: 'get'.toUpperCase(), + headers: headerParams, + contentType: contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ).then((response) { + + var serializer = _serializers.serializerForType(Order); + var data = _serializers.deserializeWith<Order>(serializer, response.data); + + return Response<Order>( + data: data, + headers: response.headers, + request: response.request, + redirects: response.redirects, + statusCode: response.statusCode, + statusMessage: response.statusMessage, + extra: response.extra, + ); + }); + } + /// Place an order for a pet + /// + /// + Future<Response<Order>>placeOrder(Order body,{ CancelToken cancelToken, Map<String, String> headers,}) async { + + String path = "/store/order"; + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + var serializedBody = _serializers.serialize(body); + var data = json.encode(serializedBody); + + return _dio.request( + path, + queryParameters: queryParams, + data: data, + options: Options( + method: 'post'.toUpperCase(), + headers: headerParams, + contentType: contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ).then((response) { + + var serializer = _serializers.serializerForType(Order); + var data = _serializers.deserializeWith<Order>(serializer, response.data); + + return Response<Order>( + data: data, + headers: response.headers, + request: response.request, + redirects: response.redirects, + statusCode: response.statusCode, + statusMessage: response.statusMessage, + extra: response.extra, + ); + }); + } + } diff --git a/samples/client/petstore/dart-dio/lib/api/user_api.dart b/samples/client/petstore/dart-dio/lib/api/user_api.dart new file mode 100644 index 0000000000000000000000000000000000000000..d30d72c380396b876b41f5dd5978b086d75659ae --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/api/user_api.dart @@ -0,0 +1,344 @@ +import 'dart:async'; +import 'dart:io'; +import 'dart:convert'; +import 'package:dio/dio.dart'; +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/serializer.dart'; + +import 'package:openapi/model/user.dart'; + +class UserApi { + final Dio _dio; + Serializers _serializers; + + UserApi(this._dio, this._serializers); + + /// Create user + /// + /// This can only be done by the logged in user. + Future<Response> createUser( + User body, { + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = "/user"; + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + var serializedBody = _serializers.serialize(body); + var data = json.encode(serializedBody); + + return _dio.request( + path, + queryParameters: queryParams, + data: data, + options: Options( + method: 'post'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ); + } + + /// Creates list of users with given input array + /// + /// + Future<Response> createUsersWithArrayInput( + List<User> body, { + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = "/user/createWithArray"; + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + final type = const FullType(BuiltList, const [const FullType(User)]); + var serializedBody = + _serializers.serialize(BuiltList<User>.from(body), specifiedType: type); + var data = json.encode(serializedBody); + + return _dio.request( + path, + queryParameters: queryParams, + data: data, + options: Options( + method: 'post'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ); + } + + /// Creates list of users with given input array + /// + /// + Future<Response> createUsersWithListInput( + List<User> body, { + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = "/user/createWithList"; + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + final type = const FullType(BuiltList, const [const FullType(User)]); + var serializedBody = + _serializers.serialize(BuiltList<User>.from(body), specifiedType: type); + var data = json.encode(serializedBody); + + return _dio.request( + path, + queryParameters: queryParams, + data: data, + options: Options( + method: 'post'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ); + } + + /// Delete user + /// + /// This can only be done by the logged in user. + Future<Response> deleteUser( + String username, { + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = "/user/{username}" + .replaceAll("{" + "username" + "}", username.toString()); + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + return _dio.request( + path, + queryParameters: queryParams, + options: Options( + method: 'delete'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ); + } + + /// Get user by user name + /// + /// + Future<Response<User>> getUserByName( + String username, { + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = "/user/{username}" + .replaceAll("{" + "username" + "}", username.toString()); + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + return _dio + .request( + path, + queryParameters: queryParams, + options: Options( + method: 'get'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ) + .then((response) { + var serializer = _serializers.serializerForType(User); + var data = _serializers.deserializeWith<User>(serializer, response.data); + + return Response<User>( + data: data, + headers: response.headers, + request: response.request, + redirects: response.redirects, + statusCode: response.statusCode, + statusMessage: response.statusMessage, + extra: response.extra, + ); + }); + } + + /// Logs user into the system + /// + /// + Future<Response<String>> loginUser( + String username, + String password, { + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = "/user/login"; + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams["username"] = username; + queryParams["password"] = password; + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + return _dio + .request( + path, + queryParameters: queryParams, + options: Options( + method: 'get'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ) + .then((response) { + var serializer = _serializers.serializerForType(String); + var data = + _serializers.deserializeWith<String>(serializer, response.data); + + return Response<String>( + data: data, + headers: response.headers, + request: response.request, + redirects: response.redirects, + statusCode: response.statusCode, + statusMessage: response.statusMessage, + extra: response.extra, + ); + }); + } + + /// Logs out current logged in user session + /// + /// + Future<Response> logoutUser({ + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = "/user/logout"; + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + return _dio.request( + path, + queryParameters: queryParams, + options: Options( + method: 'get'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ); + } + + /// Updated user + /// + /// This can only be done by the logged in user. + Future<Response> updateUser( + String username, + User body, { + CancelToken cancelToken, + Map<String, String> headers, + }) async { + String path = "/user/{username}" + .replaceAll("{" + "username" + "}", username.toString()); + + // query params + Map<String, dynamic> queryParams = {}; + Map<String, String> headerParams = Map.from(headers); + Map<String, String> formParams = {}; + + queryParams.removeWhere((key, value) => value == null); + headerParams.removeWhere((key, value) => value == null); + formParams.removeWhere((key, value) => value == null); + + List<String> contentTypes = []; + + var serializedBody = _serializers.serialize(body); + var data = json.encode(serializedBody); + + return _dio.request( + path, + queryParameters: queryParams, + data: data, + options: Options( + method: 'put'.toUpperCase(), + headers: headerParams, + contentType: + contentTypes.isNotEmpty ? contentTypes[0] : "application/json", + ), + cancelToken: cancelToken, + ); + } +} diff --git a/samples/client/petstore/dart-dio/lib/model/api_response.dart b/samples/client/petstore/dart-dio/lib/model/api_response.dart new file mode 100644 index 0000000000000000000000000000000000000000..0feebafb0051370d85ff344018a59b5c48e6eac4 --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/model/api_response.dart @@ -0,0 +1,24 @@ +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; + +part 'api_response.g.dart'; + +abstract class ApiResponse implements Built<ApiResponse, ApiResponseBuilder> { + @nullable + @BuiltValueField(wireName: 'code') + int get code; + + @nullable + @BuiltValueField(wireName: 'type') + String get type; + + @nullable + @BuiltValueField(wireName: 'message') + String get message; + + // Boilerplate code needed to wire-up generated code + ApiResponse._(); + + factory ApiResponse([updates(ApiResponseBuilder b)]) = _$ApiResponse; + static Serializer<ApiResponse> get serializer => _$apiResponseSerializer; +} diff --git a/samples/client/petstore/dart-dio/lib/model/api_response.g.dart b/samples/client/petstore/dart-dio/lib/model/api_response.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..ca7c7161ba8ab33039346e782390baac47353c16 --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/model/api_response.g.dart @@ -0,0 +1,167 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'api_response.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +Serializer<ApiResponse> _$apiResponseSerializer = new _$ApiResponseSerializer(); + +class _$ApiResponseSerializer implements StructuredSerializer<ApiResponse> { + @override + final Iterable<Type> types = const [ApiResponse, _$ApiResponse]; + @override + final String wireName = 'ApiResponse'; + + @override + Iterable<Object> serialize(Serializers serializers, ApiResponse object, + {FullType specifiedType = FullType.unspecified}) { + final result = <Object>[ + 'code', + serializers.serialize(object.code, specifiedType: const FullType(int)), + 'type', + serializers.serialize(object.type, specifiedType: const FullType(String)), + 'message', + serializers.serialize(object.message, + specifiedType: const FullType(String)), + ]; + + return result; + } + + @override + ApiResponse deserialize(Serializers serializers, Iterable<Object> serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new ApiResponseBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current as String; + iterator.moveNext(); + final dynamic value = iterator.current; + switch (key) { + case 'code': + result.code = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; + case 'type': + result.type = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + case 'message': + result.message = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + } + } + + return result.build(); + } +} + +class _$ApiResponse extends ApiResponse { + @override + final int code; + @override + final String type; + @override + final String message; + + factory _$ApiResponse([void Function(ApiResponseBuilder) updates]) => + (new ApiResponseBuilder()..update(updates)).build(); + + _$ApiResponse._({this.code, this.type, this.message}) : super._() { + if (code == null) { + throw new BuiltValueNullFieldError('ApiResponse', 'code'); + } + if (type == null) { + throw new BuiltValueNullFieldError('ApiResponse', 'type'); + } + if (message == null) { + throw new BuiltValueNullFieldError('ApiResponse', 'message'); + } + } + + @override + ApiResponse rebuild(void Function(ApiResponseBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + ApiResponseBuilder toBuilder() => new ApiResponseBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is ApiResponse && + code == other.code && + type == other.type && + message == other.message; + } + + @override + int get hashCode { + return $jf( + $jc($jc($jc(0, code.hashCode), type.hashCode), message.hashCode)); + } + + @override + String toString() { + return (newBuiltValueToStringHelper('ApiResponse') + ..add('code', code) + ..add('type', type) + ..add('message', message)) + .toString(); + } +} + +class ApiResponseBuilder implements Builder<ApiResponse, ApiResponseBuilder> { + _$ApiResponse _$v; + + int _code; + int get code => _$this._code; + set code(int code) => _$this._code = code; + + String _type; + String get type => _$this._type; + set type(String type) => _$this._type = type; + + String _message; + String get message => _$this._message; + set message(String message) => _$this._message = message; + + ApiResponseBuilder(); + + ApiResponseBuilder get _$this { + if (_$v != null) { + _code = _$v.code; + _type = _$v.type; + _message = _$v.message; + _$v = null; + } + return this; + } + + @override + void replace(ApiResponse other) { + if (other == null) { + throw new ArgumentError.notNull('other'); + } + _$v = other as _$ApiResponse; + } + + @override + void update(void Function(ApiResponseBuilder) updates) { + if (updates != null) updates(this); + } + + @override + _$ApiResponse build() { + final _$result = + _$v ?? new _$ApiResponse._(code: code, type: type, message: message); + replace(_$result); + return _$result; + } +} + +// ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,lines_longer_than_80_chars,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new diff --git a/samples/client/petstore/dart-dio/lib/model/category.dart b/samples/client/petstore/dart-dio/lib/model/category.dart new file mode 100644 index 0000000000000000000000000000000000000000..5d80fb503667f785c5b3a3ad0ffbf0a05fa4fecf --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/model/category.dart @@ -0,0 +1,20 @@ +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; + +part 'category.g.dart'; + +abstract class Category implements Built<Category, CategoryBuilder> { + @nullable + @BuiltValueField(wireName: 'id') + int get id; + + @nullable + @BuiltValueField(wireName: 'name') + String get name; + + // Boilerplate code needed to wire-up generated code + Category._(); + + factory Category([updates(CategoryBuilder b)]) = _$Category; + static Serializer<Category> get serializer => _$categorySerializer; +} diff --git a/samples/client/petstore/dart-dio/lib/model/category.g.dart b/samples/client/petstore/dart-dio/lib/model/category.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..4e4b83a0060d82bf50450d5b4accf5891273adf5 --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/model/category.g.dart @@ -0,0 +1,144 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'category.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +Serializer<Category> _$categorySerializer = new _$CategorySerializer(); + +class _$CategorySerializer implements StructuredSerializer<Category> { + @override + final Iterable<Type> types = const [Category, _$Category]; + @override + final String wireName = 'Category'; + + @override + Iterable<Object> serialize(Serializers serializers, Category object, + {FullType specifiedType = FullType.unspecified}) { + final result = <Object>[ + 'id', + serializers.serialize(object.id, specifiedType: const FullType(int)), + 'name', + serializers.serialize(object.name, specifiedType: const FullType(String)), + ]; + + return result; + } + + @override + Category deserialize(Serializers serializers, Iterable<Object> serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new CategoryBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current as String; + iterator.moveNext(); + final dynamic value = iterator.current; + switch (key) { + case 'id': + result.id = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; + case 'name': + result.name = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + } + } + + return result.build(); + } +} + +class _$Category extends Category { + @override + final int id; + @override + final String name; + + factory _$Category([void Function(CategoryBuilder) updates]) => + (new CategoryBuilder()..update(updates)).build(); + + _$Category._({this.id, this.name}) : super._() { + if (id == null) { + throw new BuiltValueNullFieldError('Category', 'id'); + } + if (name == null) { + throw new BuiltValueNullFieldError('Category', 'name'); + } + } + + @override + Category rebuild(void Function(CategoryBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + CategoryBuilder toBuilder() => new CategoryBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Category && id == other.id && name == other.name; + } + + @override + int get hashCode { + return $jf($jc($jc(0, id.hashCode), name.hashCode)); + } + + @override + String toString() { + return (newBuiltValueToStringHelper('Category') + ..add('id', id) + ..add('name', name)) + .toString(); + } +} + +class CategoryBuilder implements Builder<Category, CategoryBuilder> { + _$Category _$v; + + int _id; + int get id => _$this._id; + set id(int id) => _$this._id = id; + + String _name; + String get name => _$this._name; + set name(String name) => _$this._name = name; + + CategoryBuilder(); + + CategoryBuilder get _$this { + if (_$v != null) { + _id = _$v.id; + _name = _$v.name; + _$v = null; + } + return this; + } + + @override + void replace(Category other) { + if (other == null) { + throw new ArgumentError.notNull('other'); + } + _$v = other as _$Category; + } + + @override + void update(void Function(CategoryBuilder) updates) { + if (updates != null) updates(this); + } + + @override + _$Category build() { + final _$result = _$v ?? new _$Category._(id: id, name: name); + replace(_$result); + return _$result; + } +} + +// ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,lines_longer_than_80_chars,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new diff --git a/samples/client/petstore/dart-dio/lib/model/order.dart b/samples/client/petstore/dart-dio/lib/model/order.dart new file mode 100644 index 0000000000000000000000000000000000000000..a5bcec14b398067a56724152d17341aa6c1c2254 --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/model/order.dart @@ -0,0 +1,39 @@ +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; + +part 'order.g.dart'; + +abstract class Order implements Built<Order, OrderBuilder> { + @nullable + @BuiltValueField(wireName: 'id') + int get id; + + @nullable + @BuiltValueField(wireName: 'petId') + int get petId; + + @nullable + @BuiltValueField(wireName: 'quantity') + int get quantity; + + @nullable + @BuiltValueField(wireName: 'shipDate') + DateTime get shipDate; + /* Order Status */ + @nullable + + /* Order Status */ + @BuiltValueField(wireName: 'status') + String get status; + //enum statusEnum { placed, approved, delivered, };{ + + @nullable + @BuiltValueField(wireName: 'complete') + bool get complete; + + // Boilerplate code needed to wire-up generated code + Order._(); + + factory Order([updates(OrderBuilder b)]) = _$Order; + static Serializer<Order> get serializer => _$orderSerializer; +} diff --git a/samples/client/petstore/dart-dio/lib/model/order.g.dart b/samples/client/petstore/dart-dio/lib/model/order.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..e4eede934c3020423bc82ec3a288b9b08680d4a1 --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/model/order.g.dart @@ -0,0 +1,243 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'order.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +Serializer<Order> _$orderSerializer = new _$OrderSerializer(); + +class _$OrderSerializer implements StructuredSerializer<Order> { + @override + final Iterable<Type> types = const [Order, _$Order]; + @override + final String wireName = 'Order'; + + @override + Iterable<Object> serialize(Serializers serializers, Order object, + {FullType specifiedType = FullType.unspecified}) { + final result = <Object>[ + 'id', + serializers.serialize(object.id, specifiedType: const FullType(int)), + 'petId', + serializers.serialize(object.petId, specifiedType: const FullType(int)), + 'quantity', + serializers.serialize(object.quantity, + specifiedType: const FullType(int)), + 'shipDate', + serializers.serialize(object.shipDate, + specifiedType: const FullType(DateTime)), + 'status', + serializers.serialize(object.status, + specifiedType: const FullType(String)), + 'complete', + serializers.serialize(object.complete, + specifiedType: const FullType(bool)), + ]; + + return result; + } + + @override + Order deserialize(Serializers serializers, Iterable<Object> serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new OrderBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current as String; + iterator.moveNext(); + final dynamic value = iterator.current; + switch (key) { + case 'id': + result.id = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; + case 'petId': + result.petId = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; + case 'quantity': + result.quantity = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; + case 'shipDate': + result.shipDate = serializers.deserialize(value, + specifiedType: const FullType(DateTime)) as DateTime; + break; + case 'status': + result.status = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + case 'complete': + result.complete = serializers.deserialize(value, + specifiedType: const FullType(bool)) as bool; + break; + } + } + + return result.build(); + } +} + +class _$Order extends Order { + @override + final int id; + @override + final int petId; + @override + final int quantity; + @override + final DateTime shipDate; + @override + final String status; + @override + final bool complete; + + factory _$Order([void Function(OrderBuilder) updates]) => + (new OrderBuilder()..update(updates)).build(); + + _$Order._( + {this.id, + this.petId, + this.quantity, + this.shipDate, + this.status, + this.complete}) + : super._() { + if (id == null) { + throw new BuiltValueNullFieldError('Order', 'id'); + } + if (petId == null) { + throw new BuiltValueNullFieldError('Order', 'petId'); + } + if (quantity == null) { + throw new BuiltValueNullFieldError('Order', 'quantity'); + } + if (shipDate == null) { + throw new BuiltValueNullFieldError('Order', 'shipDate'); + } + if (status == null) { + throw new BuiltValueNullFieldError('Order', 'status'); + } + if (complete == null) { + throw new BuiltValueNullFieldError('Order', 'complete'); + } + } + + @override + Order rebuild(void Function(OrderBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + OrderBuilder toBuilder() => new OrderBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Order && + id == other.id && + petId == other.petId && + quantity == other.quantity && + shipDate == other.shipDate && + status == other.status && + complete == other.complete; + } + + @override + int get hashCode { + return $jf($jc( + $jc( + $jc( + $jc($jc($jc(0, id.hashCode), petId.hashCode), + quantity.hashCode), + shipDate.hashCode), + status.hashCode), + complete.hashCode)); + } + + @override + String toString() { + return (newBuiltValueToStringHelper('Order') + ..add('id', id) + ..add('petId', petId) + ..add('quantity', quantity) + ..add('shipDate', shipDate) + ..add('status', status) + ..add('complete', complete)) + .toString(); + } +} + +class OrderBuilder implements Builder<Order, OrderBuilder> { + _$Order _$v; + + int _id; + int get id => _$this._id; + set id(int id) => _$this._id = id; + + int _petId; + int get petId => _$this._petId; + set petId(int petId) => _$this._petId = petId; + + int _quantity; + int get quantity => _$this._quantity; + set quantity(int quantity) => _$this._quantity = quantity; + + DateTime _shipDate; + DateTime get shipDate => _$this._shipDate; + set shipDate(DateTime shipDate) => _$this._shipDate = shipDate; + + String _status; + String get status => _$this._status; + set status(String status) => _$this._status = status; + + bool _complete; + bool get complete => _$this._complete; + set complete(bool complete) => _$this._complete = complete; + + OrderBuilder(); + + OrderBuilder get _$this { + if (_$v != null) { + _id = _$v.id; + _petId = _$v.petId; + _quantity = _$v.quantity; + _shipDate = _$v.shipDate; + _status = _$v.status; + _complete = _$v.complete; + _$v = null; + } + return this; + } + + @override + void replace(Order other) { + if (other == null) { + throw new ArgumentError.notNull('other'); + } + _$v = other as _$Order; + } + + @override + void update(void Function(OrderBuilder) updates) { + if (updates != null) updates(this); + } + + @override + _$Order build() { + final _$result = _$v ?? + new _$Order._( + id: id, + petId: petId, + quantity: quantity, + shipDate: shipDate, + status: status, + complete: complete); + replace(_$result); + return _$result; + } +} + +// ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,lines_longer_than_80_chars,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new diff --git a/samples/client/petstore/dart-dio/lib/model/pet.dart b/samples/client/petstore/dart-dio/lib/model/pet.dart new file mode 100644 index 0000000000000000000000000000000000000000..c3554e423955fa7fc80652dc65495dfaa88cd907 --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/model/pet.dart @@ -0,0 +1,42 @@ +import 'package:openapi/model/tag.dart'; +import 'package:openapi/model/category.dart'; +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; + +part 'pet.g.dart'; + +abstract class Pet implements Built<Pet, PetBuilder> { + @nullable + @BuiltValueField(wireName: 'id') + int get id; + + @nullable + @BuiltValueField(wireName: 'category') + Category get category; + + @nullable + @BuiltValueField(wireName: 'name') + String get name; + + @nullable + @BuiltValueField(wireName: 'photoUrls') + BuiltList<String> get photoUrls; + + @nullable + @BuiltValueField(wireName: 'tags') + BuiltList<Tag> get tags; + /* pet status in the store */ + @nullable + + /* pet status in the store */ + @BuiltValueField(wireName: 'status') + String get status; + //enum statusEnum { available, pending, sold, };{ + + // Boilerplate code needed to wire-up generated code + Pet._(); + + factory Pet([updates(PetBuilder b)]) = _$Pet; + static Serializer<Pet> get serializer => _$petSerializer; +} diff --git a/samples/client/petstore/dart-dio/lib/model/pet.g.dart b/samples/client/petstore/dart-dio/lib/model/pet.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..058ad2dc9b143166540406245fb5ad3ac09b1c16 --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/model/pet.g.dart @@ -0,0 +1,258 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'pet.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +Serializer<Pet> _$petSerializer = new _$PetSerializer(); + +class _$PetSerializer implements StructuredSerializer<Pet> { + @override + final Iterable<Type> types = const [Pet, _$Pet]; + @override + final String wireName = 'Pet'; + + @override + Iterable<Object> serialize(Serializers serializers, Pet object, + {FullType specifiedType = FullType.unspecified}) { + final result = <Object>[ + 'id', + serializers.serialize(object.id, specifiedType: const FullType(int)), + 'category', + serializers.serialize(object.category, + specifiedType: const FullType(Category)), + 'name', + serializers.serialize(object.name, specifiedType: const FullType(String)), + 'photoUrls', + serializers.serialize(object.photoUrls, + specifiedType: const FullType(List, const [const FullType(String)])), + 'tags', + serializers.serialize(object.tags, + specifiedType: const FullType(List, const [const FullType(Tag)])), + 'status', + serializers.serialize(object.status, + specifiedType: const FullType(String)), + ]; + + return result; + } + + @override + Pet deserialize(Serializers serializers, Iterable<Object> serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new PetBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current as String; + iterator.moveNext(); + final dynamic value = iterator.current; + switch (key) { + case 'id': + result.id = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; + case 'category': + result.category.replace(serializers.deserialize(value, + specifiedType: const FullType(Category)) as Category); + break; + case 'name': + result.name = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + case 'photoUrls': + result.photoUrls = serializers.deserialize(value, + specifiedType: + const FullType(List, const [const FullType(String)])) + as List<String>; + break; + case 'tags': + result.tags = serializers.deserialize(value, + specifiedType: + const FullType(List, const [const FullType(Tag)])) + as List<Tag>; + break; + case 'status': + result.status = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + } + } + + return result.build(); + } +} + +class _$Pet extends Pet { + @override + final int id; + @override + final Category category; + @override + final String name; + @override + final List<String> photoUrls; + @override + final List<Tag> tags; + @override + final String status; + + factory _$Pet([void Function(PetBuilder) updates]) => + (new PetBuilder()..update(updates)).build(); + + _$Pet._( + {this.id, + this.category, + this.name, + this.photoUrls, + this.tags, + this.status}) + : super._() { + if (id == null) { + throw new BuiltValueNullFieldError('Pet', 'id'); + } + if (category == null) { + throw new BuiltValueNullFieldError('Pet', 'category'); + } + if (name == null) { + throw new BuiltValueNullFieldError('Pet', 'name'); + } + if (photoUrls == null) { + throw new BuiltValueNullFieldError('Pet', 'photoUrls'); + } + if (tags == null) { + throw new BuiltValueNullFieldError('Pet', 'tags'); + } + if (status == null) { + throw new BuiltValueNullFieldError('Pet', 'status'); + } + } + + @override + Pet rebuild(void Function(PetBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + PetBuilder toBuilder() => new PetBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Pet && + id == other.id && + category == other.category && + name == other.name && + photoUrls == other.photoUrls && + tags == other.tags && + status == other.status; + } + + @override + int get hashCode { + return $jf($jc( + $jc( + $jc($jc($jc($jc(0, id.hashCode), category.hashCode), name.hashCode), + photoUrls.hashCode), + tags.hashCode), + status.hashCode)); + } + + @override + String toString() { + return (newBuiltValueToStringHelper('Pet') + ..add('id', id) + ..add('category', category) + ..add('name', name) + ..add('photoUrls', photoUrls) + ..add('tags', tags) + ..add('status', status)) + .toString(); + } +} + +class PetBuilder implements Builder<Pet, PetBuilder> { + _$Pet _$v; + + int _id; + int get id => _$this._id; + set id(int id) => _$this._id = id; + + CategoryBuilder _category; + CategoryBuilder get category => _$this._category ??= new CategoryBuilder(); + set category(CategoryBuilder category) => _$this._category = category; + + String _name; + String get name => _$this._name; + set name(String name) => _$this._name = name; + + List<String> _photoUrls; + List<String> get photoUrls => _$this._photoUrls; + set photoUrls(List<String> photoUrls) => _$this._photoUrls = photoUrls; + + List<Tag> _tags; + List<Tag> get tags => _$this._tags; + set tags(List<Tag> tags) => _$this._tags = tags; + + String _status; + String get status => _$this._status; + set status(String status) => _$this._status = status; + + PetBuilder(); + + PetBuilder get _$this { + if (_$v != null) { + _id = _$v.id; + _category = _$v.category?.toBuilder(); + _name = _$v.name; + _photoUrls = _$v.photoUrls; + _tags = _$v.tags; + _status = _$v.status; + _$v = null; + } + return this; + } + + @override + void replace(Pet other) { + if (other == null) { + throw new ArgumentError.notNull('other'); + } + _$v = other as _$Pet; + } + + @override + void update(void Function(PetBuilder) updates) { + if (updates != null) updates(this); + } + + @override + _$Pet build() { + _$Pet _$result; + try { + _$result = _$v ?? + new _$Pet._( + id: id, + category: category.build(), + name: name, + photoUrls: photoUrls, + tags: tags, + status: status); + } catch (_) { + String _$failedField; + try { + _$failedField = 'category'; + category.build(); + } catch (e) { + throw new BuiltValueNestedFieldError( + 'Pet', _$failedField, e.toString()); + } + rethrow; + } + replace(_$result); + return _$result; + } +} + +// ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,lines_longer_than_80_chars,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new diff --git a/samples/client/petstore/dart-dio/lib/model/tag.dart b/samples/client/petstore/dart-dio/lib/model/tag.dart new file mode 100644 index 0000000000000000000000000000000000000000..9d304767721bc3066ac7821162a87265861eca25 --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/model/tag.dart @@ -0,0 +1,20 @@ +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; + +part 'tag.g.dart'; + +abstract class Tag implements Built<Tag, TagBuilder> { + @nullable + @BuiltValueField(wireName: 'id') + int get id; + + @nullable + @BuiltValueField(wireName: 'name') + String get name; + + // Boilerplate code needed to wire-up generated code + Tag._(); + + factory Tag([updates(TagBuilder b)]) = _$Tag; + static Serializer<Tag> get serializer => _$tagSerializer; +} diff --git a/samples/client/petstore/dart-dio/lib/model/tag.g.dart b/samples/client/petstore/dart-dio/lib/model/tag.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..e7de1eab62c9f5312c542a11111cface7825e03e --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/model/tag.g.dart @@ -0,0 +1,144 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'tag.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +Serializer<Tag> _$tagSerializer = new _$TagSerializer(); + +class _$TagSerializer implements StructuredSerializer<Tag> { + @override + final Iterable<Type> types = const [Tag, _$Tag]; + @override + final String wireName = 'Tag'; + + @override + Iterable<Object> serialize(Serializers serializers, Tag object, + {FullType specifiedType = FullType.unspecified}) { + final result = <Object>[ + 'id', + serializers.serialize(object.id, specifiedType: const FullType(int)), + 'name', + serializers.serialize(object.name, specifiedType: const FullType(String)), + ]; + + return result; + } + + @override + Tag deserialize(Serializers serializers, Iterable<Object> serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new TagBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current as String; + iterator.moveNext(); + final dynamic value = iterator.current; + switch (key) { + case 'id': + result.id = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; + case 'name': + result.name = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + } + } + + return result.build(); + } +} + +class _$Tag extends Tag { + @override + final int id; + @override + final String name; + + factory _$Tag([void Function(TagBuilder) updates]) => + (new TagBuilder()..update(updates)).build(); + + _$Tag._({this.id, this.name}) : super._() { + if (id == null) { + throw new BuiltValueNullFieldError('Tag', 'id'); + } + if (name == null) { + throw new BuiltValueNullFieldError('Tag', 'name'); + } + } + + @override + Tag rebuild(void Function(TagBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + TagBuilder toBuilder() => new TagBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Tag && id == other.id && name == other.name; + } + + @override + int get hashCode { + return $jf($jc($jc(0, id.hashCode), name.hashCode)); + } + + @override + String toString() { + return (newBuiltValueToStringHelper('Tag') + ..add('id', id) + ..add('name', name)) + .toString(); + } +} + +class TagBuilder implements Builder<Tag, TagBuilder> { + _$Tag _$v; + + int _id; + int get id => _$this._id; + set id(int id) => _$this._id = id; + + String _name; + String get name => _$this._name; + set name(String name) => _$this._name = name; + + TagBuilder(); + + TagBuilder get _$this { + if (_$v != null) { + _id = _$v.id; + _name = _$v.name; + _$v = null; + } + return this; + } + + @override + void replace(Tag other) { + if (other == null) { + throw new ArgumentError.notNull('other'); + } + _$v = other as _$Tag; + } + + @override + void update(void Function(TagBuilder) updates) { + if (updates != null) updates(this); + } + + @override + _$Tag build() { + final _$result = _$v ?? new _$Tag._(id: id, name: name); + replace(_$result); + return _$result; + } +} + +// ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,lines_longer_than_80_chars,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new diff --git a/samples/client/petstore/dart-dio/lib/model/user.dart b/samples/client/petstore/dart-dio/lib/model/user.dart new file mode 100644 index 0000000000000000000000000000000000000000..da351b55d8989801d4b51ee35af3240659a53d07 --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/model/user.dart @@ -0,0 +1,46 @@ +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; + +part 'user.g.dart'; + +abstract class User implements Built<User, UserBuilder> { + @nullable + @BuiltValueField(wireName: 'id') + int get id; + + @nullable + @BuiltValueField(wireName: 'username') + String get username; + + @nullable + @BuiltValueField(wireName: 'firstName') + String get firstName; + + @nullable + @BuiltValueField(wireName: 'lastName') + String get lastName; + + @nullable + @BuiltValueField(wireName: 'email') + String get email; + + @nullable + @BuiltValueField(wireName: 'password') + String get password; + + @nullable + @BuiltValueField(wireName: 'phone') + String get phone; + /* User Status */ + @nullable + + /* User Status */ + @BuiltValueField(wireName: 'userStatus') + int get userStatus; + + // Boilerplate code needed to wire-up generated code + User._(); + + factory User([updates(UserBuilder b)]) = _$User; + static Serializer<User> get serializer => _$userSerializer; +} diff --git a/samples/client/petstore/dart-dio/lib/model/user.g.dart b/samples/client/petstore/dart-dio/lib/model/user.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..2b277e1d49c21c4d7d3c83bd90567728815cd173 --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/model/user.g.dart @@ -0,0 +1,290 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'user.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +Serializer<User> _$userSerializer = new _$UserSerializer(); + +class _$UserSerializer implements StructuredSerializer<User> { + @override + final Iterable<Type> types = const [User, _$User]; + @override + final String wireName = 'User'; + + @override + Iterable<Object> serialize(Serializers serializers, User object, + {FullType specifiedType = FullType.unspecified}) { + final result = <Object>[ + 'id', + serializers.serialize(object.id, specifiedType: const FullType(int)), + 'username', + serializers.serialize(object.username, + specifiedType: const FullType(String)), + 'firstName', + serializers.serialize(object.firstName, + specifiedType: const FullType(String)), + 'lastName', + serializers.serialize(object.lastName, + specifiedType: const FullType(String)), + 'email', + serializers.serialize(object.email, + specifiedType: const FullType(String)), + 'password', + serializers.serialize(object.password, + specifiedType: const FullType(String)), + 'phone', + serializers.serialize(object.phone, + specifiedType: const FullType(String)), + 'userStatus', + serializers.serialize(object.userStatus, + specifiedType: const FullType(int)), + ]; + + return result; + } + + @override + User deserialize(Serializers serializers, Iterable<Object> serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new UserBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current as String; + iterator.moveNext(); + final dynamic value = iterator.current; + switch (key) { + case 'id': + result.id = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; + case 'username': + result.username = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + case 'firstName': + result.firstName = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + case 'lastName': + result.lastName = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + case 'email': + result.email = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + case 'password': + result.password = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + case 'phone': + result.phone = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + case 'userStatus': + result.userStatus = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; + } + } + + return result.build(); + } +} + +class _$User extends User { + @override + final int id; + @override + final String username; + @override + final String firstName; + @override + final String lastName; + @override + final String email; + @override + final String password; + @override + final String phone; + @override + final int userStatus; + + factory _$User([void Function(UserBuilder) updates]) => + (new UserBuilder()..update(updates)).build(); + + _$User._( + {this.id, + this.username, + this.firstName, + this.lastName, + this.email, + this.password, + this.phone, + this.userStatus}) + : super._() { + if (id == null) { + throw new BuiltValueNullFieldError('User', 'id'); + } + if (username == null) { + throw new BuiltValueNullFieldError('User', 'username'); + } + if (firstName == null) { + throw new BuiltValueNullFieldError('User', 'firstName'); + } + if (lastName == null) { + throw new BuiltValueNullFieldError('User', 'lastName'); + } + if (email == null) { + throw new BuiltValueNullFieldError('User', 'email'); + } + if (password == null) { + throw new BuiltValueNullFieldError('User', 'password'); + } + if (phone == null) { + throw new BuiltValueNullFieldError('User', 'phone'); + } + if (userStatus == null) { + throw new BuiltValueNullFieldError('User', 'userStatus'); + } + } + + @override + User rebuild(void Function(UserBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + UserBuilder toBuilder() => new UserBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is User && + id == other.id && + username == other.username && + firstName == other.firstName && + lastName == other.lastName && + email == other.email && + password == other.password && + phone == other.phone && + userStatus == other.userStatus; + } + + @override + int get hashCode { + return $jf($jc( + $jc( + $jc( + $jc( + $jc( + $jc($jc($jc(0, id.hashCode), username.hashCode), + firstName.hashCode), + lastName.hashCode), + email.hashCode), + password.hashCode), + phone.hashCode), + userStatus.hashCode)); + } + + @override + String toString() { + return (newBuiltValueToStringHelper('User') + ..add('id', id) + ..add('username', username) + ..add('firstName', firstName) + ..add('lastName', lastName) + ..add('email', email) + ..add('password', password) + ..add('phone', phone) + ..add('userStatus', userStatus)) + .toString(); + } +} + +class UserBuilder implements Builder<User, UserBuilder> { + _$User _$v; + + int _id; + int get id => _$this._id; + set id(int id) => _$this._id = id; + + String _username; + String get username => _$this._username; + set username(String username) => _$this._username = username; + + String _firstName; + String get firstName => _$this._firstName; + set firstName(String firstName) => _$this._firstName = firstName; + + String _lastName; + String get lastName => _$this._lastName; + set lastName(String lastName) => _$this._lastName = lastName; + + String _email; + String get email => _$this._email; + set email(String email) => _$this._email = email; + + String _password; + String get password => _$this._password; + set password(String password) => _$this._password = password; + + String _phone; + String get phone => _$this._phone; + set phone(String phone) => _$this._phone = phone; + + int _userStatus; + int get userStatus => _$this._userStatus; + set userStatus(int userStatus) => _$this._userStatus = userStatus; + + UserBuilder(); + + UserBuilder get _$this { + if (_$v != null) { + _id = _$v.id; + _username = _$v.username; + _firstName = _$v.firstName; + _lastName = _$v.lastName; + _email = _$v.email; + _password = _$v.password; + _phone = _$v.phone; + _userStatus = _$v.userStatus; + _$v = null; + } + return this; + } + + @override + void replace(User other) { + if (other == null) { + throw new ArgumentError.notNull('other'); + } + _$v = other as _$User; + } + + @override + void update(void Function(UserBuilder) updates) { + if (updates != null) updates(this); + } + + @override + _$User build() { + final _$result = _$v ?? + new _$User._( + id: id, + username: username, + firstName: firstName, + lastName: lastName, + email: email, + password: password, + phone: phone, + userStatus: userStatus); + replace(_$result); + return _$result; + } +} + +// ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,lines_longer_than_80_chars,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new diff --git a/samples/client/petstore/dart-dio/lib/serializers.dart b/samples/client/petstore/dart-dio/lib/serializers.dart new file mode 100644 index 0000000000000000000000000000000000000000..88a06193f3ca0f91f81c96bb34c1505c9201ae82 --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/serializers.dart @@ -0,0 +1,48 @@ +library serializers; + +import 'package:built_value/serializer.dart'; +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/standard_json_plugin.dart'; + +import 'package:openapi/model/api_response.dart'; +import 'package:openapi/model/category.dart'; +import 'package:openapi/model/order.dart'; +import 'package:openapi/model/pet.dart'; +import 'package:openapi/model/tag.dart'; +import 'package:openapi/model/user.dart'; + +part 'serializers.g.dart'; + +@SerializersFor(const [ + ApiResponse, + Category, + Order, + Pet, + Tag, + User, +]) + +//allow all models to be serialized within a list +Serializers serializers = (_$serializers.toBuilder() + ..addBuilderFactory( + const FullType(BuiltList, const [const FullType(ApiResponse)]), + () => new ListBuilder<ApiResponse>()) + ..addBuilderFactory( + const FullType(BuiltList, const [const FullType(Category)]), + () => new ListBuilder<Category>()) + ..addBuilderFactory( + const FullType(BuiltList, const [const FullType(Order)]), + () => new ListBuilder<Order>()) + ..addBuilderFactory( + const FullType(BuiltList, const [const FullType(Pet)]), + () => new ListBuilder<Pet>()) + ..addBuilderFactory( + const FullType(BuiltList, const [const FullType(Tag)]), + () => new ListBuilder<Tag>()) + ..addBuilderFactory( + const FullType(BuiltList, const [const FullType(User)]), + () => new ListBuilder<User>())) + .build(); + +Serializers standardSerializers = + (serializers.toBuilder()..addPlugin(StandardJsonPlugin())).build(); diff --git a/samples/client/petstore/dart-dio/lib/serializers.g.dart b/samples/client/petstore/dart-dio/lib/serializers.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..8106577235d9f1b8879fab971df8576a0c6963f9 --- /dev/null +++ b/samples/client/petstore/dart-dio/lib/serializers.g.dart @@ -0,0 +1,18 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of serializers; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +Serializers _$serializers = (new Serializers().toBuilder() + ..add(ApiResponse.serializer) + ..add(Category.serializer) + ..add(Order.serializer) + ..add(Pet.serializer) + ..add(Tag.serializer) + ..add(User.serializer)) + .build(); + +// ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,lines_longer_than_80_chars,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new diff --git a/samples/client/petstore/dart-dio/pubspec.yaml b/samples/client/petstore/dart-dio/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b2d0d4d00ab78a8673219c3aae0925f68ee184d2 --- /dev/null +++ b/samples/client/petstore/dart-dio/pubspec.yaml @@ -0,0 +1,13 @@ +name: openapi +version: 1.0.0 +description: OpenAPI API client +environment: + sdk: ">=2.3.0 <3.0.0" +dependencies: + dio: ^3.0.3 + built_value: 6.7.0 + built_collection: 4.2.2 +dev_dependencies: + built_value_generator: ^6.7.1 + build_runner: ^1.7.1 + test: 1.6.5 \ No newline at end of file diff --git a/website/i18n/en.json b/website/i18n/en.json index 254fe09c38f01c2bec0172104a3dc594616f30c8..f7ba090bb22fc1ab936c12ef122df1446b08ac15 100644 --- a/website/i18n/en.json +++ b/website/i18n/en.json @@ -112,6 +112,9 @@ "generators/dart-jaguar": { "title": "generators/dart-jaguar" }, + "generators/dart-dio": { + "title": "generators/dart-dio" + }, "generators/dart": { "title": "generators/dart" },