mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-11 02:12:45 +00:00
Add Dart support
This commit is contained in:
28
samples/client/petstore/dart/auth/api_key_auth.dart
Normal file
28
samples/client/petstore/dart/auth/api_key_auth.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
part of api;
|
||||
|
||||
class ApiKeyAuth implements Authentication {
|
||||
|
||||
final String location;
|
||||
final String paramName;
|
||||
String apiKey;
|
||||
String apiKeyPrefix;
|
||||
|
||||
ApiKeyAuth(this.location, this.paramName);
|
||||
|
||||
@override
|
||||
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
String value;
|
||||
if (apiKeyPrefix != null) {
|
||||
value = '$apiKeyPrefix $apiKey';
|
||||
} else {
|
||||
value = apiKey;
|
||||
}
|
||||
|
||||
if (location == 'query' && value != null) {
|
||||
queryParams[paramName] = value;
|
||||
} else if (location == 'header' && value != null) {
|
||||
headerParams[paramName] = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
7
samples/client/petstore/dart/auth/authentication.dart
Normal file
7
samples/client/petstore/dart/auth/authentication.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
part of api;
|
||||
|
||||
abstract class Authentication {
|
||||
|
||||
/// Apply authentication settings to header and query params.
|
||||
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams);
|
||||
}
|
||||
14
samples/client/petstore/dart/auth/http_basic_auth.dart
Normal file
14
samples/client/petstore/dart/auth/http_basic_auth.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
part of api;
|
||||
|
||||
class HttpBasicAuth implements Authentication {
|
||||
|
||||
String username;
|
||||
String password;
|
||||
|
||||
@override
|
||||
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
headerParams["Authorization"] = "Basic " + CryptoUtils.bytesToBase64(UTF8.encode(str));
|
||||
}
|
||||
|
||||
}
|
||||
9
samples/client/petstore/dart/auth/oauth.dart
Normal file
9
samples/client/petstore/dart/auth/oauth.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
part of api;
|
||||
|
||||
class OAuth implements Authentication {
|
||||
|
||||
@override
|
||||
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
// TODO: support oauth
|
||||
}
|
||||
}
|
||||
27
samples/client/petstore/dart/lib/api.dart
Normal file
27
samples/client/petstore/dart/lib/api.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
library api;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:html';
|
||||
import 'package:http/browser_client.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:dartson/dartson.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
part 'api_client.dart';
|
||||
part 'api_exception.dart';
|
||||
part 'auth/authentication.dart';
|
||||
part 'auth/api_key_auth.dart';
|
||||
part 'auth/oauth.dart';
|
||||
part 'auth/http_basic_auth.dart';
|
||||
|
||||
part 'api/user_api.dart';
|
||||
part 'api/store_api.dart';
|
||||
part 'api/pet_api.dart';
|
||||
|
||||
part 'model/user.dart';
|
||||
part 'model/category.dart';
|
||||
part 'model/pet.dart';
|
||||
part 'model/tag.dart';
|
||||
part 'model/order.dart';
|
||||
418
samples/client/petstore/dart/lib/api/pet_api.dart
Normal file
418
samples/client/petstore/dart/lib/api/pet_api.dart
Normal file
@@ -0,0 +1,418 @@
|
||||
part of api;
|
||||
|
||||
|
||||
|
||||
class PetApi {
|
||||
String basePath = "http://petstore.swagger.io/v2";
|
||||
ApiClient apiClient = ApiClient.defaultApiClient;
|
||||
|
||||
PetApi([ApiClient apiClient]) {
|
||||
if (apiClient != null) {
|
||||
this.apiClient = apiClient;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Update an existing pet
|
||||
///
|
||||
///
|
||||
Future updatePet(Pet body) {
|
||||
Object postBody = body;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/pet".replaceAll("{format}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = ["application/json","application/xml"];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = ["petstore_auth"];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'PUT', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Add a new pet to the store
|
||||
///
|
||||
///
|
||||
Future addPet(Pet body) {
|
||||
Object postBody = body;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/pet".replaceAll("{format}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = ["application/json","application/xml"];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = ["petstore_auth"];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'POST', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Finds Pets by status
|
||||
///
|
||||
/// Multiple status values can be provided with comma seperated strings
|
||||
Future<List<Pet>> findPetsByStatus(List<String> status) {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/pet/findByStatus".replaceAll("{format}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
if("null" != status)
|
||||
queryParams["status"] = status is List ? status.join(',') : status;
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = ["petstore_auth"];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'GET', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ApiClient.deserialize(response.body, Pet);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Finds Pets by tags
|
||||
///
|
||||
/// Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
||||
Future<List<Pet>> findPetsByTags(List<String> tags) {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/pet/findByTags".replaceAll("{format}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
if("null" != tags)
|
||||
queryParams["tags"] = tags is List ? tags.join(',') : tags;
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = ["petstore_auth"];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'GET', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ApiClient.deserialize(response.body, Pet);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Find pet by ID
|
||||
///
|
||||
/// Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
Future<Pet> getPetById(int petId) {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/pet/{petId}".replaceAll("{format}","json").replaceAll("{" + "petId" + "}", petId.toString());
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = ["petstore_auth", "api_key"];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'GET', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ApiClient.deserialize(response.body, Pet);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Updates a pet in the store with form data
|
||||
///
|
||||
///
|
||||
Future updatePetWithForm(String petId, String name, String status) {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/pet/{petId}".replaceAll("{format}","json").replaceAll("{" + "petId" + "}", petId.toString());
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = ["application/x-www-form-urlencoded"];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = ["petstore_auth"];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if (name != null) {
|
||||
hasFields = true;
|
||||
mp.fields['name'] = apiClient.parameterToString(name);
|
||||
}
|
||||
|
||||
if (status != null) {
|
||||
hasFields = true;
|
||||
mp.fields['status'] = apiClient.parameterToString(status);
|
||||
}
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
if (name != null)
|
||||
formParams['name'] = apiClient.parameterToString(name);
|
||||
if (status != null)
|
||||
formParams['status'] = apiClient.parameterToString(status);
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'POST', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Deletes a pet
|
||||
///
|
||||
///
|
||||
Future deletePet(int petId, String apiKey) {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/pet/{petId}".replaceAll("{format}","json").replaceAll("{" + "petId" + "}", petId.toString());
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
headerParams["api_key"] = apiKey;
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = ["petstore_auth"];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'DELETE', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// uploads an image
|
||||
///
|
||||
///
|
||||
Future uploadFile(int petId, String additionalMetadata, MultipartFile file) {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/pet/{petId}/uploadImage".replaceAll("{format}","json").replaceAll("{" + "petId" + "}", petId.toString());
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = ["multipart/form-data"];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = ["petstore_auth"];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if (additionalMetadata != null) {
|
||||
hasFields = true;
|
||||
mp.fields['additionalMetadata'] = apiClient.parameterToString(additionalMetadata);
|
||||
}
|
||||
|
||||
if (file != null) {
|
||||
hasFields = true;
|
||||
mp.fields['file'] = file.field;
|
||||
mp.files.add(file);
|
||||
}
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
if (additionalMetadata != null)
|
||||
formParams['additionalMetadata'] = apiClient.parameterToString(additionalMetadata);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'POST', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
201
samples/client/petstore/dart/lib/api/store_api.dart
Normal file
201
samples/client/petstore/dart/lib/api/store_api.dart
Normal file
@@ -0,0 +1,201 @@
|
||||
part of api;
|
||||
|
||||
|
||||
|
||||
class StoreApi {
|
||||
String basePath = "http://petstore.swagger.io/v2";
|
||||
ApiClient apiClient = ApiClient.defaultApiClient;
|
||||
|
||||
StoreApi([ApiClient apiClient]) {
|
||||
if (apiClient != null) {
|
||||
this.apiClient = apiClient;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Returns pet inventories by status
|
||||
///
|
||||
/// Returns a map of status codes to quantities
|
||||
Future<Map<String, int>> getInventory() {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/store/inventory".replaceAll("{format}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = ["api_key"];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'GET', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ApiClient.deserialize(response.body, Map);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Place an order for a pet
|
||||
///
|
||||
///
|
||||
Future<Order> placeOrder(Order body) {
|
||||
Object postBody = body;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/store/order".replaceAll("{format}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = [];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'POST', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ApiClient.deserialize(response.body, Order);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Find purchase order by ID
|
||||
///
|
||||
/// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
Future<Order> getOrderById(String orderId) {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/store/order/{orderId}".replaceAll("{format}","json").replaceAll("{" + "orderId" + "}", orderId.toString());
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = [];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'GET', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ApiClient.deserialize(response.body, Order);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Delete purchase order by ID
|
||||
///
|
||||
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
Future deleteOrder(String orderId) {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/store/order/{orderId}".replaceAll("{format}","json").replaceAll("{" + "orderId" + "}", orderId.toString());
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = [];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'DELETE', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
389
samples/client/petstore/dart/lib/api/user_api.dart
Normal file
389
samples/client/petstore/dart/lib/api/user_api.dart
Normal file
@@ -0,0 +1,389 @@
|
||||
part of api;
|
||||
|
||||
|
||||
|
||||
class UserApi {
|
||||
String basePath = "http://petstore.swagger.io/v2";
|
||||
ApiClient apiClient = ApiClient.defaultApiClient;
|
||||
|
||||
UserApi([ApiClient apiClient]) {
|
||||
if (apiClient != null) {
|
||||
this.apiClient = apiClient;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Create user
|
||||
///
|
||||
/// This can only be done by the logged in user.
|
||||
Future createUser(User body) {
|
||||
Object postBody = body;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/user".replaceAll("{format}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = [];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'POST', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Creates list of users with given input array
|
||||
///
|
||||
///
|
||||
Future createUsersWithArrayInput(List<User> body) {
|
||||
Object postBody = body;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/user/createWithArray".replaceAll("{format}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = [];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'POST', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Creates list of users with given input array
|
||||
///
|
||||
///
|
||||
Future createUsersWithListInput(List<User> body) {
|
||||
Object postBody = body;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/user/createWithList".replaceAll("{format}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = [];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'POST', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Logs user into the system
|
||||
///
|
||||
///
|
||||
Future<String> loginUser(String username, String password) {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/user/login".replaceAll("{format}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
if("null" != username)
|
||||
queryParams["username"] = username is List ? username.join(',') : username;
|
||||
if("null" != password)
|
||||
queryParams["password"] = password is List ? password.join(',') : password;
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = [];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'GET', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ApiClient.deserialize(response.body, String);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Logs out current logged in user session
|
||||
///
|
||||
///
|
||||
Future logoutUser() {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/user/logout".replaceAll("{format}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = [];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'GET', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Get user by user name
|
||||
///
|
||||
///
|
||||
Future<User> getUserByName(String username) {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/user/{username}".replaceAll("{format}","json").replaceAll("{" + "username" + "}", username.toString());
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = [];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'GET', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ApiClient.deserialize(response.body, User);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Updated user
|
||||
///
|
||||
/// This can only be done by the logged in user.
|
||||
Future updateUser(String username, User body) {
|
||||
Object postBody = body;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/user/{username}".replaceAll("{format}","json").replaceAll("{" + "username" + "}", username.toString());
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = [];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'PUT', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Delete user
|
||||
///
|
||||
/// This can only be done by the logged in user.
|
||||
Future deleteUser(String username) {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
// create path and map variables
|
||||
String path = "/user/{username}".replaceAll("{format}","json").replaceAll("{" + "username" + "}", username.toString());
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = {};
|
||||
Map<String, String> headerParams = {};
|
||||
Map<String, String> formParams = {};
|
||||
|
||||
|
||||
|
||||
List<String> contentTypes = [];
|
||||
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
List<String> authNames = [];
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
bool hasFields = false;
|
||||
MultipartRequest mp = new MultipartRequest(null, null);
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return apiClient.invokeAPI(basePath, path, 'DELETE', queryParams, postBody, headerParams, formParams, contentType, authNames).then((response) {
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
}
|
||||
else if(response.body != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
179
samples/client/petstore/dart/lib/api_client.dart
Normal file
179
samples/client/petstore/dart/lib/api_client.dart
Normal file
@@ -0,0 +1,179 @@
|
||||
part of api;
|
||||
|
||||
class ApiClient {
|
||||
static ApiClient defaultApiClient = new ApiClient();
|
||||
|
||||
Map<String, String> _defaultHeaderMap = {};
|
||||
Map<String, Authentication> _authentications = {};
|
||||
static final dson = new Dartson.JSON();
|
||||
final DateFormat _dateFormatter = new DateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
|
||||
ApiClient() {
|
||||
// Setup authentications (key: authentication name, value: authentication).
|
||||
_authentications['api_key'] = new ApiKeyAuth("header", "api_key");
|
||||
_authentications['petstore_auth'] = new OAuth();
|
||||
}
|
||||
|
||||
void addDefaultHeader(String key, String value) {
|
||||
_defaultHeaderMap[key] = value;
|
||||
}
|
||||
|
||||
/// Format the given Date object into string.
|
||||
String formatDate(DateTime date) {
|
||||
return _dateFormatter.format(date);
|
||||
}
|
||||
|
||||
/// Format the given parameter object into string.
|
||||
String parameterToString(Object param) {
|
||||
if (param == null) {
|
||||
return '';
|
||||
} else if (param is DateTime) {
|
||||
return formatDate(param);
|
||||
} else if (param is List) {
|
||||
return (param).join(',');
|
||||
} else {
|
||||
return param.toString();
|
||||
}
|
||||
}
|
||||
|
||||
static dynamic deserialize(String json, dynamic clazz) {
|
||||
var result = json;
|
||||
|
||||
try {
|
||||
var decodedJson = JSON.decode(json);
|
||||
|
||||
if(decodedJson is List) {
|
||||
result = [];
|
||||
for(var obj in decodedJson) {
|
||||
result.add(_createEntity(obj, clazz));
|
||||
}
|
||||
} else {
|
||||
result = _createEntity(json, clazz);
|
||||
}
|
||||
} on FormatException {
|
||||
// Just return the passed in value
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static dynamic _createEntity(dynamic json, dynamic clazz) {
|
||||
bool isMap = json is Map;
|
||||
|
||||
switch(clazz) {
|
||||
|
||||
|
||||
case User:
|
||||
return isMap ? dson.map(json, new User()) : dson.decode(json, new User());
|
||||
|
||||
|
||||
|
||||
case Category:
|
||||
return isMap ? dson.map(json, new Category()) : dson.decode(json, new Category());
|
||||
|
||||
|
||||
|
||||
case Pet:
|
||||
return isMap ? dson.map(json, new Pet()) : dson.decode(json, new Pet());
|
||||
|
||||
|
||||
|
||||
case Tag:
|
||||
return isMap ? dson.map(json, new Tag()) : dson.decode(json, new Tag());
|
||||
|
||||
|
||||
|
||||
case Order:
|
||||
return isMap ? dson.map(json, new Order()) : dson.decode(json, new Order());
|
||||
|
||||
|
||||
default:
|
||||
throw new ApiException(500, 'Could not find a suitable class for deserialization');
|
||||
}
|
||||
}
|
||||
|
||||
static String serialize(Object obj) {
|
||||
String serialized = '';
|
||||
if (obj == null) {
|
||||
serialized = '';
|
||||
} else if (obj is String) {
|
||||
serialized = obj;
|
||||
} else {
|
||||
serialized = dson.encode(obj);
|
||||
}
|
||||
return serialized;
|
||||
}
|
||||
|
||||
Future<Response> invokeAPI( String host,
|
||||
String path,
|
||||
String method,
|
||||
Map<String, String> queryParams,
|
||||
Object body,
|
||||
Map<String, String> headerParams,
|
||||
Map<String, String> formParams,
|
||||
String contentType,
|
||||
List<String> authNames) {
|
||||
|
||||
updateParamsForAuth(authNames, queryParams, headerParams);
|
||||
|
||||
var client = new BrowserClient();
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
for(String key in queryParams.keys) {
|
||||
String value = queryParams[key];
|
||||
if (value != null){
|
||||
if(sb.toString().length == 0) {
|
||||
sb.write("?");
|
||||
} else {
|
||||
sb.write("&");
|
||||
}
|
||||
sb.write(key);
|
||||
sb.write("=");
|
||||
sb.write(value);
|
||||
}
|
||||
}
|
||||
String querystring = sb.toString();
|
||||
|
||||
String url = host + path + querystring;
|
||||
|
||||
headerParams.addAll(_defaultHeaderMap);
|
||||
headerParams['Content-Type'] = contentType;
|
||||
|
||||
var completer = new Completer();
|
||||
|
||||
if(body is MultipartRequest) {
|
||||
var request = new MultipartRequest(method, Uri.parse(url));
|
||||
request.fields.addAll(body.fields);
|
||||
request.files.addAll(body.files);
|
||||
request.headers.addAll(body.headers);
|
||||
request.headers.addAll(headerParams);
|
||||
client.send(request).then((response) => completer.complete(Response.fromStream(response)));
|
||||
} else {
|
||||
var msgBody = contentType == "application/x-www-form-urlencoded" ? formParams : serialize(body);
|
||||
switch(method) {
|
||||
case "GET":
|
||||
return client.get(url, headers: headerParams);
|
||||
case "POST":
|
||||
return client.post(url, headers: headerParams, body: msgBody);
|
||||
case "PUT":
|
||||
return client.put(url, headers: headerParams, body: msgBody);
|
||||
case "DELETE":
|
||||
return client.delete(url, headers: headerParams);
|
||||
}
|
||||
}
|
||||
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
/// Update query and header parameters based on authentication settings.
|
||||
/// @param authNames The authentications to apply
|
||||
void updateParamsForAuth(List<String> authNames, Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
authNames.forEach((authName) {
|
||||
Authentication auth = _authentications[authName];
|
||||
if (auth == null) throw new ArgumentError("Authentication undefined: " + authName);
|
||||
auth.applyToParams(queryParams, headerParams);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
9
samples/client/petstore/dart/lib/api_exception.dart
Normal file
9
samples/client/petstore/dart/lib/api_exception.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
part of api;
|
||||
|
||||
class ApiException implements Exception {
|
||||
int code = 0;
|
||||
String message = null;
|
||||
|
||||
ApiException(this.code, this.message);
|
||||
|
||||
}
|
||||
28
samples/client/petstore/dart/lib/auth/api_key_auth.dart
Normal file
28
samples/client/petstore/dart/lib/auth/api_key_auth.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
part of api;
|
||||
|
||||
class ApiKeyAuth implements Authentication {
|
||||
|
||||
final String location;
|
||||
final String paramName;
|
||||
String apiKey;
|
||||
String apiKeyPrefix;
|
||||
|
||||
ApiKeyAuth(this.location, this.paramName);
|
||||
|
||||
@override
|
||||
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
String value;
|
||||
if (apiKeyPrefix != null) {
|
||||
value = '$apiKeyPrefix $apiKey';
|
||||
} else {
|
||||
value = apiKey;
|
||||
}
|
||||
|
||||
if (location == 'query' && value != null) {
|
||||
queryParams[paramName] = value;
|
||||
} else if (location == 'header' && value != null) {
|
||||
headerParams[paramName] = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
part of api;
|
||||
|
||||
abstract class Authentication {
|
||||
|
||||
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams);
|
||||
}
|
||||
14
samples/client/petstore/dart/lib/auth/http_basic_auth.dart
Normal file
14
samples/client/petstore/dart/lib/auth/http_basic_auth.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
part of api;
|
||||
|
||||
class HttpBasicAuth implements Authentication {
|
||||
|
||||
String username;
|
||||
String password;
|
||||
|
||||
@override
|
||||
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
headerParams["Authorization"] = "Basic " + CryptoUtils.bytesToBase64(UTF8.encode(str));
|
||||
}
|
||||
|
||||
}
|
||||
9
samples/client/petstore/dart/lib/auth/oauth.dart
Normal file
9
samples/client/petstore/dart/lib/auth/oauth.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
part of api;
|
||||
|
||||
class OAuth implements Authentication {
|
||||
|
||||
@override
|
||||
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
// TODO: support oauth
|
||||
}
|
||||
}
|
||||
21
samples/client/petstore/dart/lib/model/category.dart
Normal file
21
samples/client/petstore/dart/lib/model/category.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
part of api;
|
||||
|
||||
|
||||
@Entity()
|
||||
class Category {
|
||||
|
||||
int id = null;
|
||||
|
||||
|
||||
String name = null;
|
||||
|
||||
|
||||
Category();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Category[id=$id, name=$name, ]';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
33
samples/client/petstore/dart/lib/model/order.dart
Normal file
33
samples/client/petstore/dart/lib/model/order.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
part of api;
|
||||
|
||||
|
||||
@Entity()
|
||||
class Order {
|
||||
|
||||
int id = null;
|
||||
|
||||
|
||||
int petId = null;
|
||||
|
||||
|
||||
int quantity = null;
|
||||
|
||||
|
||||
DateTime shipDate = null;
|
||||
|
||||
/* Order Status */
|
||||
String status = null;
|
||||
//enum statusEnum { placed, approved, delivered, };
|
||||
|
||||
bool complete = null;
|
||||
|
||||
|
||||
Order();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Order[id=$id, petId=$petId, quantity=$quantity, shipDate=$shipDate, status=$status, complete=$complete, ]';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
33
samples/client/petstore/dart/lib/model/pet.dart
Normal file
33
samples/client/petstore/dart/lib/model/pet.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
part of api;
|
||||
|
||||
|
||||
@Entity()
|
||||
class Pet {
|
||||
|
||||
int id = null;
|
||||
|
||||
|
||||
Category category = null;
|
||||
|
||||
|
||||
String name = null;
|
||||
|
||||
|
||||
List<String> photoUrls = [];
|
||||
|
||||
|
||||
List<Tag> tags = [];
|
||||
|
||||
/* pet status in the store */
|
||||
String status = null;
|
||||
//enum statusEnum { available, pending, sold, };
|
||||
|
||||
Pet();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Pet[id=$id, category=$category, name=$name, photoUrls=$photoUrls, tags=$tags, status=$status, ]';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
21
samples/client/petstore/dart/lib/model/tag.dart
Normal file
21
samples/client/petstore/dart/lib/model/tag.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
part of api;
|
||||
|
||||
|
||||
@Entity()
|
||||
class Tag {
|
||||
|
||||
int id = null;
|
||||
|
||||
|
||||
String name = null;
|
||||
|
||||
|
||||
Tag();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Tag[id=$id, name=$name, ]';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
39
samples/client/petstore/dart/lib/model/user.dart
Normal file
39
samples/client/petstore/dart/lib/model/user.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
part of api;
|
||||
|
||||
|
||||
@Entity()
|
||||
class User {
|
||||
|
||||
int id = null;
|
||||
|
||||
|
||||
String username = null;
|
||||
|
||||
|
||||
String firstName = null;
|
||||
|
||||
|
||||
String lastName = null;
|
||||
|
||||
|
||||
String email = null;
|
||||
|
||||
|
||||
String password = null;
|
||||
|
||||
|
||||
String phone = null;
|
||||
|
||||
/* User Status */
|
||||
int userStatus = null;
|
||||
|
||||
|
||||
User();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'User[id=$id, username=$username, firstName=$firstName, lastName=$lastName, email=$email, password=$password, phone=$phone, userStatus=$userStatus, ]';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
87
samples/client/petstore/dart/pubspec.lock
Normal file
87
samples/client/petstore/dart/pubspec.lock
Normal file
@@ -0,0 +1,87 @@
|
||||
# Generated by pub
|
||||
# See http://pub.dartlang.org/doc/glossary.html#lockfile
|
||||
packages:
|
||||
analyzer:
|
||||
description: analyzer
|
||||
source: hosted
|
||||
version: "0.25.0+1"
|
||||
args:
|
||||
description: args
|
||||
source: hosted
|
||||
version: "0.13.2"
|
||||
barback:
|
||||
description: barback
|
||||
source: hosted
|
||||
version: "0.15.2+4"
|
||||
browser:
|
||||
description: browser
|
||||
source: hosted
|
||||
version: "0.10.0+2"
|
||||
collection:
|
||||
description: collection
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
crypto:
|
||||
description: crypto
|
||||
source: hosted
|
||||
version: "0.9.0"
|
||||
dartson:
|
||||
description: dartson
|
||||
source: hosted
|
||||
version: "0.2.4"
|
||||
guinness:
|
||||
description: guinness
|
||||
source: hosted
|
||||
version: "0.1.17"
|
||||
http:
|
||||
description: http
|
||||
source: hosted
|
||||
version: "0.11.2"
|
||||
http_parser:
|
||||
description: http_parser
|
||||
source: hosted
|
||||
version: "0.0.2+7"
|
||||
intl:
|
||||
description: intl
|
||||
source: hosted
|
||||
version: "0.12.4+2"
|
||||
logging:
|
||||
description: logging
|
||||
source: hosted
|
||||
version: "0.9.3"
|
||||
path:
|
||||
description: path
|
||||
source: hosted
|
||||
version: "1.3.6"
|
||||
petitparser:
|
||||
description: petitparser
|
||||
source: hosted
|
||||
version: "1.4.3"
|
||||
pool:
|
||||
description: pool
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
source_maps:
|
||||
description: source_maps
|
||||
source: hosted
|
||||
version: "0.10.1"
|
||||
source_span:
|
||||
description: source_span
|
||||
source: hosted
|
||||
version: "1.1.2"
|
||||
stack_trace:
|
||||
description: stack_trace
|
||||
source: hosted
|
||||
version: "1.3.4"
|
||||
string_scanner:
|
||||
description: string_scanner
|
||||
source: hosted
|
||||
version: "0.1.3+1"
|
||||
unittest:
|
||||
description: unittest
|
||||
source: hosted
|
||||
version: "0.11.6+1"
|
||||
watcher:
|
||||
description: watcher
|
||||
source: hosted
|
||||
version: "0.9.6"
|
||||
15
samples/client/petstore/dart/pubspec.yaml
Normal file
15
samples/client/petstore/dart/pubspec.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
name: swagger
|
||||
version: 1.0.0
|
||||
description: Swagger API client
|
||||
dependencies:
|
||||
http: '>=0.11.1 <0.12.0'
|
||||
dartson: "^0.2.4"
|
||||
crypto: "^0.9.0"
|
||||
intl: "^0.12.4+2"
|
||||
|
||||
dev_dependencies:
|
||||
guinness: '^0.1.17'
|
||||
browser: any
|
||||
|
||||
transformers:
|
||||
- dartson
|
||||
85
samples/client/petstore/dart/test/pet_test.dart
Normal file
85
samples/client/petstore/dart/test/pet_test.dart
Normal file
@@ -0,0 +1,85 @@
|
||||
part of tests;
|
||||
|
||||
testPetApi() {
|
||||
var petApi = new PetApi();
|
||||
|
||||
describe('Pet API ', () {
|
||||
it('adds a new pet and gets it by id', () async {
|
||||
var id = 137;
|
||||
|
||||
await petApi.addPet(new Pet()..id = id);
|
||||
var pet = await petApi.getPetById(id);
|
||||
expect(pet.id).toEqual(id);
|
||||
});
|
||||
|
||||
it('doesn\'t get non-existing pet by id', () {
|
||||
expect(petApi.getPetById(6789099)).toThrowWith(anInstanceOf: ApiException);
|
||||
});
|
||||
|
||||
it('deletes existing pet by id', () async {
|
||||
var id = 7689;
|
||||
await petApi.addPet(new Pet()..id = id);
|
||||
await petApi.deletePet(id, 'special-key');
|
||||
expect(petApi.getPetById(id)).toThrowWith(anInstanceOf: ApiException);
|
||||
});
|
||||
|
||||
it('updates pet with form', () async {
|
||||
var id = 52341;
|
||||
await petApi.addPet(new Pet()..id = id..name='Snowy');
|
||||
await petApi.updatePetWithForm('$id', 'Doge', '');
|
||||
var pet = await petApi.getPetById(id);
|
||||
expect(pet.name).toEqual('Doge');
|
||||
});
|
||||
|
||||
it('updates existing pet', () async {
|
||||
var id = 900001;
|
||||
var name = 'Snowy';
|
||||
|
||||
await petApi.addPet(new Pet()..id = id);
|
||||
await petApi.updatePet(new Pet()..id = id..name = name);
|
||||
var pet = await petApi.getPetById(id);
|
||||
expect(pet.name).toEqual(name);
|
||||
});
|
||||
|
||||
it('finds pets by status', () async {
|
||||
var id1 = 754111;
|
||||
var id2 = 1231341;
|
||||
var id3 = 6776251;
|
||||
var status = 'available';
|
||||
|
||||
return Future.wait([petApi.addPet(new Pet()..id = id1..status = status),
|
||||
petApi.addPet(new Pet()..id = id2..status = status),
|
||||
petApi.addPet(new Pet()..id = id3..status = 'sold')])
|
||||
.then((_) async {
|
||||
|
||||
var pets = await petApi.findPetsByStatus([status]);
|
||||
var petIds = pets.map((pet) => pet.id).toList();
|
||||
expect(petIds).toContain(id1);
|
||||
expect(petIds).toContain(id2);
|
||||
expect(petIds).not.toContain(id3);
|
||||
});
|
||||
});
|
||||
|
||||
it('finds pets by tag', () async {
|
||||
var snowyId = 253156;
|
||||
var grumpyId = 734215;
|
||||
var snowyTags = [new Tag()..id=12211..name='terrier'];
|
||||
var grumpyTags = [new Tag()..id=455803..name='grumpy'];
|
||||
await petApi.addPet(new Pet()..id = snowyId..name = 'Snowy'..tags = snowyTags);
|
||||
await petApi.addPet(new Pet()..id = grumpyId..name = 'Grumpy Cat'..tags = grumpyTags);
|
||||
|
||||
var pets = await petApi.findPetsByTags(['grumpy']);
|
||||
var petIds = pets.map((pet) => pet.id).toList();
|
||||
expect(petIds).toContain(grumpyId);
|
||||
expect(petIds).not.toContain(snowyId);
|
||||
});
|
||||
|
||||
it('uploads a pet image', () async {
|
||||
var id = 672322;
|
||||
await petApi.addPet(new Pet()..id = id);
|
||||
var file = new MultipartFile.fromBytes('file', [104, 101, 108, 108, 111]);
|
||||
await petApi.uploadFile(id, '', file);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
30
samples/client/petstore/dart/test/store_test.dart
Normal file
30
samples/client/petstore/dart/test/store_test.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
part of tests;
|
||||
|
||||
testStoreApi() {
|
||||
var storeApi = new StoreApi();
|
||||
|
||||
describe('Store API ', () async {
|
||||
|
||||
it('places an order and gets it by id', () async {
|
||||
var id = 4356;
|
||||
|
||||
await storeApi.placeOrder(new Order()..id = id);
|
||||
var order = await storeApi.getOrderById(id.toString());
|
||||
expect(order.id).toEqual(id);
|
||||
});
|
||||
|
||||
it('deletes an order', () async {
|
||||
var id = 637211;
|
||||
|
||||
await storeApi.placeOrder(new Order()..id = id);
|
||||
await storeApi.deleteOrder(id.toString());
|
||||
expect(storeApi.getOrderById(id.toString())).toThrowWith(anInstanceOf: ApiException);
|
||||
});
|
||||
|
||||
it('gets the store inventory', () async {
|
||||
Map<String, int> inventory = await storeApi.getInventory();
|
||||
expect(inventory.length).not.toBe(0);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
16
samples/client/petstore/dart/test/tests.dart
Normal file
16
samples/client/petstore/dart/test/tests.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
library tests;
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:guinness/guinness.dart';
|
||||
import 'package:swagger/api.dart';
|
||||
|
||||
part 'pet_test.dart';
|
||||
part 'store_test.dart';
|
||||
part 'user_test.dart';
|
||||
|
||||
main() {
|
||||
testPetApi();
|
||||
testStoreApi();
|
||||
testUserApi();
|
||||
}
|
||||
14
samples/client/petstore/dart/test/tests.html
Normal file
14
samples/client/petstore/dart/test/tests.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Unit Test Results</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script type="application/dart" src="tests.dart"></script>
|
||||
<script src="packages/browser/dart.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
63
samples/client/petstore/dart/test/user_test.dart
Normal file
63
samples/client/petstore/dart/test/user_test.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
part of tests;
|
||||
|
||||
testUserApi() {
|
||||
var userApi = new UserApi();
|
||||
|
||||
describe('User API ', () {
|
||||
|
||||
it('creates a user', () async {
|
||||
var id = 67567;
|
||||
var username = 'Mally45';
|
||||
await userApi.createUser(new User()..id = id..username = username);
|
||||
var user = await userApi.getUserByName(username);
|
||||
expect(user.id).toEqual(id);
|
||||
});
|
||||
|
||||
it('creates users with list input', () async {
|
||||
var firstId = 46226;
|
||||
var joe ='Joe';
|
||||
|
||||
var sally = 'Sally';
|
||||
var secondId = 95239;
|
||||
|
||||
var users = [ new User()..id = firstId..username = joe,
|
||||
new User()..id = secondId..username = sally];
|
||||
|
||||
await userApi.createUsersWithListInput(users);
|
||||
var firstUser = await userApi.getUserByName(joe);
|
||||
var secondUser = await userApi.getUserByName(sally);
|
||||
expect(firstUser.id).toEqual(firstId);
|
||||
expect(secondUser.id).toEqual(secondId);
|
||||
});
|
||||
|
||||
it('updates a user', () async {
|
||||
var username ='Arkjam89';
|
||||
var email = 'test@example.com';
|
||||
var user = new User()..id = 733356..username = username;
|
||||
|
||||
await userApi.createUser(user);
|
||||
user.email = email;
|
||||
await userApi.updateUser(username,user);
|
||||
var foundUser = await userApi.getUserByName(username);
|
||||
expect(foundUser.email).toEqual(email);
|
||||
});
|
||||
|
||||
it('deletes a user', () async {
|
||||
var username ='Riddlem325';
|
||||
await userApi.createUser(new User()..id = 1231114..username = username);
|
||||
await userApi.deleteUser(username);
|
||||
expect(userApi.getUserByName(username)).toThrowWith(anInstanceOf: ApiException);
|
||||
});
|
||||
|
||||
it('logs a user in', () async {
|
||||
var username ='sgarad625';
|
||||
var password = 'lokimoki1';
|
||||
var user = new User()..id = 733356..username = username..password = password;
|
||||
|
||||
await userApi.createUser(user);
|
||||
var result = await userApi.loginUser(username, password);
|
||||
expect(result).toContain('logged in user session:');
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user