mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
107452d406
60
README.md
60
README.md
@ -14,19 +14,20 @@ Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additi
|
||||
- [Overview](#overview)
|
||||
- [Table of Contents](#table-of-contents)
|
||||
- Installation
|
||||
- [Build and run using docker](#build-and-run-using-docker)
|
||||
- [Build a nodejs server stub](#build-a-nodejs-server-stub)
|
||||
- [Compatibility](#compatibility)
|
||||
- [Prerequisites](#prerequisites)
|
||||
- [OS X Users](#os-x-users)
|
||||
- [Building](#building)
|
||||
- [OS X Users](#os-x-users)
|
||||
- [Building](#building)
|
||||
- [Docker](#docker)
|
||||
- [Build and run](#build-and-run-using-docker)
|
||||
- [Build a Node.js server stub](#build-a-nodejs-server-stub)
|
||||
- Generators
|
||||
- [To generate a sample client library](#to-generate-a-sample-client-library)
|
||||
- [Generating libraries from your server](#generating-libraries-from-your-server)
|
||||
- [Modifying the client library format](#modifying-the-client-library-format)
|
||||
- [Making your own codegen modules](#making-your-own-codegen-modules)
|
||||
- [Where is Javascript???](#where-is-javascript)
|
||||
- [Generating a client from local files](#generating-a-client-from-local-files)
|
||||
- [Generating a client from local files](#generating-a-client-from-local-files)
|
||||
- [Customizing the generator](#customizing-the-generator)
|
||||
- [Validating your swagger spec](#validating-your-swagger-spec)
|
||||
- [Generating dynamic html api documentation](#generating-dynamic-html-api-documentation)
|
||||
@ -40,26 +41,9 @@ Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additi
|
||||
- [Java Spring MVC](#java-spring-mvc)
|
||||
- [To build the codegen library](#to-build-the-codegen-library)
|
||||
- [Online Generators](#online-generators)
|
||||
- [Guidelines for Contribution](https://github.com/swagger-api/swagger-codegen/wiki/Guidelines-for-Contribution)
|
||||
- [License](#license)
|
||||
|
||||
## Build and run using docker
|
||||
|
||||
```
|
||||
git clone https://github.com/swagger-api/swagger-codegen
|
||||
|
||||
cd swagger-codegen
|
||||
|
||||
./run-in-docker.sh mvn package
|
||||
```
|
||||
|
||||
## Build a nodejs server stub
|
||||
|
||||
```
|
||||
./run-in-docker.sh generate \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l nodejs \
|
||||
-o samples/server/petstore/nodejs
|
||||
```
|
||||
|
||||
## Compatibility
|
||||
The Swagger Specification has undergone 3 revisions since initial creation in 2010. The swagger-codegen project has the following compatibilies with the swagger specification:
|
||||
@ -88,14 +72,33 @@ export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
|
||||
export PATH=${JAVA_HOME}/bin:$PATH
|
||||
```
|
||||
|
||||
#### Building
|
||||
### Building
|
||||
|
||||
After cloning the project, you can build it from source with this command:
|
||||
|
||||
```
|
||||
mvn package
|
||||
```
|
||||
|
||||
### Docker
|
||||
#### Build and run using docker
|
||||
|
||||
```
|
||||
git clone https://github.com/swagger-api/swagger-codegen
|
||||
|
||||
cd swagger-codegen
|
||||
|
||||
./run-in-docker.sh mvn package
|
||||
```
|
||||
|
||||
#### Build a Node.js server stub
|
||||
|
||||
```
|
||||
./run-in-docker.sh generate \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l nodejs \
|
||||
-o samples/server/petstore/nodejs
|
||||
```
|
||||
|
||||
### To generate a sample client library
|
||||
You can build a client against the swagger sample [petstore](http://petstore.swagger.io) API as follows:
|
||||
|
||||
@ -204,7 +207,7 @@ static code generation.
|
||||
There is a third-party component called [swagger-js-codegen](https://github.com/wcandillon/swagger-js-codegen) that can generate angularjs or nodejs source code from a swagger specification.
|
||||
|
||||
|
||||
#### Generating a client from local files
|
||||
### Generating a client from local files
|
||||
If you don't want to call your server, you can save the swagger spec files into a directory and pass an argument
|
||||
to the code generator like this:
|
||||
|
||||
@ -481,6 +484,11 @@ curl -X POST -H "content-type:application/json" -d '{"swaggerUrl":"http://petsto
|
||||
```
|
||||
Then you will receieve a JSON response with the URL to download the zipped code.
|
||||
|
||||
Guidelines for Contribution
|
||||
---------------------------
|
||||
|
||||
Please refer to this [page](https://github.com/swagger-api/swagger-codegen/wiki/Guidelines-for-Contribution)
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
|
@ -202,11 +202,11 @@ public class DefaultCodegen {
|
||||
}
|
||||
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
return outputFolder + "/" + apiPackage().replace('.', '/');
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
return outputFolder + "/" + modelPackage().replace('.', '/');
|
||||
}
|
||||
|
||||
public Map<String, Object> additionalProperties() {
|
||||
@ -1853,7 +1853,7 @@ public class DefaultCodegen {
|
||||
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
String suffix = apiTemplateFiles().get(templateName);
|
||||
return apiFileFolder() + File.separator + toApiFilename(tag) + suffix;
|
||||
return apiFileFolder() + '/' + toApiFilename(tag) + suffix;
|
||||
}
|
||||
|
||||
public boolean shouldOverwrite(String filename) {
|
||||
|
@ -194,7 +194,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
this.sanitizeConfig();
|
||||
|
||||
final String invokerFolder = (sourceFolder + File.separator + invokerPackage).replace(".", File.separator);
|
||||
final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/");
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle"));
|
||||
supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
|
||||
@ -202,7 +202,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", invokerFolder, "ApiClient.java"));
|
||||
supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java"));
|
||||
|
||||
final String authFolder = (sourceFolder + File.separator + invokerPackage + ".auth").replace(".", File.separator);
|
||||
final String authFolder = (sourceFolder + '/' + invokerPackage + ".auth").replace(".", "/");
|
||||
supportingFiles.add(new SupportingFile("auth/HttpBasicAuth.mustache", authFolder, "HttpBasicAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/ApiKeyAuth.mustache", authFolder, "ApiKeyAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
|
||||
@ -257,12 +257,12 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', '/');
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', '/');
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -78,13 +78,13 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiException.java"));
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("ApiOriginFilter.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiOriginFilter.java"));
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiOriginFilter.java"));
|
||||
supportingFiles.add(new SupportingFile("ApiResponseMessage.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiResponseMessage.java"));
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiResponseMessage.java"));
|
||||
supportingFiles.add(new SupportingFile("NotFoundException.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "NotFoundException.java"));
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "NotFoundException.java"));
|
||||
supportingFiles.add(new SupportingFile("web.mustache",
|
||||
("src/main/webapp/WEB-INF"), "web.xml"));
|
||||
|
||||
@ -215,7 +215,7 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
}
|
||||
|
||||
private String implFileFolder(String output) {
|
||||
return outputFolder + "/" + output + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
return outputFolder + "/" + output + "/" + apiPackage().replace('.', '/');
|
||||
}
|
||||
|
||||
public boolean shouldOverwrite(String filename) {
|
||||
|
@ -173,6 +173,9 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
|
||||
// remove dollar sign
|
||||
name = name.replaceAll("$", "");
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
name = name.toLowerCase();
|
||||
@ -203,6 +206,9 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
public String toModelName(String name) {
|
||||
name = sanitizeName(name);
|
||||
|
||||
// remove dollar sign
|
||||
name = name.replaceAll("$", "");
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
|
@ -4,7 +4,7 @@ import io.swagger.codegen.SupportingFile;
|
||||
import java.io.File;
|
||||
|
||||
public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "typescript-angular";
|
||||
|
@ -12,12 +12,12 @@ namespace {{package}} {
|
||||
*/
|
||||
{{/description}}
|
||||
export class {{classname}} {
|
||||
private basePath = '{{basePath}}';
|
||||
protected basePath = '{{basePath}}';
|
||||
public defaultHeaders : any = {};
|
||||
|
||||
static $inject: string[] = ['$http', '$httpParamSerializer'];
|
||||
|
||||
constructor(private $http: ng.IHttpService, basePath?: string, private $httpParamSerializer?: (d: any) => any) {
|
||||
constructor(protected $http: ng.IHttpService, protected $httpParamSerializer?: (d: any) => any, basePath?: string) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
@ -68,7 +68,7 @@ namespace {{package}} {
|
||||
{{/hasFormParams}}
|
||||
{{#formParams}}
|
||||
formParams['{{baseName}}'] = {{paramName}};
|
||||
|
||||
|
||||
{{/formParams}}
|
||||
let httpRequestParams: any = {
|
||||
method: '{{httpMethod}}',
|
||||
|
@ -27,7 +27,7 @@ namespace {{package}} {
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
|
||||
export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}}
|
||||
export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}}
|
||||
{{.}} = <any> '{{.}}',{{/values}}{{/allowableValues}}
|
||||
}
|
||||
{{/isEnum}}
|
||||
@ -36,4 +36,4 @@ namespace {{package}} {
|
||||
{{/hasEnums}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,11 @@ class VoidAuth implements Authentication {
|
||||
*/
|
||||
{{/description}}
|
||||
export class {{classname}} {
|
||||
private basePath = '{{basePath}}';
|
||||
protected basePath = '{{basePath}}';
|
||||
protected defaultHeaders : any = {};
|
||||
|
||||
|
||||
|
||||
public authentications = {
|
||||
'default': <Authentication>new VoidAuth(),
|
||||
{{#authMethods}}
|
||||
@ -154,17 +158,21 @@ export class {{classname}} {
|
||||
{{#isOAuth}}
|
||||
{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
private extendObj<T1,T2>(objA: T1, objB: T2) {
|
||||
for(let key in objB){
|
||||
if(objB.hasOwnProperty(key)){
|
||||
objA[key] = objB[key];
|
||||
}
|
||||
}
|
||||
return <T1&T2>objA;
|
||||
}
|
||||
{{#operation}}
|
||||
|
||||
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }> {
|
||||
let path = this.url + this.basePath + '{{path}}';
|
||||
|
||||
{{#pathParams}}
|
||||
path = path.replace('{' + '{{baseName}}' + '}', String({{paramName}}));
|
||||
|
||||
{{/pathParams}}
|
||||
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> {
|
||||
const path = this.url + this.basePath + '{{path}}'{{#pathParams}}
|
||||
.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
|
||||
let queryParameters: any = {};
|
||||
let headerParams: any = {};
|
||||
let headerParams: any = this.extendObj({}, this.defaultHeaders);
|
||||
let formParams: any = {};
|
||||
|
||||
{{#allParams}}{{#required}}
|
||||
@ -194,7 +202,7 @@ export class {{classname}} {
|
||||
{{/isFile}}
|
||||
|
||||
{{/formParams}}
|
||||
let deferred = promise.defer<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }>();
|
||||
let deferred = promise.defer<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }>();
|
||||
|
||||
let requestOptions: request.Options = {
|
||||
method: '{{httpMethod}}',
|
||||
|
@ -71,6 +71,10 @@ class Configuration(object):
|
||||
self.username = ""
|
||||
# Password for HTTP basic authentication
|
||||
self.password = ""
|
||||
{{#authMethods}}{{#isOAuth}}
|
||||
# access token for OAuth
|
||||
self.access_token = ""
|
||||
{{/isOAuth}}{{/authMethods}}
|
||||
|
||||
# Logging Settings
|
||||
self.logger = {}
|
||||
@ -231,8 +235,15 @@ class Configuration(object):
|
||||
'key': 'Authorization',
|
||||
'value': self.get_basic_auth_token()
|
||||
},
|
||||
{{/isBasic}}
|
||||
{{/authMethods}}
|
||||
{{/isBasic}}{{#isOauth}}
|
||||
'{{name}}':
|
||||
{
|
||||
'type': 'oauth2',
|
||||
'in': 'header',
|
||||
'key': 'Authorization',
|
||||
'value': 'Bearer ' + self.access_token
|
||||
},
|
||||
{{/isOauth}}{{/authMethods}}
|
||||
}
|
||||
|
||||
def to_debug_report(self):
|
||||
|
@ -42,6 +42,17 @@ module {{moduleName}}
|
||||
else
|
||||
false
|
||||
end
|
||||
when /\AArray<(?<inner_type>.+)>\z/
|
||||
inner_type = Regexp.last_match[:inner_type]
|
||||
value.map { |v| _deserialize(inner_type, v) }
|
||||
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
||||
k_type = Regexp.last_match[:k_type]
|
||||
v_type = Regexp.last_match[:v_type]
|
||||
{}.tap do |hash|
|
||||
value.each do |k, v|
|
||||
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
||||
end
|
||||
end
|
||||
else # model
|
||||
_model = {{moduleName}}.const_get(type).new
|
||||
_model.build_from_hash(value)
|
||||
@ -63,11 +74,7 @@ module {{moduleName}}
|
||||
self.class.attribute_map.each_pair do |attr, param|
|
||||
value = self.send(attr)
|
||||
next if value.nil?
|
||||
if value.is_a?(Array)
|
||||
hash[param] = value.compact.map{ |v| _to_hash(v) }
|
||||
else
|
||||
hash[param] = _to_hash(value)
|
||||
end
|
||||
hash[param] = _to_hash(value)
|
||||
end
|
||||
hash
|
||||
end
|
||||
@ -75,7 +82,13 @@ module {{moduleName}}
|
||||
# Method to output non-array value in the form of hash
|
||||
# For object, use to_hash. Otherwise, just return the value
|
||||
def _to_hash(value)
|
||||
if value.respond_to? :to_hash
|
||||
if value.is_a?(Array)
|
||||
value.compact.map{ |v| _to_hash(v) }
|
||||
elsif value.is_a?(Hash)
|
||||
{}.tap do |hash|
|
||||
value.each { |k, v| hash[k] = _to_hash(v) }
|
||||
end
|
||||
elsif value.respond_to? :to_hash
|
||||
value.to_hash
|
||||
else
|
||||
value
|
||||
|
Binary file not shown.
@ -13,3 +13,10 @@ Collecting pluggy<0.4.0,>=0.3.0 (from tox->-r dev-requirements.txt (line 2))
|
||||
Using cached pluggy-0.3.0-py2.py3-none-any.whl
|
||||
Installing collected packages: nose, virtualenv, py, pluggy, tox, coverage, randomize
|
||||
Successfully installed coverage-3.7.1 nose-1.3.7 pluggy-0.3.0 py-1.4.30 randomize-0.13 tox-2.1.1 virtualenv-13.1.2
|
||||
Requirement already satisfied (use --upgrade to upgrade): nose in ./.venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 1))
|
||||
Requirement already satisfied (use --upgrade to upgrade): tox in ./.venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 2))
|
||||
Requirement already satisfied (use --upgrade to upgrade): coverage in ./.venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 3))
|
||||
Requirement already satisfied (use --upgrade to upgrade): randomize in ./.venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 4))
|
||||
Requirement already satisfied (use --upgrade to upgrade): virtualenv>=1.11.2 in ./.venv/lib/python2.7/site-packages (from tox->-r dev-requirements.txt (line 2))
|
||||
Requirement already satisfied (use --upgrade to upgrade): py>=1.4.17 in ./.venv/lib/python2.7/site-packages (from tox->-r dev-requirements.txt (line 2))
|
||||
Requirement already satisfied (use --upgrade to upgrade): pluggy<0.4.0,>=0.3.0 in ./.venv/lib/python2.7/site-packages (from tox->-r dev-requirements.txt (line 2))
|
||||
|
@ -409,7 +409,7 @@ class PetApi(object):
|
||||
select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = ['api_key', 'petstore_auth']
|
||||
auth_settings = ['api_key']
|
||||
|
||||
response = self.api_client.call_api(resource_path, method,
|
||||
path_params,
|
||||
|
@ -72,6 +72,10 @@ class Configuration(object):
|
||||
# Password for HTTP basic authentication
|
||||
self.password = ""
|
||||
|
||||
# access token for OAuth
|
||||
self.access_token = ""
|
||||
|
||||
|
||||
# Logging Settings
|
||||
self.logger = {}
|
||||
self.logger["package_logger"] = logging.getLogger("swagger_client")
|
||||
@ -220,6 +224,7 @@ class Configuration(object):
|
||||
'key': 'api_key',
|
||||
'value': self.get_api_key_with_prefix('api_key')
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
def to_debug_report(self):
|
||||
|
@ -42,6 +42,17 @@ module Petstore
|
||||
else
|
||||
false
|
||||
end
|
||||
when /\AArray<(?<inner_type>.+)>\z/
|
||||
inner_type = Regexp.last_match[:inner_type]
|
||||
value.map { |v| _deserialize(inner_type, v) }
|
||||
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
||||
k_type = Regexp.last_match[:k_type]
|
||||
v_type = Regexp.last_match[:v_type]
|
||||
{}.tap do |hash|
|
||||
value.each do |k, v|
|
||||
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
||||
end
|
||||
end
|
||||
else # model
|
||||
_model = Petstore.const_get(type).new
|
||||
_model.build_from_hash(value)
|
||||
@ -63,11 +74,7 @@ module Petstore
|
||||
self.class.attribute_map.each_pair do |attr, param|
|
||||
value = self.send(attr)
|
||||
next if value.nil?
|
||||
if value.is_a?(Array)
|
||||
hash[param] = value.compact.map{ |v| _to_hash(v) }
|
||||
else
|
||||
hash[param] = _to_hash(value)
|
||||
end
|
||||
hash[param] = _to_hash(value)
|
||||
end
|
||||
hash
|
||||
end
|
||||
@ -75,7 +82,13 @@ module Petstore
|
||||
# Method to output non-array value in the form of hash
|
||||
# For object, use to_hash. Otherwise, just return the value
|
||||
def _to_hash(value)
|
||||
if value.respond_to? :to_hash
|
||||
if value.is_a?(Array)
|
||||
value.compact.map{ |v| _to_hash(v) }
|
||||
elsif value.is_a?(Hash)
|
||||
{}.tap do |hash|
|
||||
value.each { |k, v| hash[k] = _to_hash(v) }
|
||||
end
|
||||
elsif value.respond_to? :to_hash
|
||||
value.to_hash
|
||||
else
|
||||
value
|
||||
|
81
samples/client/petstore/ruby/spec/base_object_spec.rb
Normal file
81
samples/client/petstore/ruby/spec/base_object_spec.rb
Normal file
@ -0,0 +1,81 @@
|
||||
require 'spec_helper'
|
||||
|
||||
class ArrayMapObject < Petstore::BaseObject
|
||||
attr_accessor :int_arr, :pet_arr, :int_map, :pet_map, :int_arr_map, :pet_arr_map
|
||||
|
||||
def self.attribute_map
|
||||
{
|
||||
:int_arr => :int_arr,
|
||||
:pet_arr => :pet_arr,
|
||||
:int_map => :int_map,
|
||||
:pet_map => :pet_map,
|
||||
:int_arr_map => :int_arr_map,
|
||||
:pet_arr_map => :pet_arr_map
|
||||
}
|
||||
end
|
||||
|
||||
def self.swagger_types
|
||||
{
|
||||
:int_arr => :'Array<Integer>',
|
||||
:pet_arr => :'Array<Pet>',
|
||||
:int_map => :'Hash<String, Integer>',
|
||||
:pet_map => :'Hash<String, Pet>',
|
||||
:int_arr_map => :'Hash<String, Array<Integer>>',
|
||||
:pet_arr_map => :'Hash<String, Array<Pet>>'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe Petstore::BaseObject do
|
||||
describe 'array and map properties' do
|
||||
let(:obj) { ArrayMapObject.new }
|
||||
|
||||
let(:data) do
|
||||
{int_arr: [123, 456],
|
||||
pet_arr: [{name: 'Kitty'}],
|
||||
int_map: {'int' => 123},
|
||||
pet_map: {'pet' => {name: 'Kitty'}},
|
||||
int_arr_map: {'int_arr' => [123, 456]},
|
||||
pet_arr_map: {'pet_arr' => [{name: 'Kitty'}]}
|
||||
}
|
||||
end
|
||||
|
||||
it 'works for #build_from_hash' do
|
||||
obj.build_from_hash(data)
|
||||
|
||||
obj.int_arr.should == [123, 456]
|
||||
|
||||
obj.pet_arr.should be_a(Array)
|
||||
obj.pet_arr.size.should == 1
|
||||
pet = obj.pet_arr.first
|
||||
pet.should be_a(Petstore::Pet)
|
||||
pet.name.should == 'Kitty'
|
||||
|
||||
obj.int_map.should be_a(Hash)
|
||||
obj.int_map.should == {'int' => 123}
|
||||
|
||||
obj.pet_map.should be_a(Hash)
|
||||
pet = obj.pet_map['pet']
|
||||
pet.should be_a(Petstore::Pet)
|
||||
pet.name.should == 'Kitty'
|
||||
|
||||
obj.int_arr_map.should be_a(Hash)
|
||||
arr = obj.int_arr_map['int_arr']
|
||||
arr.should == [123, 456]
|
||||
|
||||
obj.pet_arr_map.should be_a(Hash)
|
||||
arr = obj.pet_arr_map['pet_arr']
|
||||
arr.should be_a(Array)
|
||||
arr.size.should == 1
|
||||
pet = arr.first
|
||||
pet.should be_a(Petstore::Pet)
|
||||
pet.name.should == 'Kitty'
|
||||
end
|
||||
|
||||
it 'works for #to_hash' do
|
||||
obj.build_from_hash(data)
|
||||
obj.to_hash.should == data
|
||||
end
|
||||
end
|
||||
end
|
@ -1,13 +1,24 @@
|
||||
/// <reference path="api.d.ts" />
|
||||
|
||||
module API.Client {
|
||||
namespace API.Client {
|
||||
'use strict';
|
||||
|
||||
export class Category {
|
||||
|
||||
|
||||
|
||||
export interface Category {
|
||||
|
||||
|
||||
|
||||
id: number;
|
||||
|
||||
|
||||
|
||||
name: string;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,32 +1,67 @@
|
||||
/// <reference path="api.d.ts" />
|
||||
|
||||
module API.Client {
|
||||
namespace API.Client {
|
||||
'use strict';
|
||||
|
||||
export class Order {
|
||||
|
||||
|
||||
|
||||
export interface Order {
|
||||
|
||||
|
||||
|
||||
id: number;
|
||||
|
||||
|
||||
|
||||
petId: number;
|
||||
|
||||
|
||||
|
||||
quantity: number;
|
||||
|
||||
|
||||
|
||||
shipDate: Date;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
*/
|
||||
|
||||
status: Order.StatusEnum;
|
||||
|
||||
|
||||
|
||||
complete: boolean;
|
||||
|
||||
}
|
||||
|
||||
export module Order {
|
||||
|
||||
export enum StatusEnum {
|
||||
placed = <any> 'placed',
|
||||
approved = <any> 'approved',
|
||||
export namespace Order {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export enum StatusEnum {
|
||||
placed = <any> 'placed',
|
||||
approved = <any> 'approved',
|
||||
delivered = <any> 'delivered',
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,32 +1,67 @@
|
||||
/// <reference path="api.d.ts" />
|
||||
|
||||
module API.Client {
|
||||
namespace API.Client {
|
||||
'use strict';
|
||||
|
||||
export class Pet {
|
||||
|
||||
|
||||
|
||||
export interface Pet {
|
||||
|
||||
|
||||
|
||||
id: number;
|
||||
|
||||
|
||||
|
||||
category: Category;
|
||||
|
||||
|
||||
|
||||
name: string;
|
||||
|
||||
|
||||
|
||||
photoUrls: Array<string>;
|
||||
|
||||
|
||||
|
||||
tags: Array<Tag>;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* pet status in the store
|
||||
*/
|
||||
|
||||
status: Pet.StatusEnum;
|
||||
|
||||
}
|
||||
|
||||
export module Pet {
|
||||
|
||||
export enum StatusEnum {
|
||||
available = <any> 'available',
|
||||
pending = <any> 'pending',
|
||||
export namespace Pet {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export enum StatusEnum {
|
||||
available = <any> 'available',
|
||||
pending = <any> 'pending',
|
||||
sold = <any> 'sold',
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,26 +2,48 @@
|
||||
|
||||
/* tslint:disable:no-unused-variable member-ordering */
|
||||
|
||||
module API.Client {
|
||||
|
||||
namespace API.Client {
|
||||
'use strict';
|
||||
|
||||
|
||||
export class PetApi {
|
||||
private basePath = 'http://petstore.swagger.io/v2';
|
||||
protected basePath = 'http://petstore.swagger.io/v2';
|
||||
public defaultHeaders : any = {};
|
||||
|
||||
static $inject: string[] = ['$http', '$httpParamSerializer'];
|
||||
|
||||
constructor(private $http: ng.IHttpService, basePath?: string, private $httpParamSerializer?: (any) => any) {
|
||||
constructor(protected $http: ng.IHttpService, protected $httpParamSerializer?: (d: any) => any, basePath?: string) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
}
|
||||
|
||||
public updatePet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/pet';
|
||||
private extendObj<T1,T2>(objA: T1, objB: T2) {
|
||||
for(let key in objB){
|
||||
if(objB.hasOwnProperty(key)){
|
||||
objA[key] = objB[key];
|
||||
}
|
||||
}
|
||||
return <T1&T2>objA;
|
||||
}
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headerParams: any = {};
|
||||
var httpRequestParams: any = {
|
||||
|
||||
|
||||
public updatePet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
const path = this.basePath + '/pet';
|
||||
|
||||
let queryParameters: any = {};
|
||||
let headerParams: any = this.extendObj({}, this.defaultHeaders);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let httpRequestParams: any = {
|
||||
method: 'PUT',
|
||||
url: path,
|
||||
json: true,
|
||||
@ -33,22 +55,27 @@ module API.Client {
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams) {
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public addPet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/pet';
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headerParams: any = {};
|
||||
var httpRequestParams: any = {
|
||||
public addPet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
const path = this.basePath + '/pet';
|
||||
|
||||
let queryParameters: any = {};
|
||||
let headerParams: any = this.extendObj({}, this.defaultHeaders);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let httpRequestParams: any = {
|
||||
method: 'POST',
|
||||
url: path,
|
||||
json: true,
|
||||
@ -60,26 +87,32 @@ module API.Client {
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams) {
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public findPetsByStatus (status?: Array<string>, extraHttpRequestParams?: any ) : ng.IHttpPromise<Array<Pet>> {
|
||||
var path = this.basePath + '/pet/findByStatus';
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headerParams: any = {};
|
||||
public findPetsByStatus (status?: Array<string>, extraHttpRequestParams?: any ) : ng.IHttpPromise<Array<Pet>> {
|
||||
const path = this.basePath + '/pet/findByStatus';
|
||||
|
||||
let queryParameters: any = {};
|
||||
let headerParams: any = this.extendObj({}, this.defaultHeaders);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (status !== undefined) {
|
||||
queryParameters['status'] = status;
|
||||
}
|
||||
|
||||
var httpRequestParams: any = {
|
||||
|
||||
|
||||
|
||||
|
||||
let httpRequestParams: any = {
|
||||
method: 'GET',
|
||||
url: path,
|
||||
json: true,
|
||||
@ -90,26 +123,32 @@ module API.Client {
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams) {
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public findPetsByTags (tags?: Array<string>, extraHttpRequestParams?: any ) : ng.IHttpPromise<Array<Pet>> {
|
||||
var path = this.basePath + '/pet/findByTags';
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headerParams: any = {};
|
||||
public findPetsByTags (tags?: Array<string>, extraHttpRequestParams?: any ) : ng.IHttpPromise<Array<Pet>> {
|
||||
const path = this.basePath + '/pet/findByTags';
|
||||
|
||||
let queryParameters: any = {};
|
||||
let headerParams: any = this.extendObj({}, this.defaultHeaders);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (tags !== undefined) {
|
||||
queryParameters['tags'] = tags;
|
||||
}
|
||||
|
||||
var httpRequestParams: any = {
|
||||
|
||||
|
||||
|
||||
|
||||
let httpRequestParams: any = {
|
||||
method: 'GET',
|
||||
url: path,
|
||||
json: true,
|
||||
@ -120,29 +159,33 @@ module API.Client {
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams) {
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
|
||||
public getPetById (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise<Pet> {
|
||||
var path = this.basePath + '/pet/{petId}';
|
||||
const path = this.basePath + '/pet/{petId}'
|
||||
.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
let queryParameters: any = {};
|
||||
let headerParams: any = this.extendObj({}, this.defaultHeaders);
|
||||
|
||||
|
||||
path = path.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headerParams: any = {};
|
||||
// verify required parameter 'petId' is set
|
||||
if (!petId) {
|
||||
throw new Error('Missing required parameter petId when calling getPetById');
|
||||
}
|
||||
|
||||
var httpRequestParams: any = {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let httpRequestParams: any = {
|
||||
method: 'GET',
|
||||
url: path,
|
||||
json: true,
|
||||
@ -153,37 +196,49 @@ module API.Client {
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams) {
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
|
||||
public updatePetWithForm (petId: string, name?: string, status?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/pet/{petId}';
|
||||
const path = this.basePath + '/pet/{petId}'
|
||||
.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
let queryParameters: any = {};
|
||||
let headerParams: any = this.extendObj({}, this.defaultHeaders);
|
||||
|
||||
let formParams: any = {};
|
||||
|
||||
|
||||
path = path.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headerParams: any = {};
|
||||
var formParams: any = {};
|
||||
|
||||
// verify required parameter 'petId' is set
|
||||
if (!petId) {
|
||||
throw new Error('Missing required parameter petId when calling updatePetWithForm');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
headerParams['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
|
||||
|
||||
|
||||
formParams['name'] = name;
|
||||
|
||||
|
||||
|
||||
formParams['status'] = status;
|
||||
|
||||
var httpRequestParams: any = {
|
||||
|
||||
|
||||
let httpRequestParams: any = {
|
||||
method: 'POST',
|
||||
url: path,
|
||||
json: false,
|
||||
@ -195,31 +250,38 @@ module API.Client {
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams) {
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
|
||||
public deletePet (petId: number, apiKey?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/pet/{petId}';
|
||||
const path = this.basePath + '/pet/{petId}'
|
||||
.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
let queryParameters: any = {};
|
||||
let headerParams: any = this.extendObj({}, this.defaultHeaders);
|
||||
|
||||
|
||||
path = path.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headerParams: any = {};
|
||||
// verify required parameter 'petId' is set
|
||||
if (!petId) {
|
||||
throw new Error('Missing required parameter petId when calling deletePet');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
headerParams['api_key'] = apiKey;
|
||||
|
||||
var httpRequestParams: any = {
|
||||
|
||||
|
||||
|
||||
let httpRequestParams: any = {
|
||||
method: 'DELETE',
|
||||
url: path,
|
||||
json: true,
|
||||
@ -230,37 +292,49 @@ module API.Client {
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams) {
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
|
||||
public uploadFile (petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/pet/{petId}/uploadImage';
|
||||
const path = this.basePath + '/pet/{petId}/uploadImage'
|
||||
.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
let queryParameters: any = {};
|
||||
let headerParams: any = this.extendObj({}, this.defaultHeaders);
|
||||
|
||||
let formParams: any = {};
|
||||
|
||||
|
||||
path = path.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headerParams: any = {};
|
||||
var formParams: any = {};
|
||||
|
||||
// verify required parameter 'petId' is set
|
||||
if (!petId) {
|
||||
throw new Error('Missing required parameter petId when calling uploadFile');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
headerParams['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
|
||||
|
||||
|
||||
formParams['additionalMetadata'] = additionalMetadata;
|
||||
|
||||
|
||||
|
||||
formParams['file'] = file;
|
||||
|
||||
var httpRequestParams: any = {
|
||||
|
||||
|
||||
let httpRequestParams: any = {
|
||||
method: 'POST',
|
||||
url: path,
|
||||
json: false,
|
||||
@ -272,14 +346,12 @@ module API.Client {
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams) {
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,24 @@
|
||||
/// <reference path="api.d.ts" />
|
||||
|
||||
module API.Client {
|
||||
namespace API.Client {
|
||||
'use strict';
|
||||
|
||||
export class Tag {
|
||||
|
||||
|
||||
|
||||
export interface Tag {
|
||||
|
||||
|
||||
|
||||
id: number;
|
||||
|
||||
|
||||
|
||||
name: string;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,28 +1,52 @@
|
||||
/// <reference path="api.d.ts" />
|
||||
|
||||
module API.Client {
|
||||
namespace API.Client {
|
||||
'use strict';
|
||||
|
||||
export class User {
|
||||
|
||||
|
||||
|
||||
export interface User {
|
||||
|
||||
|
||||
|
||||
id: number;
|
||||
|
||||
|
||||
|
||||
username: string;
|
||||
|
||||
|
||||
|
||||
firstName: string;
|
||||
|
||||
|
||||
|
||||
lastName: string;
|
||||
|
||||
|
||||
|
||||
email: string;
|
||||
|
||||
|
||||
|
||||
password: string;
|
||||
|
||||
|
||||
|
||||
phone: string;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* User Status
|
||||
*/
|
||||
|
||||
userStatus: number;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,18 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"noImplicitAny": true,
|
||||
"out": "client.js"
|
||||
},
|
||||
"files": [
|
||||
"API/Client/Category.ts",
|
||||
"API/Client/Pet.ts",
|
||||
"API/Client/StoreApi.ts",
|
||||
"API/Client/User.ts",
|
||||
"API/Client/api.d.ts",
|
||||
"API/Client/Order.ts",
|
||||
"API/Client/PetApi.ts",
|
||||
"API/Client/Tag.ts",
|
||||
"API/Client/UserApi.ts",
|
||||
"typings/tsd.d.ts"
|
||||
]
|
||||
"compilerOptions": {
|
||||
"noImplicitAny": true,
|
||||
"suppressImplicitAnyIndexErrors": true,
|
||||
"out": "client.js"
|
||||
},
|
||||
"files": [
|
||||
"API/Client/Category.ts",
|
||||
"API/Client/Pet.ts",
|
||||
"API/Client/StoreApi.ts",
|
||||
"API/Client/User.ts",
|
||||
"API/Client/api.d.ts",
|
||||
"API/Client/Order.ts",
|
||||
"API/Client/PetApi.ts",
|
||||
"API/Client/Tag.ts",
|
||||
"API/Client/UserApi.ts",
|
||||
"typings/tsd.d.ts"
|
||||
]
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
import api = require('./api');
|
||||
import fs = require('fs');
|
||||
|
||||
var petApi = new api.PetApi('http://petstore.swagger.io');
|
||||
var petApi = new api.PetApi('http://petstore.swagger.io/');
|
||||
petApi.apiKey = 'special-key';
|
||||
|
||||
var pet = new api.Pet();
|
||||
@ -13,39 +13,39 @@ var exitCode = 0;
|
||||
|
||||
// Test various API calls to the petstore
|
||||
petApi.addPet(pet)
|
||||
.then((res) => {
|
||||
var newPet = <api.Pet>(<any>res.response).body;
|
||||
petId = (<any>res.response).body.id;
|
||||
console.log(`Created pet with ID ${petId}`);
|
||||
newPet.status = api.Pet.StatusEnum.available;
|
||||
return petApi.updatePet(newPet);
|
||||
})
|
||||
.then((res) => {
|
||||
console.log('Updated pet using POST body');
|
||||
return petApi.updatePetWithForm(petId, undefined, "pending");
|
||||
})
|
||||
.then((res) => {
|
||||
console.log('Updated pet using POST form');
|
||||
return petApi.uploadFile(petId, undefined, fs.createReadStream('sample.png'));
|
||||
})
|
||||
.then((res) => {
|
||||
console.log('Uploaded image');
|
||||
return petApi.getPetById(petId);
|
||||
})
|
||||
.then((res) => {
|
||||
console.log('Got pet by ID: ' + JSON.stringify(res.body));
|
||||
if (res.body.status != api.Pet.StatusEnum.pending) {
|
||||
throw new Error("Unexpected pet status");
|
||||
}
|
||||
})
|
||||
.catch((err:any) => {
|
||||
console.error(err);
|
||||
exitCode = 1;
|
||||
})
|
||||
.finally(() => {
|
||||
return petApi.deletePet(petId);
|
||||
})
|
||||
.then((res) => {
|
||||
console.log('Deleted pet');
|
||||
process.exit(exitCode);
|
||||
});
|
||||
.then((res) => {
|
||||
var newPet = <api.Pet>res.body;
|
||||
petId = newPet.id;
|
||||
console.log(`Created pet with ID ${petId}`);
|
||||
newPet.status = api.Pet.StatusEnum.available;
|
||||
return petApi.updatePet(newPet);
|
||||
})
|
||||
.then((res) => {
|
||||
console.log('Updated pet using POST body');
|
||||
return petApi.updatePetWithForm(petId, undefined, "pending");
|
||||
})
|
||||
.then((res) => {
|
||||
console.log('Updated pet using POST form');
|
||||
return petApi.uploadFile(petId, undefined, fs.createReadStream('sample.png'));
|
||||
})
|
||||
.then((res) => {
|
||||
console.log('Uploaded image');
|
||||
return petApi.getPetById(petId);
|
||||
})
|
||||
.then((res) => {
|
||||
console.log('Got pet by ID: ' + JSON.stringify(res.body));
|
||||
if (res.body.status != api.Pet.StatusEnum.pending) {
|
||||
throw new Error("Unexpected pet status");
|
||||
}
|
||||
})
|
||||
.catch((err: any) => {
|
||||
console.error(err);
|
||||
exitCode = 1;
|
||||
})
|
||||
.finally(() => {
|
||||
return petApi.deletePet(petId);
|
||||
})
|
||||
.then((res) => {
|
||||
console.log('Deleted pet');
|
||||
process.exit(exitCode);
|
||||
});
|
||||
|
@ -2,6 +2,7 @@
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"noImplicitAny": true,
|
||||
"suppressImplicitAnyIndexErrors": true,
|
||||
"target": "ES5"
|
||||
},
|
||||
"files": [
|
||||
|
Loading…
Reference in New Issue
Block a user