diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index bc4f08d7f55..c44e070fe62 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -600,7 +600,7 @@ public class DefaultCodegen { public CodegenProperty fromProperty(String name, Property p) { if (p == null) { - LOGGER.error("unexpected missing property for name " + null); + LOGGER.error("unexpected missing property for name " + name); return null; } CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java new file mode 100644 index 00000000000..883ad66ff7f --- /dev/null +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java @@ -0,0 +1,143 @@ +package io.swagger.codegen.languages; + +import io.swagger.codegen.*; +import io.swagger.models.properties.*; + +import java.util.*; +import java.io.File; + +public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen implements CodegenConfig { + @Override + public CodegenType getTag() { + return CodegenType.CLIENT; + } + + public AbstractTypeScriptClientCodegen() { + super(); + reservedWords = new HashSet(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")); + + languageSpecificPrimitives = new HashSet(Arrays.asList( + "String", + "boolean", + "Boolean", + "Double", + "Integer", + "Long", + "Float", + "Object")); + instantiationTypes.put("array", "Array"); + + typeMapping = new HashMap(); + 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"); + typeMapping.put("Map", "any"); + typeMapping.put("DateTime", "Date"); + + } + + @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 "{ [key: string]: "+ getTypeDeclaration(inner) + "; }"; + } else if (p instanceof FileProperty) { + return "any"; + } + 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; + } +} diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java index 11cae0de0ef..8eec2b8772e 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java @@ -1,25 +1,28 @@ package io.swagger.codegen.languages; -import java.io.File; - import io.swagger.codegen.SupportingFile; -public class TypeScriptAngularClientCodegen extends TypeScriptNodeClientCodegen { +import java.io.File; + +public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCodegen { @Override public String getName() { return "typescript-angular"; } - + + public String getHelp() { + return "Generates a TypeScript AngurlarJS client library."; + } + public TypeScriptAngularClientCodegen() { super(); outputFolder = "generated-code/typescript-angular"; modelTemplateFiles.put("model.mustache", ".ts"); apiTemplateFiles.put("api.mustache", ".ts"); templateDir = "TypeScript-Angular"; - apiPackage = "api"; - modelPackage = "model"; - - supportingFiles.add(new SupportingFile("api.d.mustache", apiPackage + File.separator, "api.d.ts")); + apiPackage = "API.Client"; + modelPackage = "API.Client"; + supportingFiles.add(new SupportingFile("api.d.mustache", apiPackage().replace('.', File.separatorChar), "api.d.ts")); } } \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptNodeClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptNodeClientCodegen.java index 0ea33f21709..b92598b1fb6 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptNodeClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptNodeClientCodegen.java @@ -1,171 +1,24 @@ package io.swagger.codegen.languages; -import io.swagger.codegen.*; -import io.swagger.models.properties.*; +import io.swagger.codegen.SupportingFile; -import java.util.*; -import java.io.File; +public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen { -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 String getName() { + return "typescript-node"; + } - @Override - public CodegenType getTag() { - return CodegenType.CLIENT; - } + @Override + public String getHelp() { + return "Generates a TypeScript nodejs client library."; + } - @Override - public String getName() { - return "typescript-node"; - } + public TypeScriptNodeClientCodegen() { + super(); + outputFolder = "generated-code/typescript-node"; + templateDir = "TypeScript-node"; + supportingFiles.add(new SupportingFile("api.mustache", null, "api.ts")); + } - @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(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(Arrays.asList( - "String", - "boolean", - "Boolean", - "Double", - "Integer", - "Long", - "Float", - "Object")); - instantiationTypes.put("array", "Array"); - - typeMapping = new HashMap(); - 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"); - typeMapping.put("Map", "any"); - typeMapping.put("DateTime", "Date"); - - } - - @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) + ""; - } - 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; - } } diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache index bd5eaaef87a..427d847663b 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache @@ -6,11 +6,11 @@ module {{package}} { 'use strict'; - {{#description}} +{{#description}} /** * {{&description}} */ - {{/description}} +{{/description}} export class {{classname}} { private basePath = '{{contextPath}}'; @@ -21,24 +21,37 @@ module {{package}} { this.basePath = basePath; } } - {{#operation}} +{{#operation}} + public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any ) : ng.IHttpPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { var path = this.basePath + '{{path}}'; - {{#pathParams}} + +{{#pathParams}} path = path.replace('{' + '{{paramName}}' + '}', String({{paramName}})); - {{/pathParams}} + +{{/pathParams}} var queryParameters: any = {}; var headerParams: any = {}; - {{#allParams}}{{#required}} + +{{#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) { + +{{/required}} +{{/allParams}} +{{#queryParams}} + if ({{paramName}} !== undefined) { queryParameters['{{paramName}}'] = {{paramName}}; - }{{/queryParams}} - {{#headerParams}}headerParams['{{paramName}}'] = {{paramName}};{{/headerParams}} + } + +{{/queryParams}} +{{#headerParams}} + headerParams['{{paramName}}'] = {{paramName}}; + +{{/headerParams}} var httpRequestParams: any = { method: '{{httpMethod}}', url: path, @@ -59,7 +72,7 @@ module {{package}} { return this.$http(httpRequestParams); } - {{/operation}} +{{/operation}} } } {{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache index debeed69515..f8d4577ee7a 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache @@ -1,73 +1,245 @@ +import request = require('request'); +import promise = require('bluebird'); +import http = require('http'); + +// =============================================== +// This file is autogenerated - Please do not edit +// =============================================== + /* tslint:disable:no-unused-variable */ -{{#operations}} +{{#models}} +{{#model}} +{{#description}} +/** +* {{{description}}} +*/ +{{/description}} +export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ +{{#vars}} {{#description}} /** - * {{&description}} + * {{{description}}} */ +{{/description}} + {{name}}: {{#isEnum}}{{classname}}.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; +{{/vars}} +} + +{{#hasEnums}} +export module {{classname}} { +{{#vars}} +{{#isEnum}} + export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}} + {{.}} = '{{.}}',{{/values}}{{/allowableValues}} + } +{{/isEnum}} +{{/vars}} +} +{{/hasEnums}} +{{/model}} +{{/models}} + +interface Authentication { + /** + * Apply authentication settings to header and query params. + */ + applyToRequest(requestOptions: request.Options): void; +} + +class HttpBasicAuth implements Authentication { + public username: string; + public password: string; + applyToRequest(requestOptions: request.Options): void { + requestOptions.auth = { + username: this.username, password: this.password + } + } +} + +class ApiKeyAuth implements Authentication { + public apiKey: string; + + constructor(private location: string, private paramName: string) { + } + + applyToRequest(requestOptions: request.Options): void { + if (this.location == "query") { + (requestOptions.qs)[this.paramName] = this.apiKey; + } else if (this.location == "header") { + requestOptions.headers[this.paramName] = this.apiKey; + } + } +} + +class OAuth implements Authentication { + applyToRequest(requestOptions: request.Options): void { + // TODO: support oauth + } +} + +class VoidAuth implements Authentication { + public username: string; + public password: string; + applyToRequest(requestOptions: request.Options): void { + // Do nothing + } +} + +{{#apiInfo}} +{{#apis}} +{{#operations}} +{{#description}} +/** +* {{&description}} +*/ {{/description}} export class {{classname}} { private basePath = '{{contextPath}}'; - - constructor(private url: string, private username: string, private password: string, basePath?: string) { - if (basePath) { - this.basePath = basePath; - } + public authentications = { + 'default': new VoidAuth(), +{{#authMethods}} +{{#isBasic}} + '{{name}}': new HttpBasicAuth(), +{{/isBasic}} +{{#isApiKey}} + '{{name}}': new ApiKeyAuth({{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{^isKeyInHeader}}'query'{{/isKeyInHeader}}, '{{keyParamName}}'), +{{/isApiKey}} +{{#isOAuth}} + '{{name}}': new OAuth(), +{{/isOAuth}} +{{/authMethods}} } - {{#operation}} - public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{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 }); + constructor(url: string, basePath?: string); +{{#authMethods}} +{{#isBasic}} + constructor(url: string, username: string, password: string, basePath?: string); +{{/isBasic}} +{{/authMethods}} + constructor(private url: string, basePathOrUsername: string, password?: string, basePath?: string) { + if (password) { +{{#authMethods}} +{{#isBasic}} + this.username = basePathOrUsername; + this.password = password +{{/isBasic}} +{{/authMethods}} + if (basePath) { + this.basePath = basePath; + } } else { - deferred.reject({ response: response, body: body }); + if (basePathOrUsername) { + this.basePath = basePathOrUsername + } } - } - }); + } +{{#authMethods}} +{{#isBasic}} - return deferred.promise; - } + set username(username: string) { + this.authentications.{{name}}.username = username; + } - {{/operation}} + set password(password: string) { + this.authentications.{{name}}.password = password; + } +{{/isBasic}} +{{#isApiKey}} + + set apiKey(key: string) { + this.authentications.{{name}}.apiKey = key; + } +{{/isApiKey}} +{{#isOAuth}} +{{/isOAuth}} +{{/authMethods}} +{{#operation}} + + public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{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 = {}; + var formParams: 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 useFormData = false; + +{{#formParams}} + if ({{paramName}} !== undefined) { + formParams['{{paramName}}'] = {{paramName}}; + } +{{#isFile}} + useFormData = true; +{{/isFile}} + +{{/formParams}} + var deferred = promise.defer<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }>(); + + var requestOptions: request.Options = { + method: '{{httpMethod}}', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, +{{#bodyParam}} + body: {{paramName}}, +{{/bodyParam}} + } + +{{#authMethods}} + this.authentications.{{name}}.applyToRequest(requestOptions); + +{{/authMethods}} + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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}} +{{/apis}} +{{/apiInfo}} diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-node/model.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-node/model.mustache deleted file mode 100644 index 55c8997e1bc..00000000000 --- a/modules/swagger-codegen/src/main/resources/TypeScript-node/model.mustache +++ /dev/null @@ -1,33 +0,0 @@ -{{#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}} - {{.}} = '{{.}}',{{/values}}{{/allowableValues}} - } -{{/isEnum}} -{{/vars}} -} -{{/hasEnums}} -{{/model}} -{{/models}} diff --git a/samples/client/petstore/typescript-angular/.gitignore b/samples/client/petstore/typescript-angular/.gitignore new file mode 100644 index 00000000000..abfad1bf5e2 --- /dev/null +++ b/samples/client/petstore/typescript-angular/.gitignore @@ -0,0 +1,3 @@ +/node_modules +/typings +/client.js \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular/api/Category.ts b/samples/client/petstore/typescript-angular/API/Client/Category.ts similarity index 87% rename from samples/client/petstore/typescript-angular/api/Category.ts rename to samples/client/petstore/typescript-angular/API/Client/Category.ts index e4a3caa208e..7faf87208eb 100644 --- a/samples/client/petstore/typescript-angular/api/Category.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Category.ts @@ -1,6 +1,6 @@ /// -module api { +module API.Client { 'use strict'; export class Category { diff --git a/samples/client/petstore/typescript-angular/api/Order.ts b/samples/client/petstore/typescript-angular/API/Client/Order.ts similarity index 91% rename from samples/client/petstore/typescript-angular/api/Order.ts rename to samples/client/petstore/typescript-angular/API/Client/Order.ts index 3f37c608758..abee3a2894b 100644 --- a/samples/client/petstore/typescript-angular/api/Order.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Order.ts @@ -1,6 +1,6 @@ /// -module api { +module API.Client { 'use strict'; export class Order { @@ -11,7 +11,7 @@ module api { quantity: number; - shipDate: DateTime; + shipDate: Date; /** * Order Status diff --git a/samples/client/petstore/typescript-angular/api/Pet.ts b/samples/client/petstore/typescript-angular/API/Client/Pet.ts similarity index 96% rename from samples/client/petstore/typescript-angular/api/Pet.ts rename to samples/client/petstore/typescript-angular/API/Client/Pet.ts index c34be9c3dbc..9523bef90b0 100644 --- a/samples/client/petstore/typescript-angular/api/Pet.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Pet.ts @@ -1,6 +1,6 @@ /// -module api { +module API.Client { 'use strict'; export class Pet { diff --git a/samples/client/petstore/typescript-angular/api/PetApi.ts b/samples/client/petstore/typescript-angular/API/Client/PetApi.ts similarity index 74% rename from samples/client/petstore/typescript-angular/api/PetApi.ts rename to samples/client/petstore/typescript-angular/API/Client/PetApi.ts index d294cfbebbc..6bb4e10d387 100644 --- a/samples/client/petstore/typescript-angular/api/PetApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/PetApi.ts @@ -2,12 +2,11 @@ /* tslint:disable:no-unused-variable member-ordering */ -module api { +module API.Client { 'use strict'; - export class PetApi { - private basePath = 'http://petstore.swagger.io/v2'; + private basePath = '/v2'; static $inject: string[] = ['$http']; @@ -16,15 +15,13 @@ module api { this.basePath = basePath; } } - - public updatePet (body: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { + + public updatePet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { var path = this.basePath + '/pet'; - + var queryParameters: any = {}; - var headers: any = {}; - - - + var headerParams: any = {}; + var httpRequestParams: any = { method: 'PUT', url: path, @@ -32,11 +29,11 @@ module api { data: body, params: queryParameters, - headers: headers + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -45,15 +42,13 @@ module api { return this.$http(httpRequestParams); } - - public addPet (body: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { + + public addPet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { var path = this.basePath + '/pet'; - + var queryParameters: any = {}; - var headers: any = {}; - - - + var headerParams: any = {}; + var httpRequestParams: any = { method: 'POST', url: path, @@ -61,11 +56,11 @@ module api { data: body, params: queryParameters, - headers: headers + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -74,28 +69,28 @@ module api { return this.$http(httpRequestParams); } - - public findPetsByStatus (status: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise> { + + public findPetsByStatus (status?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise> { var path = this.basePath + '/pet/findByStatus'; - + var queryParameters: any = {}; - var headers: any = {}; - + var headerParams: any = {}; + if (status !== undefined) { queryParameters['status'] = status; } - + var httpRequestParams: any = { method: 'GET', url: path, json: true, params: queryParameters, - headers: headers + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -104,28 +99,28 @@ module api { return this.$http(httpRequestParams); } - - public findPetsByTags (tags: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise> { + + public findPetsByTags (tags?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise> { var path = this.basePath + '/pet/findByTags'; - + var queryParameters: any = {}; - var headers: any = {}; - + var headerParams: any = {}; + if (tags !== undefined) { queryParameters['tags'] = tags; } - + var httpRequestParams: any = { method: 'GET', url: path, json: true, params: queryParameters, - headers: headers + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -134,33 +129,31 @@ module api { return this.$http(httpRequestParams); } - - public getPetById (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise { + + public getPetById (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise { var path = this.basePath + '/pet/{petId}'; - + path = path.replace('{' + 'petId' + '}', String(petId)); - + var queryParameters: any = {}; - var headers: 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 = { method: 'GET', url: path, json: true, params: queryParameters, - headers: headers + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -169,33 +162,31 @@ module api { return this.$http(httpRequestParams); } - - public updatePetWithForm (petId: string, name: string, status: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { + + 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 = {}; - + var headerParams: 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 + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -204,33 +195,33 @@ module api { return this.$http(httpRequestParams); } - - public deletePet (apiKey: string, petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { + + public deletePet (petId: number, apiKey?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { var path = this.basePath + '/pet/{petId}'; - + path = path.replace('{' + 'petId' + '}', String(petId)); - + var queryParameters: any = {}; - var headers: any = {}; - + var headerParams: 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 + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -239,33 +230,31 @@ module api { return this.$http(httpRequestParams); } - - public uploadFile (petId: number, additionalMetadata: string, file: file, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { + + public uploadFile (petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { var path = this.basePath + '/pet/{petId}/uploadImage'; - + path = path.replace('{' + 'petId' + '}', String(petId)); - + var queryParameters: any = {}; - var headers: any = {}; - + var headerParams: 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 + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -274,9 +263,5 @@ module api { return this.$http(httpRequestParams); } - } - - angular.module('api_PetApi', ['$http']) - .service('PetApi', PetApi); } diff --git a/samples/client/petstore/typescript-angular/api/StoreApi.ts b/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts similarity index 72% rename from samples/client/petstore/typescript-angular/api/StoreApi.ts rename to samples/client/petstore/typescript-angular/API/Client/StoreApi.ts index e8c85b00c45..948b6859381 100644 --- a/samples/client/petstore/typescript-angular/api/StoreApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts @@ -2,12 +2,11 @@ /* tslint:disable:no-unused-variable member-ordering */ -module api { +module API.Client { 'use strict'; - export class StoreApi { - private basePath = 'http://petstore.swagger.io/v2'; + private basePath = '/v2'; static $inject: string[] = ['$http']; @@ -16,26 +15,24 @@ module api { this.basePath = basePath; } } - - public getInventory ( extraHttpRequestParams?: any ) : ng.IHttpPromise> { + + public getInventory (extraHttpRequestParams?: any ) : ng.IHttpPromise<{ [key: string]: number; }> { var path = this.basePath + '/store/inventory'; - + var queryParameters: any = {}; - var headers: any = {}; - - - + var headerParams: any = {}; + var httpRequestParams: any = { method: 'GET', url: path, json: true, params: queryParameters, - headers: headers + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -44,15 +41,13 @@ module api { return this.$http(httpRequestParams); } - - public placeOrder (body: Order, extraHttpRequestParams?: any ) : ng.IHttpPromise { + + public placeOrder (body?: Order, extraHttpRequestParams?: any ) : ng.IHttpPromise { var path = this.basePath + '/store/order'; - + var queryParameters: any = {}; - var headers: any = {}; - - - + var headerParams: any = {}; + var httpRequestParams: any = { method: 'POST', url: path, @@ -60,11 +55,11 @@ module api { data: body, params: queryParameters, - headers: headers + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -73,33 +68,31 @@ module api { return this.$http(httpRequestParams); } - - public getOrderById (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { + + public getOrderById (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 = {}; - + var headerParams: 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 + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -108,33 +101,31 @@ module api { return this.$http(httpRequestParams); } - - public deleteOrder (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { + + 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 = {}; - + var headerParams: 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 + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -143,9 +134,5 @@ module api { return this.$http(httpRequestParams); } - } - - angular.module('api_StoreApi', ['$http']) - .service('StoreApi', StoreApi); } diff --git a/samples/client/petstore/typescript-angular/api/Tag.ts b/samples/client/petstore/typescript-angular/API/Client/Tag.ts similarity index 86% rename from samples/client/petstore/typescript-angular/api/Tag.ts rename to samples/client/petstore/typescript-angular/API/Client/Tag.ts index 33f0ffaa1e2..2ec9b456f27 100644 --- a/samples/client/petstore/typescript-angular/api/Tag.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Tag.ts @@ -1,6 +1,6 @@ /// -module api { +module API.Client { 'use strict'; export class Tag { diff --git a/samples/client/petstore/typescript-angular/api/User.ts b/samples/client/petstore/typescript-angular/API/Client/User.ts similarity index 94% rename from samples/client/petstore/typescript-angular/api/User.ts rename to samples/client/petstore/typescript-angular/API/Client/User.ts index 57385044943..ca8ac57c7a3 100644 --- a/samples/client/petstore/typescript-angular/api/User.ts +++ b/samples/client/petstore/typescript-angular/API/Client/User.ts @@ -1,6 +1,6 @@ /// -module api { +module API.Client { 'use strict'; export class User { diff --git a/samples/client/petstore/typescript-angular/api/UserApi.ts b/samples/client/petstore/typescript-angular/API/Client/UserApi.ts similarity index 73% rename from samples/client/petstore/typescript-angular/api/UserApi.ts rename to samples/client/petstore/typescript-angular/API/Client/UserApi.ts index 40d82f73852..eb04f4b31f0 100644 --- a/samples/client/petstore/typescript-angular/api/UserApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/UserApi.ts @@ -2,12 +2,11 @@ /* tslint:disable:no-unused-variable member-ordering */ -module api { +module API.Client { 'use strict'; - export class UserApi { - private basePath = 'http://petstore.swagger.io/v2'; + private basePath = '/v2'; static $inject: string[] = ['$http']; @@ -16,15 +15,13 @@ module api { this.basePath = basePath; } } - - public createUser (body: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { + + public createUser (body?: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { var path = this.basePath + '/user'; - + var queryParameters: any = {}; - var headers: any = {}; - - - + var headerParams: any = {}; + var httpRequestParams: any = { method: 'POST', url: path, @@ -32,11 +29,11 @@ module api { data: body, params: queryParameters, - headers: headers + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -45,15 +42,13 @@ module api { return this.$http(httpRequestParams); } - - public createUsersWithArrayInput (body: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { + + public createUsersWithArrayInput (body?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { var path = this.basePath + '/user/createWithArray'; - + var queryParameters: any = {}; - var headers: any = {}; - - - + var headerParams: any = {}; + var httpRequestParams: any = { method: 'POST', url: path, @@ -61,11 +56,11 @@ module api { data: body, params: queryParameters, - headers: headers + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -74,15 +69,13 @@ module api { return this.$http(httpRequestParams); } - - public createUsersWithListInput (body: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { + + public createUsersWithListInput (body?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { var path = this.basePath + '/user/createWithList'; - + var queryParameters: any = {}; - var headers: any = {}; - - - + var headerParams: any = {}; + var httpRequestParams: any = { method: 'POST', url: path, @@ -90,11 +83,11 @@ module api { data: body, params: queryParameters, - headers: headers + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -103,30 +96,32 @@ module api { return this.$http(httpRequestParams); } - - public loginUser (username: string, password: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { + + public loginUser (username?: string, password?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { var path = this.basePath + '/user/login'; - + var queryParameters: any = {}; - var headers: any = {}; - + var headerParams: any = {}; + if (username !== undefined) { queryParameters['username'] = username; - }if (password !== undefined) { + } + + if (password !== undefined) { queryParameters['password'] = password; } - + var httpRequestParams: any = { method: 'GET', url: path, json: true, params: queryParameters, - headers: headers + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -135,26 +130,24 @@ module api { return this.$http(httpRequestParams); } - - public logoutUser ( extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { + + public logoutUser (extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { var path = this.basePath + '/user/logout'; - + var queryParameters: any = {}; - var headers: any = {}; - - - + var headerParams: any = {}; + var httpRequestParams: any = { method: 'GET', url: path, json: true, params: queryParameters, - headers: headers + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -163,33 +156,31 @@ module api { return this.$http(httpRequestParams); } - - public getUserByName (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { + + public getUserByName (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { var path = this.basePath + '/user/{username}'; - + path = path.replace('{' + 'username' + '}', String(username)); - + var queryParameters: any = {}; - var headers: any = {}; - + var headerParams: 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 + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -198,22 +189,20 @@ module api { return this.$http(httpRequestParams); } - - public updateUser (username: string, body: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { + + 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 = {}; - + var headerParams: 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, @@ -221,11 +210,11 @@ module api { data: body, params: queryParameters, - headers: headers + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -234,33 +223,31 @@ module api { return this.$http(httpRequestParams); } - - public deleteUser (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { + + 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 = {}; - + var headerParams: 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 + headers: headerParams }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams){ + for (var k in extraHttpRequestParams) { if (extraHttpRequestParams.hasOwnProperty(k)) { httpRequestParams[k] = extraHttpRequestParams[k]; } @@ -269,9 +256,5 @@ module api { return this.$http(httpRequestParams); } - } - - angular.module('api_UserApi', ['$http']) - .service('UserApi', UserApi); } diff --git a/samples/client/petstore/typescript-angular/api/api.d.ts b/samples/client/petstore/typescript-angular/API/Client/api.d.ts similarity index 100% rename from samples/client/petstore/typescript-angular/api/api.d.ts rename to samples/client/petstore/typescript-angular/API/Client/api.d.ts diff --git a/samples/client/petstore/typescript-angular/README.md b/samples/client/petstore/typescript-angular/README.md new file mode 100644 index 00000000000..3a4e49be9e8 --- /dev/null +++ b/samples/client/petstore/typescript-angular/README.md @@ -0,0 +1,19 @@ +# SwaggerClient + +Sample of TypeScript AngularJS petstore client + +## Testing the generated code + +``` +npm install +npm test +``` + +To clean the workspace run: +``` +npm run clean +``` + +## Author + +mads@maetzke-tandrup.dk \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular/package.json b/samples/client/petstore/typescript-angular/package.json new file mode 100644 index 00000000000..f50b782c09f --- /dev/null +++ b/samples/client/petstore/typescript-angular/package.json @@ -0,0 +1,20 @@ +{ + "name": "petstore-typescript-node-sample", + "version": "1.0.0", + "description": "Sample of generated TypeScript petstore client", + "main": "api.js", + "scripts": { + "postinstall": "tsd reinstall --overwrite", + "test": "tsc", + "clean": "rm -Rf node_modules/ typings/ *.js" + }, + "author": "Mads M. Tandrup", + "license": "Apache 2.0", + "dependencies": { + "angular": "^1.4.3" + }, + "devDependencies": { + "tsd": "^0.6.3", + "typescript": "^1.5.3" + } +} diff --git a/samples/client/petstore/typescript-angular/tsconfig.json b/samples/client/petstore/typescript-angular/tsconfig.json new file mode 100644 index 00000000000..c389d5011ff --- /dev/null +++ b/samples/client/petstore/typescript-angular/tsconfig.json @@ -0,0 +1,18 @@ +{ + "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" + ] +} diff --git a/samples/client/petstore/typescript-angular/tsd.json b/samples/client/petstore/typescript-angular/tsd.json new file mode 100644 index 00000000000..182b9f68fa2 --- /dev/null +++ b/samples/client/petstore/typescript-angular/tsd.json @@ -0,0 +1,15 @@ +{ + "version": "v4", + "repo": "borisyankov/DefinitelyTyped", + "ref": "master", + "path": "typings", + "bundle": "typings/tsd.d.ts", + "installed": { + "angularjs/angular.d.ts": { + "commit": "f6c8ca47193fb67947944a3170912672ac3e908e" + }, + "jquery/jquery.d.ts": { + "commit": "f6c8ca47193fb67947944a3170912672ac3e908e" + } + } +} diff --git a/samples/client/petstore/typescript-node/.gitignore b/samples/client/petstore/typescript-node/.gitignore new file mode 100644 index 00000000000..5c06ad7bc24 --- /dev/null +++ b/samples/client/petstore/typescript-node/.gitignore @@ -0,0 +1,3 @@ +/node_modules +/typings +/*.js diff --git a/samples/client/petstore/typescript-node/README.md b/samples/client/petstore/typescript-node/README.md new file mode 100644 index 00000000000..82225d3260a --- /dev/null +++ b/samples/client/petstore/typescript-node/README.md @@ -0,0 +1,22 @@ +# SwaggerClient + +Sample of TypeScript Node.js petstore client + +## Testing the generated code + +``` +npm install +npm test +``` + +This will compile the code and run a small test application that will do some simple test calls to the Swagger Petstore API. + +To clean the workspace run: +``` +npm run clean +``` + + +## Author + +mads@maetzke-tandrup.dk \ No newline at end of file diff --git a/samples/client/petstore/typescript-node/api.ts b/samples/client/petstore/typescript-node/api.ts new file mode 100644 index 00000000000..0b7089fdaae --- /dev/null +++ b/samples/client/petstore/typescript-node/api.ts @@ -0,0 +1,1199 @@ +import request = require('request'); +import promise = require('bluebird'); +import http = require('http'); + +// =============================================== +// This file is autogenerated - Please do not edit +// =============================================== + +/* tslint:disable:no-unused-variable */ + +export class User { + id: number; + username: string; + firstName: string; + lastName: string; + email: string; + password: string; + phone: string; + /** + * User Status + */ + userStatus: number; +} + +export class Category { + id: number; + name: string; +} + +export class Pet { + id: number; + category: Category; + name: string; + photoUrls: Array; + tags: Array; + /** + * pet status in the store + */ + status: Pet.StatusEnum; +} + +export module Pet { + export enum StatusEnum { + available = 'available', + pending = 'pending', + sold = 'sold', + } +} +export class Tag { + id: number; + name: string; +} + +export class Order { + id: number; + petId: number; + quantity: number; + shipDate: Date; + /** + * Order Status + */ + status: Order.StatusEnum; + complete: boolean; +} + +export module Order { + export enum StatusEnum { + placed = 'placed', + approved = 'approved', + delivered = 'delivered', + } +} + +interface Authentication { + /** + * Apply authentication settings to header and query params. + */ + applyToRequest(requestOptions: request.Options): void; +} + +class HttpBasicAuth implements Authentication { + public username: string; + public password: string; + applyToRequest(requestOptions: request.Options): void { + requestOptions.auth = { + username: this.username, password: this.password + } + } +} + +class ApiKeyAuth implements Authentication { + public apiKey: string; + + constructor(private location: string, private paramName: string) { + } + + applyToRequest(requestOptions: request.Options): void { + if (this.location == "query") { + (requestOptions.qs)[this.paramName] = this.apiKey; + } else if (this.location == "header") { + requestOptions.headers[this.paramName] = this.apiKey; + } + } +} + +class OAuth implements Authentication { + applyToRequest(requestOptions: request.Options): void { + // TODO: support oauth + } +} + +class VoidAuth implements Authentication { + public username: string; + public password: string; + applyToRequest(requestOptions: request.Options): void { + // Do nothing + } +} + +export class UserApi { + private basePath = '/v2'; + public authentications = { + 'default': new VoidAuth(), + 'api_key': new ApiKeyAuth('header', 'api_key'), + 'petstore_auth': new OAuth(), + } + + constructor(url: string, basePath?: string); + constructor(private url: string, basePathOrUsername: string, password?: string, basePath?: string) { + if (password) { + if (basePath) { + this.basePath = basePath; + } + } else { + if (basePathOrUsername) { + this.basePath = basePathOrUsername + } + } + } + + set apiKey(key: string) { + this.authentications.api_key.apiKey = key; + } + + public createUser (body?: User) : Promise<{ response: http.ClientResponse; }> { + var path = this.url + this.basePath + '/user'; + + var queryParameters: any = {}; + var headerParams: any = {}; + var formParams: any = {}; + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + var requestOptions: request.Options = { + method: 'POST', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + body: body, + } + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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) : Promise<{ response: http.ClientResponse; }> { + var path = this.url + this.basePath + '/user/createWithArray'; + + var queryParameters: any = {}; + var headerParams: any = {}; + var formParams: any = {}; + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + var requestOptions: request.Options = { + method: 'POST', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + body: body, + } + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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) : Promise<{ response: http.ClientResponse; }> { + var path = this.url + this.basePath + '/user/createWithList'; + + var queryParameters: any = {}; + var headerParams: any = {}; + var formParams: any = {}; + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + var requestOptions: request.Options = { + method: 'POST', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + body: body, + } + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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 headerParams: any = {}; + var formParams: any = {}; + + if (username !== undefined) { + queryParameters['username'] = username; + } + + if (password !== undefined) { + queryParameters['password'] = password; + } + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; body: string; }>(); + + var requestOptions: request.Options = { + method: 'GET', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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 headerParams: any = {}; + var formParams: any = {}; + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + var requestOptions: request.Options = { + method: 'GET', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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 headerParams: any = {}; + var formParams: any = {}; + + // verify required parameter 'username' is set + if (!username) { + throw new Error('Missing required parameter username when calling getUserByName'); + } + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; body: User; }>(); + + var requestOptions: request.Options = { + method: 'GET', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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 headerParams: any = {}; + var formParams: any = {}; + + // verify required parameter 'username' is set + if (!username) { + throw new Error('Missing required parameter username when calling updateUser'); + } + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + var requestOptions: request.Options = { + method: 'PUT', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + body: body, + } + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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 headerParams: any = {}; + var formParams: any = {}; + + // verify required parameter 'username' is set + if (!username) { + throw new Error('Missing required parameter username when calling deleteUser'); + } + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + var requestOptions: request.Options = { + method: 'DELETE', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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; + } +} +export class PetApi { + private basePath = '/v2'; + public authentications = { + 'default': new VoidAuth(), + 'api_key': new ApiKeyAuth('header', 'api_key'), + 'petstore_auth': new OAuth(), + } + + constructor(url: string, basePath?: string); + constructor(private url: string, basePathOrUsername: string, password?: string, basePath?: string) { + if (password) { + if (basePath) { + this.basePath = basePath; + } + } else { + if (basePathOrUsername) { + this.basePath = basePathOrUsername + } + } + } + + set apiKey(key: string) { + this.authentications.api_key.apiKey = key; + } + + public updatePet (body?: Pet) : Promise<{ response: http.ClientResponse; }> { + var path = this.url + this.basePath + '/pet'; + + var queryParameters: any = {}; + var headerParams: any = {}; + var formParams: any = {}; + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + var requestOptions: request.Options = { + method: 'PUT', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + body: body, + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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 headerParams: any = {}; + var formParams: any = {}; + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + var requestOptions: request.Options = { + method: 'POST', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + body: body, + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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) : Promise<{ response: http.ClientResponse; body: Array; }> { + var path = this.url + this.basePath + '/pet/findByStatus'; + + var queryParameters: any = {}; + var headerParams: any = {}; + var formParams: any = {}; + + if (status !== undefined) { + queryParameters['status'] = status; + } + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); + + var requestOptions: request.Options = { + method: 'GET', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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) : Promise<{ response: http.ClientResponse; body: Array; }> { + var path = this.url + this.basePath + '/pet/findByTags'; + + var queryParameters: any = {}; + var headerParams: any = {}; + var formParams: any = {}; + + if (tags !== undefined) { + queryParameters['tags'] = tags; + } + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); + + var requestOptions: request.Options = { + method: 'GET', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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 headerParams: any = {}; + var formParams: any = {}; + + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling getPetById'); + } + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; body: Pet; }>(); + + var requestOptions: request.Options = { + method: 'GET', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.api_key.applyToRequest(requestOptions); + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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 headerParams: any = {}; + var formParams: any = {}; + + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling updatePetWithForm'); + } + + var useFormData = false; + + if (name !== undefined) { + formParams['name'] = name; + } + + if (status !== undefined) { + formParams['status'] = status; + } + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + var requestOptions: request.Options = { + method: 'POST', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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 (petId: number, apiKey?: string) : Promise<{ response: http.ClientResponse; }> { + var path = this.url + this.basePath + '/pet/{petId}'; + + 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 deletePet'); + } + + headerParams['apiKey'] = apiKey; + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + var requestOptions: request.Options = { + method: 'DELETE', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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?: any) : Promise<{ response: http.ClientResponse; }> { + var path = this.url + this.basePath + '/pet/{petId}/uploadImage'; + + 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'); + } + + var useFormData = false; + + if (additionalMetadata !== undefined) { + formParams['additionalMetadata'] = additionalMetadata; + } + + if (file !== undefined) { + formParams['file'] = file; + } + useFormData = true; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + var requestOptions: request.Options = { + method: 'POST', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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; + } +} +export class StoreApi { + private basePath = '/v2'; + public authentications = { + 'default': new VoidAuth(), + 'api_key': new ApiKeyAuth('header', 'api_key'), + 'petstore_auth': new OAuth(), + } + + constructor(url: string, basePath?: string); + constructor(private url: string, basePathOrUsername: string, password?: string, basePath?: string) { + if (password) { + if (basePath) { + this.basePath = basePath; + } + } else { + if (basePathOrUsername) { + this.basePath = basePathOrUsername + } + } + } + + set apiKey(key: string) { + this.authentications.api_key.apiKey = key; + } + + public getInventory () : Promise<{ response: http.ClientResponse; body: { [key: string]: number; }; }> { + var path = this.url + this.basePath + '/store/inventory'; + + var queryParameters: any = {}; + var headerParams: any = {}; + var formParams: any = {}; + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; body: { [key: string]: number; }; }>(); + + var requestOptions: request.Options = { + method: 'GET', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.api_key.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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 headerParams: any = {}; + var formParams: any = {}; + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); + + var requestOptions: request.Options = { + method: 'POST', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + body: body, + } + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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 headerParams: any = {}; + var formParams: any = {}; + + // verify required parameter 'orderId' is set + if (!orderId) { + throw new Error('Missing required parameter orderId when calling getOrderById'); + } + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); + + var requestOptions: request.Options = { + method: 'GET', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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 headerParams: any = {}; + var formParams: any = {}; + + // verify required parameter 'orderId' is set + if (!orderId) { + throw new Error('Missing required parameter orderId when calling deleteOrder'); + } + + var useFormData = false; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + var requestOptions: request.Options = { + method: 'DELETE', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (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; + } +} diff --git a/samples/client/petstore/typescript-node/api/PetApi.ts b/samples/client/petstore/typescript-node/api/PetApi.ts deleted file mode 100644 index 02605f2c8a8..00000000000 --- a/samples/client/petstore/typescript-node/api/PetApi.ts +++ /dev/null @@ -1,378 +0,0 @@ -/* 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 ) : Promise<{ response: http.ClientResponse; body: Array; }> { - 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; }>(); - - 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 ) : Promise<{ response: http.ClientResponse; body: Array; }> { - 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; }>(); - - 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; - } - - -} diff --git a/samples/client/petstore/typescript-node/api/StoreApi.ts b/samples/client/petstore/typescript-node/api/StoreApi.ts deleted file mode 100644 index 71cfe106fca..00000000000 --- a/samples/client/petstore/typescript-node/api/StoreApi.ts +++ /dev/null @@ -1,192 +0,0 @@ -/* 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; }> { - var path = this.url + this.basePath + '/store/inventory'; - - - - var queryParameters: any = {}; - var headers: any = {}; - - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; body: map; }>(); - - 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; - } - - -} diff --git a/samples/client/petstore/typescript-node/api/UserApi.ts b/samples/client/petstore/typescript-node/api/UserApi.ts deleted file mode 100644 index ca6fd41c593..00000000000 --- a/samples/client/petstore/typescript-node/api/UserApi.ts +++ /dev/null @@ -1,372 +0,0 @@ -/* 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 ) : 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 ) : 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; - } - - -} diff --git a/samples/client/petstore/typescript-node/client.ts b/samples/client/petstore/typescript-node/client.ts new file mode 100644 index 00000000000..111c76f03c7 --- /dev/null +++ b/samples/client/petstore/typescript-node/client.ts @@ -0,0 +1,51 @@ +import api = require('./api'); +import fs = require('fs'); + +var petApi = new api.PetApi('http://petstore.swagger.io'); +petApi.apiKey = 'special-key'; + +var pet = new api.Pet(); +pet.name = 'TypeScriptDoggie'; + +var petId: any; + +var exitCode = 0; + +// Test various API calls to the petstore +petApi.addPet(pet) +.then((res) => { + var newPet = (res.response).body; + petId = (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); +}); diff --git a/samples/client/petstore/typescript-node/model/Category.ts b/samples/client/petstore/typescript-node/model/Category.ts deleted file mode 100644 index fc4b2874e93..00000000000 --- a/samples/client/petstore/typescript-node/model/Category.ts +++ /dev/null @@ -1,7 +0,0 @@ -export class Category { - - id: number; - - name: string; -} - diff --git a/samples/client/petstore/typescript-node/model/Order.ts b/samples/client/petstore/typescript-node/model/Order.ts deleted file mode 100644 index b46ad4570a0..00000000000 --- a/samples/client/petstore/typescript-node/model/Order.ts +++ /dev/null @@ -1,26 +0,0 @@ -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 = 'placed', - approved = 'approved', - delivered = 'delivered', - } -} diff --git a/samples/client/petstore/typescript-node/model/Pet.ts b/samples/client/petstore/typescript-node/model/Pet.ts deleted file mode 100644 index 4a3faa129ed..00000000000 --- a/samples/client/petstore/typescript-node/model/Pet.ts +++ /dev/null @@ -1,26 +0,0 @@ -export class Pet { - - id: number; - - category: Category; - - name: string; - - photoUrls: Array; - - tags: Array; - - /** - * pet status in the store - */ - status: Pet.StatusEnum; -} - -export module Pet { - - export enum StatusEnum { - available = 'available', - pending = 'pending', - sold = 'sold', - } -} diff --git a/samples/client/petstore/typescript-node/model/Tag.ts b/samples/client/petstore/typescript-node/model/Tag.ts deleted file mode 100644 index 6ae0d4ef576..00000000000 --- a/samples/client/petstore/typescript-node/model/Tag.ts +++ /dev/null @@ -1,7 +0,0 @@ -export class Tag { - - id: number; - - name: string; -} - diff --git a/samples/client/petstore/typescript-node/model/User.ts b/samples/client/petstore/typescript-node/model/User.ts deleted file mode 100644 index fee31563d13..00000000000 --- a/samples/client/petstore/typescript-node/model/User.ts +++ /dev/null @@ -1,22 +0,0 @@ -export class User { - - id: number; - - username: string; - - firstName: string; - - lastName: string; - - email: string; - - password: string; - - phone: string; - - /** - * User Status - */ - userStatus: number; -} - diff --git a/samples/client/petstore/typescript-node/package.json b/samples/client/petstore/typescript-node/package.json new file mode 100644 index 00000000000..ee598dcc6c2 --- /dev/null +++ b/samples/client/petstore/typescript-node/package.json @@ -0,0 +1,21 @@ +{ + "name": "petstore-typescript-node-sample", + "version": "1.0.0", + "description": "Sample of generated TypeScript petstore client", + "main": "api.js", + "scripts": { + "postinstall": "tsd reinstall --overwrite", + "test": "tsc && node client.js", + "clean": "rm -Rf node_modules/ typings/ *.js" + }, + "author": "Mads M. Tandrup", + "license": "Apache 2.0", + "dependencies": { + "bluebird": "^2.9.34", + "request": "^2.60.0" + }, + "devDependencies": { + "tsd": "^0.6.3", + "typescript": "^1.5.3" + } +} diff --git a/samples/client/petstore/typescript-node/sample.png b/samples/client/petstore/typescript-node/sample.png new file mode 100644 index 00000000000..c5916f28970 Binary files /dev/null and b/samples/client/petstore/typescript-node/sample.png differ diff --git a/samples/client/petstore/typescript-node/tsconfig.json b/samples/client/petstore/typescript-node/tsconfig.json new file mode 100644 index 00000000000..572228f6356 --- /dev/null +++ b/samples/client/petstore/typescript-node/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "module": "commonjs", + "noImplicitAny": true, + "target": "ES5" + }, + "files": [ + "api.ts", + "client.ts", + "typings/tsd.d.ts" + ] +} diff --git a/samples/client/petstore/typescript-node/tsd.json b/samples/client/petstore/typescript-node/tsd.json new file mode 100644 index 00000000000..89e4861f949 --- /dev/null +++ b/samples/client/petstore/typescript-node/tsd.json @@ -0,0 +1,21 @@ +{ + "version": "v4", + "repo": "borisyankov/DefinitelyTyped", + "ref": "master", + "path": "typings", + "bundle": "typings/tsd.d.ts", + "installed": { + "bluebird/bluebird.d.ts": { + "commit": "f6c8ca47193fb67947944a3170912672ac3e908e" + }, + "request/request.d.ts": { + "commit": "f6c8ca47193fb67947944a3170912672ac3e908e" + }, + "form-data/form-data.d.ts": { + "commit": "f6c8ca47193fb67947944a3170912672ac3e908e" + }, + "node/node.d.ts": { + "commit": "f6c8ca47193fb67947944a3170912672ac3e908e" + } + } +}