forked from loafle/openapi-generator-original
Merge pull request #885 from mhardorf/develop_2.0
Added support for TypeScript generation for AngularJS and Node.js
This commit is contained in:
commit
69b75bb1af
@ -35,3 +35,5 @@ cd $APP_DIR
|
||||
./bin/silex-petstore-server.sh
|
||||
./bin/spring-mvc-petstore-server.sh
|
||||
./bin/tizen-petstore.sh
|
||||
./bin/typescript-angular-petstore.sh
|
||||
./bin/typescript-node-petstore.sh
|
||||
|
31
bin/typescript-angular-petstore.sh
Executable file
31
bin/typescript-angular-petstore.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-angular -o samples/client/petstore/typescript-angular"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
31
bin/typescript-node-petstore.sh
Executable file
31
bin/typescript-node-petstore.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-node -o samples/client/petstore/typescript-node"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -0,0 +1,25 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
|
||||
public class TypeScriptAngularClientCodegen extends TypeScriptNodeClientCodegen {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "typescript-angular";
|
||||
}
|
||||
|
||||
public TypeScriptAngularClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/typescript-angular";
|
||||
modelTemplateFiles.put("model.mustache", ".ts");
|
||||
apiTemplateFiles.put("api.mustache", ".ts");
|
||||
templateDir = "TypeScript-Angular";
|
||||
apiPackage = "api";
|
||||
modelPackage = "api";
|
||||
|
||||
supportingFiles.add(new SupportingFile("api.d.mustache", apiPackage + File.separator, "api.d.ts"));
|
||||
}
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.properties.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class TypeScriptNodeClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String groupId = "io.swagger";
|
||||
protected String artifactId = "swagger-typescript-node-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "src/main/typescript";
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "typescript-node";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a TypeScript nodejs client library.";
|
||||
}
|
||||
|
||||
public TypeScriptNodeClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/typescript-node";
|
||||
modelTemplateFiles.put("model.mustache", ".ts");
|
||||
apiTemplateFiles.put("api.mustache", ".ts");
|
||||
templateDir = "TypeScript-node";
|
||||
apiPackage = "api";
|
||||
modelPackage = "model";
|
||||
|
||||
reservedWords = new HashSet<String>(Arrays.asList("abstract",
|
||||
"continue", "for", "new", "switch", "assert", "default", "if",
|
||||
"package", "synchronized", "do", "goto", "private",
|
||||
"this", "break", "double", "implements", "protected", "throw",
|
||||
"byte", "else", "import", "public", "throws", "case", "enum",
|
||||
"instanceof", "return", "transient", "catch", "extends", "int",
|
||||
"short", "try", "char", "final", "interface", "static", "void",
|
||||
"class", "finally", "const", "super", "while"));
|
||||
|
||||
additionalProperties.put("invokerPackage", invokerPackage);
|
||||
additionalProperties.put("groupId", groupId);
|
||||
additionalProperties.put("artifactId", artifactId);
|
||||
additionalProperties.put("artifactVersion", artifactVersion);
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(Arrays.asList(
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float",
|
||||
"Object"));
|
||||
instantiationTypes.put("array", "Array");
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("Array", "Array");
|
||||
typeMapping.put("array", "Array");
|
||||
typeMapping.put("List", "Array");
|
||||
typeMapping.put("boolean", "boolean");
|
||||
typeMapping.put("string", "string");
|
||||
typeMapping.put("int", "number");
|
||||
typeMapping.put("float", "number");
|
||||
typeMapping.put("number", "number");
|
||||
typeMapping.put("long", "number");
|
||||
typeMapping.put("short", "number");
|
||||
typeMapping.put("char", "string");
|
||||
typeMapping.put("double", "number");
|
||||
typeMapping.put("object", "any");
|
||||
typeMapping.put("integer", "number");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$"))
|
||||
return name;
|
||||
|
||||
// camelize the variable name
|
||||
// pet_id => PetId
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*"))
|
||||
name = escapeReservedWord(name);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// 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");
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// should be the same as the model name
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
return getSwaggerType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
return getSwaggerType(p) + "<String, " + getTypeDeclaration(inner)
|
||||
+ ">";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSwaggerType(Property p) {
|
||||
String swaggerType = super.getSwaggerType(p);
|
||||
String type = null;
|
||||
if (typeMapping.containsKey(swaggerType)) {
|
||||
type = typeMapping.get(swaggerType);
|
||||
if (languageSpecificPrimitives.contains(type))
|
||||
return type;
|
||||
} else
|
||||
type = swaggerType;
|
||||
return type;
|
||||
}
|
||||
}
|
@ -23,4 +23,6 @@ io.swagger.codegen.languages.SwaggerGenerator
|
||||
io.swagger.codegen.languages.SwaggerYamlGenerator
|
||||
io.swagger.codegen.languages.SwiftGenerator
|
||||
io.swagger.codegen.languages.TizenClientCodegen
|
||||
io.swagger.codegen.languages.TypeScriptAngularClientCodegen
|
||||
io.swagger.codegen.languages.TypeScriptNodeClientCodegen
|
||||
io.swagger.codegen.languages.AkkaScalaClientCodegen
|
||||
|
@ -0,0 +1,13 @@
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
/// <reference path="{{{classname}}}.ts" />
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
{{#operations}}
|
||||
/// <reference path="{{classname}}.ts" />
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
@ -0,0 +1,68 @@
|
||||
/// <reference path="api.d.ts" />
|
||||
|
||||
/* tslint:disable:no-unused-variable member-ordering */
|
||||
|
||||
{{#operations}}
|
||||
module {{package}} {
|
||||
'use strict';
|
||||
|
||||
{{#description}}
|
||||
/**
|
||||
* {{&description}}
|
||||
*/
|
||||
{{/description}}
|
||||
export class {{classname}} {
|
||||
private basePath = '{{basePath}}';
|
||||
|
||||
static $inject: string[] = ['$http'];
|
||||
|
||||
constructor(private $http: ng.IHttpService, basePath?: string) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
}
|
||||
{{#operation}}
|
||||
public {{nickname}} ({{#allParams}}{{paramName}}: {{{dataType}}}, {{/allParams}} extraHttpRequestParams?: any ) : ng.IHttpPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> {
|
||||
var path = this.basePath + '{{path}}';
|
||||
{{#pathParams}}
|
||||
path = path.replace('{' + '{{paramName}}' + '}', String({{paramName}}));
|
||||
{{/pathParams}}
|
||||
var queryParameters: any = {};
|
||||
var headerParams: any = {};
|
||||
{{#allParams}}{{#required}}
|
||||
// verify required parameter '{{paramName}}' is set
|
||||
if (!{{paramName}}) {
|
||||
throw new Error('Missing required parameter {{paramName}} when calling {{nickname}}');
|
||||
}
|
||||
{{/required}}{{/allParams}}
|
||||
{{#queryParams}}if ({{paramName}} !== undefined) {
|
||||
queryParameters['{{paramName}}'] = {{paramName}};
|
||||
}{{/queryParams}}
|
||||
{{#headerParams}}headerParams['{{paramName}}'] = {{paramName}};{{/headerParams}}
|
||||
var httpRequestParams: any = {
|
||||
method: '{{httpMethod}}',
|
||||
url: path,
|
||||
json: true,
|
||||
{{#bodyParam}}data: {{paramName}},
|
||||
{{/bodyParam}}
|
||||
params: queryParameters,
|
||||
headers: headerParams
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
|
||||
angular.module('{{package}}_{{classname}}', ['$http'])
|
||||
.service('{{classname}}', {{classname}});
|
||||
}
|
||||
{{/operations}}
|
@ -0,0 +1,39 @@
|
||||
/// <reference path="api.d.ts" />
|
||||
|
||||
module {{package}} {
|
||||
'use strict';
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/description}}
|
||||
export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
|
||||
{{#vars}}
|
||||
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/description}}
|
||||
{{name}}: {{#isEnum}}{{classname}}.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}};
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
{{#hasEnums}}
|
||||
export module {{classname}} {
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
|
||||
export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}}
|
||||
{{.}} = <any> '{{.}}',{{/values}}{{/allowableValues}}
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{/vars}}
|
||||
}
|
||||
{{/hasEnums}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/* tslint:disable:no-unused-variable */
|
||||
|
||||
{{#operations}}
|
||||
{{#description}}
|
||||
/**
|
||||
* {{&description}}
|
||||
*/
|
||||
{{/description}}
|
||||
export class {{classname}} {
|
||||
private basePath = '{{basePath}}';
|
||||
|
||||
constructor(private url: string, private username: string, private password: string, basePath?: string) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
}
|
||||
|
||||
{{#operation}}
|
||||
public {{nickname}} ({{#allParams}}{{paramName}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}} ) : Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }> {
|
||||
var path = this.url + this.basePath + '{{path}}';
|
||||
|
||||
{{#pathParams}}
|
||||
path = path.replace('{' + '{{paramName}}' + '}', String({{paramName}}));
|
||||
{{/pathParams}}
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headerParams: any = {};
|
||||
|
||||
{{#allParams}}{{#required}}
|
||||
// verify required parameter '{{paramName}}' is set
|
||||
if (!{{paramName}}) {
|
||||
throw new Error('Missing required parameter {{paramName}} when calling {{nickname}}');
|
||||
}
|
||||
{{/required}}{{/allParams}}
|
||||
|
||||
{{#queryParams}}if ({{paramName}} !== undefined) {
|
||||
queryParameters['{{paramName}}'] = {{paramName}};
|
||||
}
|
||||
{{/queryParams}}
|
||||
|
||||
{{#headerParams}}headerParams['{{paramName}}'] = {{paramName}};
|
||||
{{/headerParams}}
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }>();
|
||||
|
||||
request({
|
||||
method: '{{httpMethod}}',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
{{#bodyParam}}body: {{paramName}},
|
||||
{{/bodyParam}}
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
@ -0,0 +1,33 @@
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/description}}
|
||||
export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
|
||||
{{#vars}}
|
||||
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/description}}
|
||||
{{name}}: {{#isEnum}}{{classname}}.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}};
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
{{#hasEnums}}
|
||||
export module {{classname}} {
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
|
||||
export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}}
|
||||
{{.}} = <any> '{{.}}',{{/values}}{{/allowableValues}}
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{/vars}}
|
||||
}
|
||||
{{/hasEnums}}
|
||||
{{/model}}
|
||||
{{/models}}
|
@ -0,0 +1,170 @@
|
||||
package typescriptangular
|
||||
|
||||
import io.swagger.codegen.languages.TypeScriptAngularClientCodegen
|
||||
import io.swagger.models._
|
||||
import io.swagger.models.properties._
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest.{FlatSpec, Matchers}
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class TypeScriptAngularModelTest extends FlatSpec with Matchers {
|
||||
|
||||
it should "convert a simple TypeScript Angular model" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("id", new LongProperty())
|
||||
.property("name", new StringProperty())
|
||||
.property("createdAt", new DateTimeProperty())
|
||||
.required("id")
|
||||
.required("name")
|
||||
|
||||
val codegen = new TypeScriptAngularClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("a sample model")
|
||||
cm.vars.size should be(3)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("id")
|
||||
vars.get(0).datatype should be("number")
|
||||
vars.get(0).name should be("id")
|
||||
vars.get(0).defaultValue should be("null")
|
||||
vars.get(0).baseType should be("number")
|
||||
vars.get(0).hasMore should equal(true)
|
||||
vars.get(0).required should equal(true)
|
||||
vars.get(0).isNotContainer should equal(true)
|
||||
|
||||
vars.get(1).baseName should be("name")
|
||||
vars.get(1).datatype should be("string")
|
||||
vars.get(1).name should be("name")
|
||||
vars.get(1).defaultValue should be("null")
|
||||
vars.get(1).baseType should be("string")
|
||||
vars.get(1).hasMore should equal(true)
|
||||
vars.get(1).required should equal(true)
|
||||
vars.get(1).isNotContainer should equal(true)
|
||||
|
||||
vars.get(2).baseName should be("createdAt")
|
||||
vars.get(2).complexType should be("DateTime")
|
||||
vars.get(2).datatype should be("DateTime")
|
||||
vars.get(2).name should be("createdAt")
|
||||
vars.get(2).defaultValue should be("null")
|
||||
vars.get(2).hasMore should equal(null)
|
||||
vars.get(2).required should equal(null)
|
||||
vars.get(2).isNotContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert a model with list property" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("id", new LongProperty())
|
||||
.property("urls", new ArrayProperty()
|
||||
.items(new StringProperty()))
|
||||
.required("id")
|
||||
|
||||
val codegen = new TypeScriptAngularClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("a sample model")
|
||||
cm.vars.size should be(2)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("id")
|
||||
vars.get(0).datatype should be("number")
|
||||
vars.get(0).name should be("id")
|
||||
vars.get(0).defaultValue should be("null")
|
||||
vars.get(0).baseType should be("number")
|
||||
vars.get(0).hasMore should equal(true)
|
||||
vars.get(0).required should equal(true)
|
||||
vars.get(0).isNotContainer should equal(true)
|
||||
|
||||
vars.get(1).baseName should be("urls")
|
||||
vars.get(1).datatype should be("Array<string>")
|
||||
vars.get(1).name should be("urls")
|
||||
vars.get(1).baseType should be("Array")
|
||||
vars.get(1).hasMore should be(null)
|
||||
vars.get(1).required should equal(null)
|
||||
vars.get(1).isContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert a model with complex property" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("children", new RefProperty("#/definitions/Children"))
|
||||
|
||||
val codegen = new TypeScriptAngularClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("a sample model")
|
||||
cm.vars.size should be(1)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("children")
|
||||
vars.get(0).datatype should be("Children")
|
||||
vars.get(0).name should be("children")
|
||||
vars.get(0).baseType should be("Children")
|
||||
vars.get(0).required should equal(null)
|
||||
vars.get(0).isNotContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert a model with complex list property" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("children", new ArrayProperty()
|
||||
.items(new RefProperty("#/definitions/Children")))
|
||||
|
||||
val codegen = new TypeScriptAngularClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("a sample model")
|
||||
cm.vars.size should be(1)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("children")
|
||||
vars.get(0).complexType should be("Children")
|
||||
vars.get(0).datatype should be("Array<Children>")
|
||||
vars.get(0).name should be("children")
|
||||
vars.get(0).baseType should be("Array")
|
||||
vars.get(0).required should equal(null)
|
||||
vars.get(0).isContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert an array model" in {
|
||||
val model = new ArrayModel()
|
||||
.description("an array model")
|
||||
.items(new RefProperty("#/definitions/Children"))
|
||||
val codegen = new TypeScriptAngularClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("an array model")
|
||||
cm.vars.size should be(0)
|
||||
}
|
||||
|
||||
it should "convert an map model" in {
|
||||
val model = new ModelImpl()
|
||||
.description("an map model")
|
||||
.additionalProperties(new RefProperty("#/definitions/Children"))
|
||||
|
||||
val codegen = new TypeScriptAngularClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("an map model")
|
||||
cm.vars.size should be(0)
|
||||
cm.imports.size should be(1)
|
||||
(cm.imports.asScala.toSet & Set("Children")).size should be(1)
|
||||
}
|
||||
}
|
@ -0,0 +1,170 @@
|
||||
package typescriptnode
|
||||
|
||||
import io.swagger.codegen.languages.TypeScriptNodeClientCodegen
|
||||
import io.swagger.models._
|
||||
import io.swagger.models.properties._
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest.{FlatSpec, Matchers}
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class TypeScriptNodeModelTest extends FlatSpec with Matchers {
|
||||
|
||||
it should "convert a simple TypeScript Node model" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("id", new LongProperty())
|
||||
.property("name", new StringProperty())
|
||||
.property("createdAt", new DateTimeProperty())
|
||||
.required("id")
|
||||
.required("name")
|
||||
|
||||
val codegen = new TypeScriptNodeClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("a sample model")
|
||||
cm.vars.size should be(3)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("id")
|
||||
vars.get(0).datatype should be("number")
|
||||
vars.get(0).name should be("id")
|
||||
vars.get(0).defaultValue should be("null")
|
||||
vars.get(0).baseType should be("number")
|
||||
vars.get(0).hasMore should equal(true)
|
||||
vars.get(0).required should equal(true)
|
||||
vars.get(0).isNotContainer should equal(true)
|
||||
|
||||
vars.get(1).baseName should be("name")
|
||||
vars.get(1).datatype should be("string")
|
||||
vars.get(1).name should be("name")
|
||||
vars.get(1).defaultValue should be("null")
|
||||
vars.get(1).baseType should be("string")
|
||||
vars.get(1).hasMore should equal(true)
|
||||
vars.get(1).required should equal(true)
|
||||
vars.get(1).isNotContainer should equal(true)
|
||||
|
||||
vars.get(2).baseName should be("createdAt")
|
||||
vars.get(2).complexType should be("DateTime")
|
||||
vars.get(2).datatype should be("DateTime")
|
||||
vars.get(2).name should be("createdAt")
|
||||
vars.get(2).defaultValue should be("null")
|
||||
vars.get(2).hasMore should equal(null)
|
||||
vars.get(2).required should equal(null)
|
||||
vars.get(2).isNotContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert a model with list property" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("id", new LongProperty())
|
||||
.property("urls", new ArrayProperty()
|
||||
.items(new StringProperty()))
|
||||
.required("id")
|
||||
|
||||
val codegen = new TypeScriptNodeClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("a sample model")
|
||||
cm.vars.size should be(2)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("id")
|
||||
vars.get(0).datatype should be("number")
|
||||
vars.get(0).name should be("id")
|
||||
vars.get(0).defaultValue should be("null")
|
||||
vars.get(0).baseType should be("number")
|
||||
vars.get(0).hasMore should equal(true)
|
||||
vars.get(0).required should equal(true)
|
||||
vars.get(0).isNotContainer should equal(true)
|
||||
|
||||
vars.get(1).baseName should be("urls")
|
||||
vars.get(1).datatype should be("Array<string>")
|
||||
vars.get(1).name should be("urls")
|
||||
vars.get(1).baseType should be("Array")
|
||||
vars.get(1).hasMore should be(null)
|
||||
vars.get(1).required should equal(null)
|
||||
vars.get(1).isContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert a model with complex property" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("children", new RefProperty("#/definitions/Children"))
|
||||
|
||||
val codegen = new TypeScriptNodeClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("a sample model")
|
||||
cm.vars.size should be(1)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("children")
|
||||
vars.get(0).datatype should be("Children")
|
||||
vars.get(0).name should be("children")
|
||||
vars.get(0).baseType should be("Children")
|
||||
vars.get(0).required should equal(null)
|
||||
vars.get(0).isNotContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert a model with complex list property" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("children", new ArrayProperty()
|
||||
.items(new RefProperty("#/definitions/Children")))
|
||||
|
||||
val codegen = new TypeScriptNodeClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("a sample model")
|
||||
cm.vars.size should be(1)
|
||||
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("children")
|
||||
vars.get(0).complexType should be("Children")
|
||||
vars.get(0).datatype should be("Array<Children>")
|
||||
vars.get(0).name should be("children")
|
||||
vars.get(0).baseType should be("Array")
|
||||
vars.get(0).required should equal(null)
|
||||
vars.get(0).isContainer should equal(true)
|
||||
}
|
||||
|
||||
it should "convert an array model" in {
|
||||
val model = new ArrayModel()
|
||||
.description("an array model")
|
||||
.items(new RefProperty("#/definitions/Children"))
|
||||
val codegen = new TypeScriptNodeClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("an array model")
|
||||
cm.vars.size should be(0)
|
||||
}
|
||||
|
||||
it should "convert an map model" in {
|
||||
val model = new ModelImpl()
|
||||
.description("an map model")
|
||||
.additionalProperties(new RefProperty("#/definitions/Children"))
|
||||
|
||||
val codegen = new TypeScriptNodeClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.name should be("sample")
|
||||
cm.classname should be("Sample")
|
||||
cm.description should be("an map model")
|
||||
cm.vars.size should be(0)
|
||||
cm.imports.size should be(1)
|
||||
(cm.imports.asScala.toSet & Set("Children")).size should be(1)
|
||||
}
|
||||
}
|
13
samples/client/petstore/typescript-angular/api/Category.ts
Normal file
13
samples/client/petstore/typescript-angular/api/Category.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/// <reference path="api.d.ts" />
|
||||
|
||||
module api {
|
||||
'use strict';
|
||||
|
||||
export class Category {
|
||||
|
||||
id: number;
|
||||
|
||||
name: string;
|
||||
}
|
||||
|
||||
}
|
32
samples/client/petstore/typescript-angular/api/Order.ts
Normal file
32
samples/client/petstore/typescript-angular/api/Order.ts
Normal file
@ -0,0 +1,32 @@
|
||||
/// <reference path="api.d.ts" />
|
||||
|
||||
module api {
|
||||
'use strict';
|
||||
|
||||
export class Order {
|
||||
|
||||
id: number;
|
||||
|
||||
petId: number;
|
||||
|
||||
quantity: number;
|
||||
|
||||
shipDate: DateTime;
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
*/
|
||||
status: Order.StatusEnum;
|
||||
|
||||
complete: boolean;
|
||||
}
|
||||
|
||||
export module Order {
|
||||
|
||||
export enum StatusEnum {
|
||||
placed = <any> 'placed',
|
||||
approved = <any> 'approved',
|
||||
delivered = <any> 'delivered',
|
||||
}
|
||||
}
|
||||
}
|
32
samples/client/petstore/typescript-angular/api/Pet.ts
Normal file
32
samples/client/petstore/typescript-angular/api/Pet.ts
Normal file
@ -0,0 +1,32 @@
|
||||
/// <reference path="api.d.ts" />
|
||||
|
||||
module api {
|
||||
'use strict';
|
||||
|
||||
export class 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',
|
||||
sold = <any> 'sold',
|
||||
}
|
||||
}
|
||||
}
|
282
samples/client/petstore/typescript-angular/api/PetApi.ts
Normal file
282
samples/client/petstore/typescript-angular/api/PetApi.ts
Normal file
@ -0,0 +1,282 @@
|
||||
/// <reference path="api.d.ts" />
|
||||
|
||||
/* tslint:disable:no-unused-variable member-ordering */
|
||||
|
||||
module api {
|
||||
'use strict';
|
||||
|
||||
|
||||
export class PetApi {
|
||||
private basePath = 'http://petstore.swagger.io/v2';
|
||||
|
||||
static $inject: string[] = ['$http'];
|
||||
|
||||
constructor(private $http: ng.IHttpService, basePath?: string) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
}
|
||||
|
||||
public updatePet (body: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/pet';
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'PUT',
|
||||
url: path,
|
||||
json: true,
|
||||
data: body,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public addPet (body: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/pet';
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'POST',
|
||||
url: path,
|
||||
json: true,
|
||||
data: body,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 headers: any = {};
|
||||
|
||||
if (status !== undefined) {
|
||||
queryParameters['status'] = status;
|
||||
}
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'GET',
|
||||
url: path,
|
||||
json: true,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 headers: any = {};
|
||||
|
||||
if (tags !== undefined) {
|
||||
queryParameters['tags'] = tags;
|
||||
}
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'GET',
|
||||
url: path,
|
||||
json: true,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public getPetById (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise<Pet> {
|
||||
var path = this.basePath + '/pet/{petId}';
|
||||
|
||||
path = path.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
// verify required parameter 'petId' is set
|
||||
if (!petId) {
|
||||
throw new Error('Missing required parameter petId when calling getPetById');
|
||||
}
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'GET',
|
||||
url: path,
|
||||
json: true,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public updatePetWithForm (petId: string, name: string, status: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/pet/{petId}';
|
||||
|
||||
path = path.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
// verify required parameter 'petId' is set
|
||||
if (!petId) {
|
||||
throw new Error('Missing required parameter petId when calling updatePetWithForm');
|
||||
}
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'POST',
|
||||
url: path,
|
||||
json: true,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public deletePet (apiKey: string, petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/pet/{petId}';
|
||||
|
||||
path = path.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
// verify required parameter 'petId' is set
|
||||
if (!petId) {
|
||||
throw new Error('Missing required parameter petId when calling deletePet');
|
||||
}
|
||||
|
||||
|
||||
headerParams['apiKey'] = apiKey;
|
||||
var httpRequestParams: any = {
|
||||
method: 'DELETE',
|
||||
url: path,
|
||||
json: true,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public uploadFile (petId: number, additionalMetadata: string, file: file, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/pet/{petId}/uploadImage';
|
||||
|
||||
path = path.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
// verify required parameter 'petId' is set
|
||||
if (!petId) {
|
||||
throw new Error('Missing required parameter petId when calling uploadFile');
|
||||
}
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'POST',
|
||||
url: path,
|
||||
json: true,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
angular.module('api_PetApi', ['$http'])
|
||||
.service('PetApi', PetApi);
|
||||
}
|
151
samples/client/petstore/typescript-angular/api/StoreApi.ts
Normal file
151
samples/client/petstore/typescript-angular/api/StoreApi.ts
Normal file
@ -0,0 +1,151 @@
|
||||
/// <reference path="api.d.ts" />
|
||||
|
||||
/* tslint:disable:no-unused-variable member-ordering */
|
||||
|
||||
module api {
|
||||
'use strict';
|
||||
|
||||
|
||||
export class StoreApi {
|
||||
private basePath = 'http://petstore.swagger.io/v2';
|
||||
|
||||
static $inject: string[] = ['$http'];
|
||||
|
||||
constructor(private $http: ng.IHttpService, basePath?: string) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
}
|
||||
|
||||
public getInventory ( extraHttpRequestParams?: any ) : ng.IHttpPromise<map<String, number>> {
|
||||
var path = this.basePath + '/store/inventory';
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'GET',
|
||||
url: path,
|
||||
json: true,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public placeOrder (body: Order, extraHttpRequestParams?: any ) : ng.IHttpPromise<Order> {
|
||||
var path = this.basePath + '/store/order';
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'POST',
|
||||
url: path,
|
||||
json: true,
|
||||
data: body,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public getOrderById (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<Order> {
|
||||
var path = this.basePath + '/store/order/{orderId}';
|
||||
|
||||
path = path.replace('{' + 'orderId' + '}', String(orderId));
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
// verify required parameter 'orderId' is set
|
||||
if (!orderId) {
|
||||
throw new Error('Missing required parameter orderId when calling getOrderById');
|
||||
}
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'GET',
|
||||
url: path,
|
||||
json: true,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public deleteOrder (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/store/order/{orderId}';
|
||||
|
||||
path = path.replace('{' + 'orderId' + '}', String(orderId));
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
// verify required parameter 'orderId' is set
|
||||
if (!orderId) {
|
||||
throw new Error('Missing required parameter orderId when calling deleteOrder');
|
||||
}
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'DELETE',
|
||||
url: path,
|
||||
json: true,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
angular.module('api_StoreApi', ['$http'])
|
||||
.service('StoreApi', StoreApi);
|
||||
}
|
13
samples/client/petstore/typescript-angular/api/Tag.ts
Normal file
13
samples/client/petstore/typescript-angular/api/Tag.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/// <reference path="api.d.ts" />
|
||||
|
||||
module api {
|
||||
'use strict';
|
||||
|
||||
export class Tag {
|
||||
|
||||
id: number;
|
||||
|
||||
name: string;
|
||||
}
|
||||
|
||||
}
|
28
samples/client/petstore/typescript-angular/api/User.ts
Normal file
28
samples/client/petstore/typescript-angular/api/User.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/// <reference path="api.d.ts" />
|
||||
|
||||
module api {
|
||||
'use strict';
|
||||
|
||||
export class User {
|
||||
|
||||
id: number;
|
||||
|
||||
username: string;
|
||||
|
||||
firstName: string;
|
||||
|
||||
lastName: string;
|
||||
|
||||
email: string;
|
||||
|
||||
password: string;
|
||||
|
||||
phone: string;
|
||||
|
||||
/**
|
||||
* User Status
|
||||
*/
|
||||
userStatus: number;
|
||||
}
|
||||
|
||||
}
|
277
samples/client/petstore/typescript-angular/api/UserApi.ts
Normal file
277
samples/client/petstore/typescript-angular/api/UserApi.ts
Normal file
@ -0,0 +1,277 @@
|
||||
/// <reference path="api.d.ts" />
|
||||
|
||||
/* tslint:disable:no-unused-variable member-ordering */
|
||||
|
||||
module api {
|
||||
'use strict';
|
||||
|
||||
|
||||
export class UserApi {
|
||||
private basePath = 'http://petstore.swagger.io/v2';
|
||||
|
||||
static $inject: string[] = ['$http'];
|
||||
|
||||
constructor(private $http: ng.IHttpService, basePath?: string) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
}
|
||||
|
||||
public createUser (body: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/user';
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'POST',
|
||||
url: path,
|
||||
json: true,
|
||||
data: body,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public createUsersWithArrayInput (body: Array<User>, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/user/createWithArray';
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'POST',
|
||||
url: path,
|
||||
json: true,
|
||||
data: body,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public createUsersWithListInput (body: Array<User>, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/user/createWithList';
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'POST',
|
||||
url: path,
|
||||
json: true,
|
||||
data: body,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public loginUser (username: string, password: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<string> {
|
||||
var path = this.basePath + '/user/login';
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
if (username !== undefined) {
|
||||
queryParameters['username'] = username;
|
||||
}if (password !== undefined) {
|
||||
queryParameters['password'] = password;
|
||||
}
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'GET',
|
||||
url: path,
|
||||
json: true,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public logoutUser ( extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/user/logout';
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'GET',
|
||||
url: path,
|
||||
json: true,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public getUserByName (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<User> {
|
||||
var path = this.basePath + '/user/{username}';
|
||||
|
||||
path = path.replace('{' + 'username' + '}', String(username));
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
// verify required parameter 'username' is set
|
||||
if (!username) {
|
||||
throw new Error('Missing required parameter username when calling getUserByName');
|
||||
}
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'GET',
|
||||
url: path,
|
||||
json: true,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public updateUser (username: string, body: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/user/{username}';
|
||||
|
||||
path = path.replace('{' + 'username' + '}', String(username));
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
// verify required parameter 'username' is set
|
||||
if (!username) {
|
||||
throw new Error('Missing required parameter username when calling updateUser');
|
||||
}
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'PUT',
|
||||
url: path,
|
||||
json: true,
|
||||
data: body,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
public deleteUser (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
|
||||
var path = this.basePath + '/user/{username}';
|
||||
|
||||
path = path.replace('{' + 'username' + '}', String(username));
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
// verify required parameter 'username' is set
|
||||
if (!username) {
|
||||
throw new Error('Missing required parameter username when calling deleteUser');
|
||||
}
|
||||
|
||||
|
||||
|
||||
var httpRequestParams: any = {
|
||||
method: 'DELETE',
|
||||
url: path,
|
||||
json: true,
|
||||
|
||||
params: queryParameters,
|
||||
headers: headers
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.$http(httpRequestParams);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
angular.module('api_UserApi', ['$http'])
|
||||
.service('UserApi', UserApi);
|
||||
}
|
9
samples/client/petstore/typescript-angular/api/api.d.ts
vendored
Normal file
9
samples/client/petstore/typescript-angular/api/api.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/// <reference path="User.ts" />
|
||||
/// <reference path="Category.ts" />
|
||||
/// <reference path="Pet.ts" />
|
||||
/// <reference path="Tag.ts" />
|
||||
/// <reference path="Order.ts" />
|
||||
|
||||
/// <reference path="UserApi.ts" />
|
||||
/// <reference path="PetApi.ts" />
|
||||
/// <reference path="StoreApi.ts" />
|
378
samples/client/petstore/typescript-node/api/PetApi.ts
Normal file
378
samples/client/petstore/typescript-node/api/PetApi.ts
Normal file
@ -0,0 +1,378 @@
|
||||
/* tslint:disable:no-unused-variable */
|
||||
|
||||
export class PetApi {
|
||||
private basePath = 'http://petstore.swagger.io/v2';
|
||||
|
||||
constructor(private url: string, private username: string, private password: string, basePath?: string) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public updatePet (body: Pet ) : Promise<{ response: http.ClientResponse; }> {
|
||||
var path = this.url + this.basePath + '/pet';
|
||||
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; }>();
|
||||
|
||||
request({
|
||||
method: 'PUT',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
body: body,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public addPet (body: Pet ) : Promise<{ response: http.ClientResponse; }> {
|
||||
var path = this.url + this.basePath + '/pet';
|
||||
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; }>();
|
||||
|
||||
request({
|
||||
method: 'POST',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
body: body,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public findPetsByStatus (status: Array<string> ) : Promise<{ response: http.ClientResponse; body: Array<Pet>; }> {
|
||||
var path = this.url + this.basePath + '/pet/findByStatus';
|
||||
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
if (status !== undefined) {
|
||||
queryParameters['status'] = status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; body: Array<Pet>; }>();
|
||||
|
||||
request({
|
||||
method: 'GET',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public findPetsByTags (tags: Array<string> ) : Promise<{ response: http.ClientResponse; body: Array<Pet>; }> {
|
||||
var path = this.url + this.basePath + '/pet/findByTags';
|
||||
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
if (tags !== undefined) {
|
||||
queryParameters['tags'] = tags;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; body: Array<Pet>; }>();
|
||||
|
||||
request({
|
||||
method: 'GET',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public getPetById (petId: number ) : Promise<{ response: http.ClientResponse; body: Pet; }> {
|
||||
var path = this.url + this.basePath + '/pet/{petId}';
|
||||
|
||||
|
||||
path = path.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
// verify required parameter 'petId' is set
|
||||
if (!petId) {
|
||||
throw new Error('Missing required parameter petId when calling getPetById');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; body: Pet; }>();
|
||||
|
||||
request({
|
||||
method: 'GET',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public updatePetWithForm (petId: string, name: string, status: string ) : Promise<{ response: http.ClientResponse; }> {
|
||||
var path = this.url + this.basePath + '/pet/{petId}';
|
||||
|
||||
|
||||
path = path.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
// verify required parameter 'petId' is set
|
||||
if (!petId) {
|
||||
throw new Error('Missing required parameter petId when calling updatePetWithForm');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; }>();
|
||||
|
||||
request({
|
||||
method: 'POST',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public deletePet (apiKey: string, petId: number ) : Promise<{ response: http.ClientResponse; }> {
|
||||
var path = this.url + this.basePath + '/pet/{petId}';
|
||||
|
||||
|
||||
path = path.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
// verify required parameter 'petId' is set
|
||||
if (!petId) {
|
||||
throw new Error('Missing required parameter petId when calling deletePet');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
headerParams['apiKey'] = apiKey;
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; }>();
|
||||
|
||||
request({
|
||||
method: 'DELETE',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public uploadFile (petId: number, additionalMetadata: string, file: file ) : Promise<{ response: http.ClientResponse; }> {
|
||||
var path = this.url + this.basePath + '/pet/{petId}/uploadImage';
|
||||
|
||||
|
||||
path = path.replace('{' + 'petId' + '}', String(petId));
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
// verify required parameter 'petId' is set
|
||||
if (!petId) {
|
||||
throw new Error('Missing required parameter petId when calling uploadFile');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; }>();
|
||||
|
||||
request({
|
||||
method: 'POST',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
}
|
192
samples/client/petstore/typescript-node/api/StoreApi.ts
Normal file
192
samples/client/petstore/typescript-node/api/StoreApi.ts
Normal file
@ -0,0 +1,192 @@
|
||||
/* tslint:disable:no-unused-variable */
|
||||
|
||||
export class StoreApi {
|
||||
private basePath = 'http://petstore.swagger.io/v2';
|
||||
|
||||
constructor(private url: string, private username: string, private password: string, basePath?: string) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public getInventory ( ) : Promise<{ response: http.ClientResponse; body: map<String, number>; }> {
|
||||
var path = this.url + this.basePath + '/store/inventory';
|
||||
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; body: map<String, number>; }>();
|
||||
|
||||
request({
|
||||
method: 'GET',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public placeOrder (body: Order ) : Promise<{ response: http.ClientResponse; body: Order; }> {
|
||||
var path = this.url + this.basePath + '/store/order';
|
||||
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>();
|
||||
|
||||
request({
|
||||
method: 'POST',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
body: body,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public getOrderById (orderId: string ) : Promise<{ response: http.ClientResponse; body: Order; }> {
|
||||
var path = this.url + this.basePath + '/store/order/{orderId}';
|
||||
|
||||
|
||||
path = path.replace('{' + 'orderId' + '}', String(orderId));
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
// verify required parameter 'orderId' is set
|
||||
if (!orderId) {
|
||||
throw new Error('Missing required parameter orderId when calling getOrderById');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>();
|
||||
|
||||
request({
|
||||
method: 'GET',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public deleteOrder (orderId: string ) : Promise<{ response: http.ClientResponse; }> {
|
||||
var path = this.url + this.basePath + '/store/order/{orderId}';
|
||||
|
||||
|
||||
path = path.replace('{' + 'orderId' + '}', String(orderId));
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
// verify required parameter 'orderId' is set
|
||||
if (!orderId) {
|
||||
throw new Error('Missing required parameter orderId when calling deleteOrder');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; }>();
|
||||
|
||||
request({
|
||||
method: 'DELETE',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
}
|
372
samples/client/petstore/typescript-node/api/UserApi.ts
Normal file
372
samples/client/petstore/typescript-node/api/UserApi.ts
Normal file
@ -0,0 +1,372 @@
|
||||
/* tslint:disable:no-unused-variable */
|
||||
|
||||
export class UserApi {
|
||||
private basePath = 'http://petstore.swagger.io/v2';
|
||||
|
||||
constructor(private url: string, private username: string, private password: string, basePath?: string) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public createUser (body: User ) : Promise<{ response: http.ClientResponse; }> {
|
||||
var path = this.url + this.basePath + '/user';
|
||||
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; }>();
|
||||
|
||||
request({
|
||||
method: 'POST',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
body: body,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public createUsersWithArrayInput (body: Array<User> ) : Promise<{ response: http.ClientResponse; }> {
|
||||
var path = this.url + this.basePath + '/user/createWithArray';
|
||||
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; }>();
|
||||
|
||||
request({
|
||||
method: 'POST',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
body: body,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public createUsersWithListInput (body: Array<User> ) : Promise<{ response: http.ClientResponse; }> {
|
||||
var path = this.url + this.basePath + '/user/createWithList';
|
||||
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; }>();
|
||||
|
||||
request({
|
||||
method: 'POST',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
body: body,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public loginUser (username: string, password: string ) : Promise<{ response: http.ClientResponse; body: string; }> {
|
||||
var path = this.url + this.basePath + '/user/login';
|
||||
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
if (username !== undefined) {
|
||||
queryParameters['username'] = username;
|
||||
}
|
||||
if (password !== undefined) {
|
||||
queryParameters['password'] = password;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; body: string; }>();
|
||||
|
||||
request({
|
||||
method: 'GET',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public logoutUser ( ) : Promise<{ response: http.ClientResponse; }> {
|
||||
var path = this.url + this.basePath + '/user/logout';
|
||||
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; }>();
|
||||
|
||||
request({
|
||||
method: 'GET',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public getUserByName (username: string ) : Promise<{ response: http.ClientResponse; body: User; }> {
|
||||
var path = this.url + this.basePath + '/user/{username}';
|
||||
|
||||
|
||||
path = path.replace('{' + 'username' + '}', String(username));
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
// verify required parameter 'username' is set
|
||||
if (!username) {
|
||||
throw new Error('Missing required parameter username when calling getUserByName');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; body: User; }>();
|
||||
|
||||
request({
|
||||
method: 'GET',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public updateUser (username: string, body: User ) : Promise<{ response: http.ClientResponse; }> {
|
||||
var path = this.url + this.basePath + '/user/{username}';
|
||||
|
||||
|
||||
path = path.replace('{' + 'username' + '}', String(username));
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
// verify required parameter 'username' is set
|
||||
if (!username) {
|
||||
throw new Error('Missing required parameter username when calling updateUser');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; }>();
|
||||
|
||||
request({
|
||||
method: 'PUT',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
body: body,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
public deleteUser (username: string ) : Promise<{ response: http.ClientResponse; }> {
|
||||
var path = this.url + this.basePath + '/user/{username}';
|
||||
|
||||
|
||||
path = path.replace('{' + 'username' + '}', String(username));
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
// verify required parameter 'username' is set
|
||||
if (!username) {
|
||||
throw new Error('Missing required parameter username when calling deleteUser');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; }>();
|
||||
|
||||
request({
|
||||
method: 'DELETE',
|
||||
qs: queryParameters,
|
||||
uri: path,
|
||||
json: true,
|
||||
|
||||
auth: {
|
||||
username: this.username, password: this.password
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
deferred.reject(error);
|
||||
} else {
|
||||
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
||||
deferred.resolve({ response: response, body: body });
|
||||
} else {
|
||||
deferred.reject({ response: response, body: body });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
export class Category {
|
||||
|
||||
id: number;
|
||||
|
||||
name: string;
|
||||
}
|
||||
|
26
samples/client/petstore/typescript-node/model/Order.ts
Normal file
26
samples/client/petstore/typescript-node/model/Order.ts
Normal file
@ -0,0 +1,26 @@
|
||||
export class Order {
|
||||
|
||||
id: number;
|
||||
|
||||
petId: number;
|
||||
|
||||
quantity: number;
|
||||
|
||||
shipDate: DateTime;
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
*/
|
||||
status: Order.StatusEnum;
|
||||
|
||||
complete: boolean;
|
||||
}
|
||||
|
||||
export module Order {
|
||||
|
||||
export enum StatusEnum {
|
||||
placed = <any> 'placed',
|
||||
approved = <any> 'approved',
|
||||
delivered = <any> 'delivered',
|
||||
}
|
||||
}
|
26
samples/client/petstore/typescript-node/model/Pet.ts
Normal file
26
samples/client/petstore/typescript-node/model/Pet.ts
Normal file
@ -0,0 +1,26 @@
|
||||
export class 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',
|
||||
sold = <any> 'sold',
|
||||
}
|
||||
}
|
7
samples/client/petstore/typescript-node/model/Tag.ts
Normal file
7
samples/client/petstore/typescript-node/model/Tag.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export class Tag {
|
||||
|
||||
id: number;
|
||||
|
||||
name: string;
|
||||
}
|
||||
|
22
samples/client/petstore/typescript-node/model/User.ts
Normal file
22
samples/client/petstore/typescript-node/model/User.ts
Normal file
@ -0,0 +1,22 @@
|
||||
export class User {
|
||||
|
||||
id: number;
|
||||
|
||||
username: string;
|
||||
|
||||
firstName: string;
|
||||
|
||||
lastName: string;
|
||||
|
||||
email: string;
|
||||
|
||||
password: string;
|
||||
|
||||
phone: string;
|
||||
|
||||
/**
|
||||
* User Status
|
||||
*/
|
||||
userStatus: number;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user