Skip to content

[dart-dio] Fix basepath #4911

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class {{clientName}} {

Dio dio;
Serializers serializers;
String basePath = "http://petstore.swagger.io/v2";
String basePath = "{{{basePath}}}";

{{clientName}}({this.dio, Serializers serializers}) {
if (dio == null) {
Expand Down
52 changes: 26 additions & 26 deletions samples/client/petstore/dart-dio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,36 +57,36 @@ All URIs are relative to *http://petstore.swagger.io/v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*PetApi* | [**addPet**](doc//PetApi.md#addpet) | **post** /pet | Add a new pet to the store
*PetApi* | [**deletePet**](doc//PetApi.md#deletepet) | **delete** /pet/{petId} | Deletes a pet
*PetApi* | [**findPetsByStatus**](doc//PetApi.md#findpetsbystatus) | **get** /pet/findByStatus | Finds Pets by status
*PetApi* | [**findPetsByTags**](doc//PetApi.md#findpetsbytags) | **get** /pet/findByTags | Finds Pets by tags
*PetApi* | [**getPetById**](doc//PetApi.md#getpetbyid) | **get** /pet/{petId} | Find pet by ID
*PetApi* | [**updatePet**](doc//PetApi.md#updatepet) | **put** /pet | Update an existing pet
*PetApi* | [**updatePetWithForm**](doc//PetApi.md#updatepetwithform) | **post** /pet/{petId} | Updates a pet in the store with form data
*PetApi* | [**uploadFile**](doc//PetApi.md#uploadfile) | **post** /pet/{petId}/uploadImage | uploads an image
*StoreApi* | [**deleteOrder**](doc//StoreApi.md#deleteorder) | **delete** /store/order/{orderId} | Delete purchase order by ID
*StoreApi* | [**getInventory**](doc//StoreApi.md#getinventory) | **get** /store/inventory | Returns pet inventories by status
*StoreApi* | [**getOrderById**](doc//StoreApi.md#getorderbyid) | **get** /store/order/{orderId} | Find purchase order by ID
*StoreApi* | [**placeOrder**](doc//StoreApi.md#placeorder) | **post** /store/order | Place an order for a pet
*UserApi* | [**createUser**](doc//UserApi.md#createuser) | **post** /user | Create user
*UserApi* | [**createUsersWithArrayInput**](doc//UserApi.md#createuserswitharrayinput) | **post** /user/createWithArray | Creates list of users with given input array
*UserApi* | [**createUsersWithListInput**](doc//UserApi.md#createuserswithlistinput) | **post** /user/createWithList | Creates list of users with given input array
*UserApi* | [**deleteUser**](doc//UserApi.md#deleteuser) | **delete** /user/{username} | Delete user
*UserApi* | [**getUserByName**](doc//UserApi.md#getuserbyname) | **get** /user/{username} | Get user by user name
*UserApi* | [**loginUser**](doc//UserApi.md#loginuser) | **get** /user/login | Logs user into the system
*UserApi* | [**logoutUser**](doc//UserApi.md#logoutuser) | **get** /user/logout | Logs out current logged in user session
*UserApi* | [**updateUser**](doc//UserApi.md#updateuser) | **put** /user/{username} | Updated user
*PetApi* | [**addPet**](doc\/PetApi.md#addpet) | **post** /pet | Add a new pet to the store
*PetApi* | [**deletePet**](doc\/PetApi.md#deletepet) | **delete** /pet/{petId} | Deletes a pet
*PetApi* | [**findPetsByStatus**](doc\/PetApi.md#findpetsbystatus) | **get** /pet/findByStatus | Finds Pets by status
*PetApi* | [**findPetsByTags**](doc\/PetApi.md#findpetsbytags) | **get** /pet/findByTags | Finds Pets by tags
*PetApi* | [**getPetById**](doc\/PetApi.md#getpetbyid) | **get** /pet/{petId} | Find pet by ID
*PetApi* | [**updatePet**](doc\/PetApi.md#updatepet) | **put** /pet | Update an existing pet
*PetApi* | [**updatePetWithForm**](doc\/PetApi.md#updatepetwithform) | **post** /pet/{petId} | Updates a pet in the store with form data
*PetApi* | [**uploadFile**](doc\/PetApi.md#uploadfile) | **post** /pet/{petId}/uploadImage | uploads an image
*StoreApi* | [**deleteOrder**](doc\/StoreApi.md#deleteorder) | **delete** /store/order/{orderId} | Delete purchase order by ID
*StoreApi* | [**getInventory**](doc\/StoreApi.md#getinventory) | **get** /store/inventory | Returns pet inventories by status
*StoreApi* | [**getOrderById**](doc\/StoreApi.md#getorderbyid) | **get** /store/order/{orderId} | Find purchase order by ID
*StoreApi* | [**placeOrder**](doc\/StoreApi.md#placeorder) | **post** /store/order | Place an order for a pet
*UserApi* | [**createUser**](doc\/UserApi.md#createuser) | **post** /user | Create user
*UserApi* | [**createUsersWithArrayInput**](doc\/UserApi.md#createuserswitharrayinput) | **post** /user/createWithArray | Creates list of users with given input array
*UserApi* | [**createUsersWithListInput**](doc\/UserApi.md#createuserswithlistinput) | **post** /user/createWithList | Creates list of users with given input array
*UserApi* | [**deleteUser**](doc\/UserApi.md#deleteuser) | **delete** /user/{username} | Delete user
*UserApi* | [**getUserByName**](doc\/UserApi.md#getuserbyname) | **get** /user/{username} | Get user by user name
*UserApi* | [**loginUser**](doc\/UserApi.md#loginuser) | **get** /user/login | Logs user into the system
*UserApi* | [**logoutUser**](doc\/UserApi.md#logoutuser) | **get** /user/logout | Logs out current logged in user session
*UserApi* | [**updateUser**](doc\/UserApi.md#updateuser) | **put** /user/{username} | Updated user


## Documentation For Models

- [ApiResponse](doc//ApiResponse.md)
- [Category](doc//Category.md)
- [Order](doc//Order.md)
- [Pet](doc//Pet.md)
- [Tag](doc//Tag.md)
- [User](doc//User.md)
- [ApiResponse](doc\/ApiResponse.md)
- [Category](doc\/Category.md)
- [Order](doc\/Order.md)
- [Pet](doc\/Pet.md)
- [Tag](doc\/Tag.md)
- [User](doc\/User.md)


## Documentation For Authorization
Expand Down
149 changes: 77 additions & 72 deletions samples/client/petstore/dart-dio/lib/api/pet_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:built_value/serializer.dart';
import 'package:openapi/model/pet.dart';
import 'package:openapi/model/api_response.dart';
import 'dart:typed_data';
import 'package:openapi/api_util.dart';

class PetApi {
final Dio _dio;
Expand All @@ -22,26 +23,24 @@ class PetApi {

String path = "/pet";

// query params
Map<String, dynamic> queryParams = {};
Map<String, String> headerParams = Map.from(headers ?? {});
Map<String, String> formParams = {};
Map<String, dynamic> queryParams = {};
Map<String, String> headerParams = Map.from(headers ?? {});
dynamic bodyData;

queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);
formParams.removeWhere((key, value) => value == null);
queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);

List<String> contentTypes = ["application/json","application/xml"];

List<String> contentTypes = [
"application/json",
"application/xml"];

var serializedBody = _serializers.serialize(body);
var jsonbody = json.encode(serializedBody);
bodyData = jsonbody;

return _dio.request(
path,
queryParameters: queryParams,
data: jsonbody,
data: bodyData,
options: Options(
method: 'post'.toUpperCase(),
headers: headerParams,
Expand All @@ -57,22 +56,22 @@ class PetApi {

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 = {};
Map<String, dynamic> queryParams = {};
Map<String, String> headerParams = Map.from(headers ?? {});
dynamic bodyData;

headerParams["api_key"] = apiKey;
queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);
formParams.removeWhere((key, value) => value == null);
queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);

List<String> contentTypes = [];

List<String> contentTypes = [];


return _dio.request(
path,
queryParameters: queryParams,
data: bodyData,
options: Options(
method: 'delete'.toUpperCase(),
headers: headerParams,
Expand All @@ -88,22 +87,22 @@ class PetApi {

String path = "/pet/findByStatus";

// query params
Map<String, dynamic> queryParams = {};
Map<String, String> headerParams = Map.from(headers ?? {});
Map<String, String> formParams = {};
Map<String, dynamic> queryParams = {};
Map<String, String> headerParams = Map.from(headers ?? {});
dynamic bodyData;

queryParams["status"] = status;
queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);
formParams.removeWhere((key, value) => value == null);
queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);

List<String> contentTypes = [];

List<String> contentTypes = [];


return _dio.request(
path,
queryParameters: queryParams,
data: bodyData,
options: Options(
method: 'get'.toUpperCase(),
headers: headerParams,
Expand Down Expand Up @@ -134,22 +133,22 @@ class PetApi {

String path = "/pet/findByTags";

// query params
Map<String, dynamic> queryParams = {};
Map<String, String> headerParams = Map.from(headers ?? {});
Map<String, String> formParams = {};
Map<String, dynamic> queryParams = {};
Map<String, String> headerParams = Map.from(headers ?? {});
dynamic bodyData;

queryParams["tags"] = tags;
queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);
formParams.removeWhere((key, value) => value == null);
queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);

List<String> contentTypes = [];

List<String> contentTypes = [];


return _dio.request(
path,
queryParameters: queryParams,
data: bodyData,
options: Options(
method: 'get'.toUpperCase(),
headers: headerParams,
Expand Down Expand Up @@ -180,21 +179,21 @@ class PetApi {

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 = {};
Map<String, dynamic> queryParams = {};
Map<String, String> headerParams = Map.from(headers ?? {});
dynamic bodyData;

queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);
formParams.removeWhere((key, value) => value == null);
queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);

List<String> contentTypes = [];

List<String> contentTypes = [];


return _dio.request(
path,
queryParameters: queryParams,
data: bodyData,
options: Options(
method: 'get'.toUpperCase(),
headers: headerParams,
Expand Down Expand Up @@ -224,26 +223,24 @@ class PetApi {

String path = "/pet";

// query params
Map<String, dynamic> queryParams = {};
Map<String, String> headerParams = Map.from(headers ?? {});
Map<String, String> formParams = {};
Map<String, dynamic> queryParams = {};
Map<String, String> headerParams = Map.from(headers ?? {});
dynamic bodyData;

queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);

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"];

List<String> contentTypes = [
"application/json",
"application/xml"];

var serializedBody = _serializers.serialize(body);
var jsonbody = json.encode(serializedBody);
bodyData = jsonbody;

return _dio.request(
path,
queryParameters: queryParams,
data: jsonbody,
data: bodyData,
options: Options(
method: 'put'.toUpperCase(),
headers: headerParams,
Expand All @@ -259,22 +256,23 @@ class PetApi {

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 = {};
Map<String, dynamic> queryParams = {};
Map<String, String> headerParams = Map.from(headers ?? {});
dynamic bodyData;

queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);
formParams.removeWhere((key, value) => value == null);
queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);

List<String> contentTypes = [
"application/x-www-form-urlencoded"];
List<String> contentTypes = ["application/x-www-form-urlencoded"];

Map<String, dynamic> formData = {};
bodyData = FormData.fromMap(formData);


return _dio.request(
path,
queryParameters: queryParams,
data: bodyData,
options: Options(
method: 'post'.toUpperCase(),
headers: headerParams,
Expand All @@ -290,22 +288,29 @@ class PetApi {

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 = {};
Map<String, dynamic> queryParams = {};
Map<String, String> headerParams = Map.from(headers ?? {});
dynamic bodyData;

queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);

queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);
formParams.removeWhere((key, value) => value == null);
List<String> contentTypes = ["multipart/form-data"];

List<String> contentTypes = [
"multipart/form-data"];
Map<String, dynamic> formData = {};
if (additionalMetadata != null) {
formData['additionalMetadata'] = parameterToString(additionalMetadata);
}
if (file != null) {
formData['file'] = MultipartFile.fromBytes(file, filename: "file");
}
bodyData = FormData.fromMap(formData);


return _dio.request(
path,
queryParameters: queryParams,
data: bodyData,
options: Options(
method: 'post'.toUpperCase(),
headers: headerParams,
Expand Down
Loading