diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java index ebb9c7312247..636f0157a525 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java @@ -43,7 +43,8 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig { protected String groupId = "io.swagger"; protected String artifactId = "swagger-java-client"; protected String artifactVersion = "1.0.0"; - protected String sourceFolder = "src/main/java"; + protected String projectFolder = "src" + File.separator + "main"; + protected String sourceFolder = projectFolder + File.separator + "java"; protected String localVariablePrefix = ""; protected boolean fullJavaUtil = false; protected String javaUtilPrefix = ""; @@ -51,7 +52,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig { public JavaClientCodegen() { super(); - outputFolder = "generated-code/java"; + outputFolder = "generated-code" + File.separator + "java"; modelTemplateFiles.put("model.mustache", ".java"); apiTemplateFiles.put("api.mustache", ".java"); embeddedTemplateDir = templateDir = "Java"; @@ -209,6 +210,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig { supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle")); supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle")); supportingFiles.add(new SupportingFile("gradle.properties.mustache", "", "gradle.properties")); + supportingFiles.add(new SupportingFile("manifest.mustache", projectFolder, "AndroidManifest.xml")); supportingFiles.add(new SupportingFile("ApiClient.mustache", invokerFolder, "ApiClient.java")); supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java")); diff --git a/modules/swagger-codegen/src/main/resources/Java/manifest.mustache b/modules/swagger-codegen/src/main/resources/Java/manifest.mustache new file mode 100644 index 000000000000..f44bd07d0a0b --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/manifest.mustache @@ -0,0 +1,3 @@ + + + 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 fc787b6437f0..9efea198f360 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache @@ -37,8 +37,7 @@ namespace {{package}} { * {{summary}} * {{notes}} {{#allParams}}* @param {{paramName}} {{description}} - {{/allParams}} - */ + {{/allParams}}*/ public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any ) : ng.IHttpPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { const path = this.basePath + '{{path}}'{{#pathParams}} .replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; 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 266dbaa412f2..c1f311fec196 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache @@ -171,8 +171,7 @@ export class {{classname}} { * {{summary}} * {{notes}} {{#allParams}}* @param {{paramName}} {{description}} - {{/allParams}} - */ + {{/allParams}}*/ public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> { const path = this.url + this.basePath + '{{path}}'{{#pathParams}} .replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; diff --git a/modules/swagger-codegen/src/main/resources/swift/APIs.mustache b/modules/swagger-codegen/src/main/resources/swift/APIs.mustache index dbe41eb9c0a3..5a9f1f7a2781 100644 --- a/modules/swagger-codegen/src/main/resources/swift/APIs.mustache +++ b/modules/swagger-codegen/src/main/resources/swift/APIs.mustache @@ -52,7 +52,7 @@ public class RequestBuilder { } } - public func execute(completion: (response: Response?, erorr: ErrorType?) -> Void) { } + public func execute(completion: (response: Response?, error: ErrorType?) -> Void) { } public func addHeader(name name: String, value: String) -> Self { if !value.isEmpty { diff --git a/modules/swagger-codegen/src/main/resources/swift/AlamofireImplementations.mustache b/modules/swagger-codegen/src/main/resources/swift/AlamofireImplementations.mustache index dbc25584886c..6b4d36f94105 100644 --- a/modules/swagger-codegen/src/main/resources/swift/AlamofireImplementations.mustache +++ b/modules/swagger-codegen/src/main/resources/swift/AlamofireImplementations.mustache @@ -20,7 +20,7 @@ class AlamofireRequestBuilder: RequestBuilder { super.init(method: method, URLString: URLString, parameters: parameters, isBody: isBody) } - override func execute(completion: (response: Response?, erorr: ErrorType?) -> Void) { + override func execute(completion: (response: Response?, error: ErrorType?) -> Void) { let managerId = NSUUID().UUIDString // Create a new manager for each request to customize its request header let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() @@ -60,7 +60,7 @@ class AlamofireRequestBuilder: RequestBuilder { case .Success(let upload, _, _): self.processRequest(upload, managerId, completion) case .Failure(let encodingError): - completion(response: nil, erorr: encodingError) + completion(response: nil, error: encodingError) } } ) @@ -70,7 +70,7 @@ class AlamofireRequestBuilder: RequestBuilder { } - private func processRequest(request: Request, _ managerId: String, _ completion: (response: Response?, erorr: ErrorType?) -> Void) { + private func processRequest(request: Request, _ managerId: String, _ completion: (response: Response?, error: ErrorType?) -> Void) { if let credential = self.credential { request.authenticate(usingCredential: credential) } @@ -79,26 +79,26 @@ class AlamofireRequestBuilder: RequestBuilder { managerStore.removeValueForKey(managerId) if response.result.isFailure { - completion(response: nil, erorr: response.result.error) + completion(response: nil, error: response.result.error) return } if () is T { - completion(response: Response(response: response.response!, body: () as! T), erorr: nil) + completion(response: Response(response: response.response!, body: () as! T), error: nil) return } if let json: AnyObject = response.result.value { let body = Decoders.decode(clazz: T.self, source: json) - completion(response: Response(response: response.response!, body: body), erorr: nil) + completion(response: Response(response: response.response!, body: body), error: nil) return } else if "" is T { // swagger-parser currently doesn't support void, which will be fixed in future swagger-parser release // https://github.com/swagger-api/swagger-parser/pull/34 - completion(response: Response(response: response.response!, body: "" as! T), erorr: nil) + completion(response: Response(response: response.response!, body: "" as! T), error: nil) return } - completion(response: nil, erorr: NSError(domain: "localhost", code: 500, userInfo: ["reason": "unreacheable code"])) + completion(response: nil, error: NSError(domain: "localhost", code: 500, userInfo: ["reason": "unreacheable code"])) } } diff --git a/modules/swagger-codegen/src/main/resources/swift/Models.mustache b/modules/swagger-codegen/src/main/resources/swift/Models.mustache index f6df790ea94e..af8f5c875a78 100644 --- a/modules/swagger-codegen/src/main/resources/swift/Models.mustache +++ b/modules/swagger-codegen/src/main/resources/swift/Models.mustache @@ -118,6 +118,10 @@ class Decoders { fatalError("formatter failed to parse \(sourceString)") } {{#models}}{{#model}} + // Decoder for [{{{classname}}}] + Decoders.addDecoder(clazz: [{{{classname}}}].self) { (source: AnyObject) -> [{{{classname}}}] in + return Decoders.decode(clazz: [{{{classname}}}].self, source: source) + } // Decoder for {{{classname}}} Decoders.addDecoder(clazz: {{{classname}}}.self) { (source: AnyObject) -> {{{classname}}} in let sourceDictionary = source as! [NSObject:AnyObject] diff --git a/samples/client/petstore/java/default/src/main/AndroidManifest.xml b/samples/client/petstore/java/default/src/main/AndroidManifest.xml new file mode 100644 index 000000000000..465dcb520c40 --- /dev/null +++ b/samples/client/petstore/java/default/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + + diff --git a/samples/client/petstore/java/jersey2/src/main/AndroidManifest.xml b/samples/client/petstore/java/jersey2/src/main/AndroidManifest.xml new file mode 100644 index 000000000000..465dcb520c40 --- /dev/null +++ b/samples/client/petstore/java/jersey2/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + + diff --git a/samples/client/petstore/java/okhttp-gson/src/main/AndroidManifest.xml b/samples/client/petstore/java/okhttp-gson/src/main/AndroidManifest.xml new file mode 100644 index 000000000000..465dcb520c40 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + + diff --git a/samples/client/petstore/java/retrofit/src/main/AndroidManifest.xml b/samples/client/petstore/java/retrofit/src/main/AndroidManifest.xml new file mode 100644 index 000000000000..465dcb520c40 --- /dev/null +++ b/samples/client/petstore/java/retrofit/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + + diff --git a/samples/client/petstore/java/retrofit2/.settings/org.eclipse.m2e.core.prefs b/samples/client/petstore/java/retrofit2/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index f897a7f1cb23..000000000000 --- a/samples/client/petstore/java/retrofit2/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/samples/client/petstore/swift/Cartfile b/samples/client/petstore/swift/Cartfile index fbd9346e4680..745e00376a80 100644 --- a/samples/client/petstore/swift/Cartfile +++ b/samples/client/petstore/swift/Cartfile @@ -1,2 +1,2 @@ -github "Alamofire/Alamofire" >= 2.0.0 +github "Alamofire/Alamofire" >= 3.0.0 github "mxcl/PromiseKit" >=1.5.3 diff --git a/samples/client/petstore/swift/PetstoreClient.podspec b/samples/client/petstore/swift/PetstoreClient.podspec index 473b130c40c5..3caf12083de0 100644 --- a/samples/client/petstore/swift/PetstoreClient.podspec +++ b/samples/client/petstore/swift/PetstoreClient.podspec @@ -7,5 +7,5 @@ Pod::Spec.new do |s| s.license = 'Apache License, Version 2.0' s.source_files = 'PetstoreClient/Classes/Swaggers/**/*.swift' s.dependency 'PromiseKit', '~> 2.1' - s.dependency 'Alamofire', '~> 2.0.0' + s.dependency 'Alamofire', '~> 3.0.0' end diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs.swift index 73c923e6486a..96eead0d8dd4 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs.swift @@ -7,8 +7,9 @@ import Foundation public class PetstoreClientAPI { - static let basePath = "http://petstore.swagger.io/v2" - static var credential: NSURLCredential? + public static var basePath = "http://petstore.swagger.io/v2" + public static var credential: NSURLCredential? + public static var customHeaders: [String:String] = [:] static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory() } @@ -41,9 +42,17 @@ public class RequestBuilder { self.URLString = URLString self.parameters = parameters self.isBody = isBody + + addHeaders(PetstoreClientAPI.customHeaders) } - public func execute(completion: (response: Response?, erorr: ErrorType?) -> Void) { } + public func addHeaders(aHeaders:[String:String]) { + for (header, value) in aHeaders { + headers[header] = value + } + } + + public func execute(completion: (response: Response?, error: ErrorType?) -> Void) { } public func addHeader(name name: String, value: String) -> Self { if !value.isEmpty { diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift index 614e70b717ef..ea6c50e2549c 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift @@ -71,20 +71,20 @@ extension PetstoreClientAPI { - OAuth: - type: oauth2 - name: petstore_auth - - examples: [{example=[ { - "tags" : [ { - "id" : 123456789, - "name" : "aeiou" - } ], + - examples: [{contentType=application/json, example=[ { + "photoUrls" : [ "aeiou" ], + "name" : "doggie", "id" : 123456789, "category" : { - "id" : 123456789, - "name" : "aeiou" + "name" : "aeiou", + "id" : 123456789 }, - "status" : "aeiou", - "name" : "doggie", - "photoUrls" : [ "aeiou" ] -} ], contentType=application/json}, {example= + "tags" : [ { + "name" : "aeiou", + "id" : 123456789 + } ], + "status" : "aeiou" +} ]}, {contentType=application/xml, example= 123456 doggie @@ -93,21 +93,21 @@ extension PetstoreClientAPI { string -, contentType=application/xml}] - - examples: [{example=[ { - "tags" : [ { - "id" : 123456789, - "name" : "aeiou" - } ], +}] + - examples: [{contentType=application/json, example=[ { + "photoUrls" : [ "aeiou" ], + "name" : "doggie", "id" : 123456789, "category" : { - "id" : 123456789, - "name" : "aeiou" + "name" : "aeiou", + "id" : 123456789 }, - "status" : "aeiou", - "name" : "doggie", - "photoUrls" : [ "aeiou" ] -} ], contentType=application/json}, {example= + "tags" : [ { + "name" : "aeiou", + "id" : 123456789 + } ], + "status" : "aeiou" +} ]}, {contentType=application/xml, example= 123456 doggie @@ -116,7 +116,7 @@ extension PetstoreClientAPI { string -, contentType=application/xml}] +}] - parameter status: (query) Status values that need to be considered for filter @@ -145,20 +145,20 @@ extension PetstoreClientAPI { - OAuth: - type: oauth2 - name: petstore_auth - - examples: [{example=[ { - "tags" : [ { - "id" : 123456789, - "name" : "aeiou" - } ], + - examples: [{contentType=application/json, example=[ { + "photoUrls" : [ "aeiou" ], + "name" : "doggie", "id" : 123456789, "category" : { - "id" : 123456789, - "name" : "aeiou" + "name" : "aeiou", + "id" : 123456789 }, - "status" : "aeiou", - "name" : "doggie", - "photoUrls" : [ "aeiou" ] -} ], contentType=application/json}, {example= + "tags" : [ { + "name" : "aeiou", + "id" : 123456789 + } ], + "status" : "aeiou" +} ]}, {contentType=application/xml, example= 123456 doggie @@ -167,21 +167,21 @@ extension PetstoreClientAPI { string -, contentType=application/xml}] - - examples: [{example=[ { - "tags" : [ { - "id" : 123456789, - "name" : "aeiou" - } ], +}] + - examples: [{contentType=application/json, example=[ { + "photoUrls" : [ "aeiou" ], + "name" : "doggie", "id" : 123456789, "category" : { - "id" : 123456789, - "name" : "aeiou" + "name" : "aeiou", + "id" : 123456789 }, - "status" : "aeiou", - "name" : "doggie", - "photoUrls" : [ "aeiou" ] -} ], contentType=application/json}, {example= + "tags" : [ { + "name" : "aeiou", + "id" : 123456789 + } ], + "status" : "aeiou" +} ]}, {contentType=application/xml, example= 123456 doggie @@ -190,7 +190,7 @@ extension PetstoreClientAPI { string -, contentType=application/xml}] +}] - parameter tags: (query) Tags to filter by @@ -219,23 +219,20 @@ extension PetstoreClientAPI { - API Key: - type: apiKey api_key - name: api_key - - OAuth: - - type: oauth2 - - name: petstore_auth - - examples: [{example={ - "tags" : [ { - "id" : 123456789, - "name" : "aeiou" - } ], + - examples: [{contentType=application/json, example={ + "photoUrls" : [ "aeiou" ], + "name" : "doggie", "id" : 123456789, "category" : { - "id" : 123456789, - "name" : "aeiou" + "name" : "aeiou", + "id" : 123456789 }, - "status" : "aeiou", - "name" : "doggie", - "photoUrls" : [ "aeiou" ] -}, contentType=application/json}, {example= + "tags" : [ { + "name" : "aeiou", + "id" : 123456789 + } ], + "status" : "aeiou" +}}, {contentType=application/xml, example= 123456 doggie @@ -244,21 +241,21 @@ extension PetstoreClientAPI { string -, contentType=application/xml}] - - examples: [{example={ - "tags" : [ { - "id" : 123456789, - "name" : "aeiou" - } ], +}] + - examples: [{contentType=application/json, example={ + "photoUrls" : [ "aeiou" ], + "name" : "doggie", "id" : 123456789, "category" : { - "id" : 123456789, - "name" : "aeiou" + "name" : "aeiou", + "id" : 123456789 }, - "status" : "aeiou", - "name" : "doggie", - "photoUrls" : [ "aeiou" ] -}, contentType=application/json}, {example= + "tags" : [ { + "name" : "aeiou", + "id" : 123456789 + } ], + "status" : "aeiou" +}}, {contentType=application/xml, example= 123456 doggie @@ -267,7 +264,7 @@ extension PetstoreClientAPI { string -, contentType=application/xml}] +}] - parameter petId: (path) ID of pet that needs to be fetched diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift index 92cedda725e9..c3865cb3cccf 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift @@ -21,12 +21,12 @@ extension PetstoreClientAPI { - API Key: - type: apiKey api_key - name: api_key - - examples: [{example={ + - examples: [{contentType=application/json, example={ "key" : 123 -}, contentType=application/json}, {example=not implemented io.swagger.models.properties.MapProperty@d1e580af, contentType=application/xml}] - - examples: [{example={ +}}, {contentType=application/xml, example=not implemented io.swagger.models.properties.MapProperty@d1e580af}] + - examples: [{contentType=application/json, example={ "key" : 123 -}, contentType=application/json}, {example=not implemented io.swagger.models.properties.MapProperty@d1e580af, contentType=application/xml}] +}}, {contentType=application/xml, example=not implemented io.swagger.models.properties.MapProperty@d1e580af}] - returns: RequestBuilder<[String:Int]> */ @@ -48,36 +48,36 @@ extension PetstoreClientAPI { - POST /store/order - - - examples: [{example={ - "id" : 123456789, + - examples: [{contentType=application/json, example={ "petId" : 123456789, - "complete" : true, - "status" : "aeiou", "quantity" : 123, - "shipDate" : "2015-10-20T06:12:32.347+0000" -}, contentType=application/json}, {example= + "id" : 123456789, + "shipDate" : "2015-11-11T12:31:12.079+0000", + "complete" : true, + "status" : "aeiou" +}}, {contentType=application/xml, example= 123456 123456 0 - 2015-10-19T23:12:32.350Z + 2015-11-11T14:31:12.082Z string true -, contentType=application/xml}] - - examples: [{example={ - "id" : 123456789, +}] + - examples: [{contentType=application/json, example={ "petId" : 123456789, - "complete" : true, - "status" : "aeiou", "quantity" : 123, - "shipDate" : "2015-10-20T06:12:32.347+0000" -}, contentType=application/json}, {example= + "id" : 123456789, + "shipDate" : "2015-11-11T12:31:12.079+0000", + "complete" : true, + "status" : "aeiou" +}}, {contentType=application/xml, example= 123456 123456 0 - 2015-10-19T23:12:32.350Z + 2015-11-11T14:31:12.082Z string true -, contentType=application/xml}] +}] - parameter body: (body) order placed for purchasing the pet @@ -100,36 +100,36 @@ extension PetstoreClientAPI { - GET /store/order/{orderId} - For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - - examples: [{example={ - "id" : 123456789, + - examples: [{contentType=application/json, example={ "petId" : 123456789, - "complete" : true, - "status" : "aeiou", "quantity" : 123, - "shipDate" : "2015-10-20T06:12:32.351+0000" -}, contentType=application/json}, {example= + "id" : 123456789, + "shipDate" : "2015-11-11T12:31:12.083+0000", + "complete" : true, + "status" : "aeiou" +}}, {contentType=application/xml, example= 123456 123456 0 - 2015-10-19T23:12:32.351Z + 2015-11-11T14:31:12.083Z string true -, contentType=application/xml}] - - examples: [{example={ - "id" : 123456789, +}] + - examples: [{contentType=application/json, example={ "petId" : 123456789, - "complete" : true, - "status" : "aeiou", "quantity" : 123, - "shipDate" : "2015-10-20T06:12:32.351+0000" -}, contentType=application/json}, {example= + "id" : 123456789, + "shipDate" : "2015-11-11T12:31:12.083+0000", + "complete" : true, + "status" : "aeiou" +}}, {contentType=application/xml, example= 123456 123456 0 - 2015-10-19T23:12:32.351Z + 2015-11-11T14:31:12.083Z string true -, contentType=application/xml}] +}] - parameter orderId: (path) ID of pet that needs to be fetched diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift index 19cf534cea83..231e7f59228e 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift @@ -84,8 +84,8 @@ extension PetstoreClientAPI { - GET /user/login - - - examples: [{example="aeiou", contentType=application/json}, {example=string, contentType=application/xml}] - - examples: [{example="aeiou", contentType=application/json}, {example=string, contentType=application/xml}] + - examples: [{contentType=application/json, example="aeiou"}, {contentType=application/xml, example=string}] + - examples: [{contentType=application/json, example="aeiou"}, {contentType=application/xml, example=string}] - parameter username: (query) The user name for login - parameter password: (query) The password for login in clear text @@ -134,7 +134,7 @@ extension PetstoreClientAPI { - GET /user/{username} - - - examples: [{example={ + - examples: [{contentType=application/json, example={ "id" : 1, "username" : "johnp", "firstName" : "John", @@ -143,7 +143,7 @@ extension PetstoreClientAPI { "password" : "-secret-", "phone" : "0123456789", "userStatus" : 0 -}, contentType=application/json}] +}}] - parameter username: (path) The name that needs to be fetched. Use user1 for testing. diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift index 21791168ab2f..6b4d36f94105 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift @@ -20,7 +20,7 @@ class AlamofireRequestBuilder: RequestBuilder { super.init(method: method, URLString: URLString, parameters: parameters, isBody: isBody) } - override func execute(completion: (response: Response?, erorr: ErrorType?) -> Void) { + override func execute(completion: (response: Response?, error: ErrorType?) -> Void) { let managerId = NSUUID().UUIDString // Create a new manager for each request to customize its request header let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() @@ -60,7 +60,7 @@ class AlamofireRequestBuilder: RequestBuilder { case .Success(let upload, _, _): self.processRequest(upload, managerId, completion) case .Failure(let encodingError): - completion(response: nil, erorr: encodingError) + completion(response: nil, error: encodingError) } } ) @@ -70,38 +70,35 @@ class AlamofireRequestBuilder: RequestBuilder { } - private func processRequest(request: Request, _ managerId: String, _ completion: (response: Response?, erorr: ErrorType?) -> Void) { + private func processRequest(request: Request, _ managerId: String, _ completion: (response: Response?, error: ErrorType?) -> Void) { if let credential = self.credential { request.authenticate(usingCredential: credential) } - request.responseJSON(options: .AllowFragments) { (req, res, result) in + request.responseJSON(options: .AllowFragments) { response in managerStore.removeValueForKey(managerId) - if result.isFailure { - completion(response: nil, erorr: result.error) + if response.result.isFailure { + completion(response: nil, error: response.result.error) return } if () is T { - let response = Response(response: res!, body: () as! T) - completion(response: response, erorr: nil) + completion(response: Response(response: response.response!, body: () as! T), error: nil) return } - if let json: AnyObject = result.value { + if let json: AnyObject = response.result.value { let body = Decoders.decode(clazz: T.self, source: json) - let response = Response(response: res!, body: body) - completion(response: response, erorr: nil) + completion(response: Response(response: response.response!, body: body), error: nil) return } else if "" is T { // swagger-parser currently doesn't support void, which will be fixed in future swagger-parser release // https://github.com/swagger-api/swagger-parser/pull/34 - let response = Response(response: res!, body: "" as! T) - completion(response: response, erorr: nil) + completion(response: Response(response: response.response!, body: "" as! T), error: nil) return } - completion(response: nil, erorr: NSError(domain: "localhost", code: 500, userInfo: ["reason": "unreacheable code"])) + completion(response: nil, error: NSError(domain: "localhost", code: 500, userInfo: ["reason": "unreacheable code"])) } } @@ -113,4 +110,3 @@ class AlamofireRequestBuilder: RequestBuilder { return httpHeaders } } - diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models.swift index 7ac67ca1b4ad..8266d08a1b2d 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models.swift @@ -118,6 +118,10 @@ class Decoders { fatalError("formatter failed to parse \(sourceString)") } + // Decoder for [User] + Decoders.addDecoder(clazz: [User].self) { (source: AnyObject) -> [User] in + return Decoders.decode(clazz: [User].self, source: source) + } // Decoder for User Decoders.addDecoder(clazz: User.self) { (source: AnyObject) -> User in let sourceDictionary = source as! [NSObject:AnyObject] @@ -134,6 +138,10 @@ class Decoders { } + // Decoder for [Category] + Decoders.addDecoder(clazz: [Category].self) { (source: AnyObject) -> [Category] in + return Decoders.decode(clazz: [Category].self, source: source) + } // Decoder for Category Decoders.addDecoder(clazz: Category.self) { (source: AnyObject) -> Category in let sourceDictionary = source as! [NSObject:AnyObject] @@ -144,6 +152,10 @@ class Decoders { } + // Decoder for [Pet] + Decoders.addDecoder(clazz: [Pet].self) { (source: AnyObject) -> [Pet] in + return Decoders.decode(clazz: [Pet].self, source: source) + } // Decoder for Pet Decoders.addDecoder(clazz: Pet.self) { (source: AnyObject) -> Pet in let sourceDictionary = source as! [NSObject:AnyObject] @@ -158,6 +170,10 @@ class Decoders { } + // Decoder for [Tag] + Decoders.addDecoder(clazz: [Tag].self) { (source: AnyObject) -> [Tag] in + return Decoders.decode(clazz: [Tag].self, source: source) + } // Decoder for Tag Decoders.addDecoder(clazz: Tag.self) { (source: AnyObject) -> Tag in let sourceDictionary = source as! [NSObject:AnyObject] @@ -168,6 +184,10 @@ class Decoders { } + // Decoder for [Order] + Decoders.addDecoder(clazz: [Order].self) { (source: AnyObject) -> [Order] in + return Decoders.decode(clazz: [Order].self, source: source) + } // Decoder for Order Decoders.addDecoder(clazz: Order.self) { (source: AnyObject) -> Order in let sourceDictionary = source as! [NSObject:AnyObject] diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Category.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Category.swift index 1356bd1db989..f542ea676f81 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Category.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Category.swift @@ -14,6 +14,8 @@ public class Category: JSONEncodable { public var name: String? + public init() {} + // MARK: JSONEncodable func encodeToJSON() -> AnyObject { var nillableDictionary = [String:AnyObject?]() diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Order.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Order.swift index 25f7745f3068..f309744da998 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Order.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Order.swift @@ -25,6 +25,8 @@ public class Order: JSONEncodable { public var complete: Bool? + public init() {} + // MARK: JSONEncodable func encodeToJSON() -> AnyObject { var nillableDictionary = [String:AnyObject?]() diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Pet.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Pet.swift index b94e5a7a6de8..b1491df25162 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Pet.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Pet.swift @@ -25,6 +25,8 @@ public class Pet: JSONEncodable { public var status: Status? + public init() {} + // MARK: JSONEncodable func encodeToJSON() -> AnyObject { var nillableDictionary = [String:AnyObject?]() diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Tag.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Tag.swift index b7ab8a3a0cfe..edcd73a7a0c7 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Tag.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/Tag.swift @@ -14,6 +14,8 @@ public class Tag: JSONEncodable { public var name: String? + public init() {} + // MARK: JSONEncodable func encodeToJSON() -> AnyObject { var nillableDictionary = [String:AnyObject?]() diff --git a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/User.swift b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/User.swift index a7592185021d..fa0ad3f50193 100644 --- a/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/User.swift +++ b/samples/client/petstore/swift/PetstoreClient/Classes/Swaggers/Models/User.swift @@ -21,6 +21,8 @@ public class User: JSONEncodable { public var userStatus: Int? + public init() {} + // MARK: JSONEncodable func encodeToJSON() -> AnyObject { var nillableDictionary = [String:AnyObject?]() diff --git a/samples/client/petstore/typescript-angular/API/Client/Category.ts b/samples/client/petstore/typescript-angular/API/Client/Category.ts index 5e0a12f2122a..a802fe4ebdf6 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Category.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Category.ts @@ -3,22 +3,11 @@ namespace API.Client { 'use strict'; - - - export interface Category { - - id?: number; - - name?: string; - } - - - } diff --git a/samples/client/petstore/typescript-angular/API/Client/Order.ts b/samples/client/petstore/typescript-angular/API/Client/Order.ts index 874efb18c7e7..1dd84e6d0adb 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Order.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Order.ts @@ -3,65 +3,30 @@ namespace API.Client { 'use strict'; - - - export interface Order { - - id?: number; - - petId?: number; - - quantity?: number; - - shipDate?: Date; - - /** * Order Status */ - status?: Order.StatusEnum; - - complete?: boolean; - } - export namespace Order { - - - - - - - - - - export enum StatusEnum { placed = 'placed', approved = 'approved', delivered = 'delivered', } - - - - } - - - } diff --git a/samples/client/petstore/typescript-angular/API/Client/Pet.ts b/samples/client/petstore/typescript-angular/API/Client/Pet.ts index bf1560de85cc..60431f69c83b 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Pet.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Pet.ts @@ -3,65 +3,30 @@ namespace API.Client { 'use strict'; - - - export interface Pet { - - id?: number; - - category?: Category; - - name: string; - - photoUrls: Array; - - tags?: Array; - - /** * pet status in the store */ - status?: Pet.StatusEnum; - } - export namespace Pet { - - - - - - - - - - - - export enum StatusEnum { available = 'available', pending = 'pending', sold = 'sold', } - - } - - - } diff --git a/samples/client/petstore/typescript-angular/API/Client/PetApi.ts b/samples/client/petstore/typescript-angular/API/Client/PetApi.ts index 2e936fdddd19..11ef0aa3d5a0 100644 --- a/samples/client/petstore/typescript-angular/API/Client/PetApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/PetApi.ts @@ -2,11 +2,9 @@ /* tslint:disable:no-unused-variable member-ordering */ - namespace API.Client { 'use strict'; - export class PetApi { protected basePath = 'http://petstore.swagger.io/v2'; public defaultHeaders : any = {}; @@ -28,26 +26,16 @@ namespace API.Client { return objA; } - /** * Update an existing pet * * @param body Pet object that needs to be added to the store - */ public updatePet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/pet'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - - - - - - let httpRequestParams: any = { method: 'PUT', url: path, @@ -65,26 +53,16 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Add a new pet to the store * * @param body Pet object that needs to be added to the store - */ public addPet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/pet'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - - - - - - let httpRequestParams: any = { method: 'POST', url: path, @@ -102,31 +80,20 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Finds Pets by status * Multiple status values can be provided with comma seperated strings * @param status Status values that need to be considered for filter - */ public findPetsByStatus (status?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise> { const path = this.basePath + '/pet/findByStatus'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - - - if (status !== undefined) { queryParameters['status'] = status; } - - - - let httpRequestParams: any = { method: 'GET', url: path, @@ -143,31 +110,20 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Finds Pets by tags * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by - */ public findPetsByTags (tags?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise> { const path = this.basePath + '/pet/findByTags'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - - - if (tags !== undefined) { queryParameters['tags'] = tags; } - - - - let httpRequestParams: any = { method: 'GET', url: path, @@ -184,12 +140,10 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Find pet by ID * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions * @param petId ID of pet that needs to be fetched - */ public getPetById (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise { const path = this.basePath + '/pet/{petId}' @@ -197,19 +151,10 @@ namespace API.Client { let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - // verify required parameter 'petId' is set if (!petId) { throw new Error('Missing required parameter petId when calling getPetById'); } - - - - - - let httpRequestParams: any = { method: 'GET', url: path, @@ -226,14 +171,12 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Updates a pet in the store with form data * * @param petId ID of pet that needs to be updated * @param name Updated name of the pet * @param status Updated status of the pet - */ public updatePetWithForm (petId: string, name?: string, status?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/pet/{petId}' @@ -241,35 +184,18 @@ namespace API.Client { let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - // verify required parameter 'petId' is set if (!petId) { throw new Error('Missing required parameter petId when calling updatePetWithForm'); } - - - - - - - - - headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; - - formParams['name'] = name; - formParams['status'] = status; - let httpRequestParams: any = { method: 'POST', url: path, @@ -287,13 +213,11 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Deletes a pet * * @param petId Pet id to delete * @param apiKey - */ public deletePet (petId: number, apiKey?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/pet/{petId}' @@ -301,24 +225,12 @@ namespace API.Client { let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - // verify required parameter 'petId' is set if (!petId) { throw new Error('Missing required parameter petId when calling deletePet'); } - - - - - - headerParams['api_key'] = apiKey; - - - let httpRequestParams: any = { method: 'DELETE', url: path, @@ -335,14 +247,12 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * uploads an image * * @param petId ID of pet to update * @param additionalMetadata Additional data to pass to server * @param file file to upload - */ public uploadFile (petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/pet/{petId}/uploadImage' @@ -350,35 +260,18 @@ namespace API.Client { let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - // verify required parameter 'petId' is set if (!petId) { throw new Error('Missing required parameter petId when calling uploadFile'); } - - - - - - - - - headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; - - formParams['additionalMetadata'] = additionalMetadata; - formParams['file'] = file; - let httpRequestParams: any = { method: 'POST', url: path, @@ -396,7 +289,5 @@ namespace API.Client { return this.$http(httpRequestParams); } - } } - diff --git a/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts b/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts index 492ef6885feb..3d3c445a144f 100644 --- a/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts @@ -2,11 +2,9 @@ /* tslint:disable:no-unused-variable member-ordering */ - namespace API.Client { 'use strict'; - export class StoreApi { protected basePath = 'http://petstore.swagger.io/v2'; public defaultHeaders : any = {}; @@ -28,23 +26,15 @@ namespace API.Client { return objA; } - /** * Returns pet inventories by status * Returns a map of status codes to quantities - */ public getInventory (extraHttpRequestParams?: any ) : ng.IHttpPromise<{ [key: string]: number; }> { const path = this.basePath + '/store/inventory'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - - - - let httpRequestParams: any = { method: 'GET', url: path, @@ -61,26 +51,16 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Place an order for a pet * * @param body order placed for purchasing the pet - */ public placeOrder (body?: Order, extraHttpRequestParams?: any ) : ng.IHttpPromise { const path = this.basePath + '/store/order'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - - - - - - let httpRequestParams: any = { method: 'POST', url: path, @@ -98,12 +78,10 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched - */ public getOrderById (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { const path = this.basePath + '/store/order/{orderId}' @@ -111,19 +89,10 @@ namespace API.Client { let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - // verify required parameter 'orderId' is set if (!orderId) { throw new Error('Missing required parameter orderId when calling getOrderById'); } - - - - - - let httpRequestParams: any = { method: 'GET', url: path, @@ -140,12 +109,10 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Delete purchase order by ID * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted - */ public deleteOrder (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/store/order/{orderId}' @@ -153,19 +120,10 @@ namespace API.Client { let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - // verify required parameter 'orderId' is set if (!orderId) { throw new Error('Missing required parameter orderId when calling deleteOrder'); } - - - - - - let httpRequestParams: any = { method: 'DELETE', url: path, @@ -182,7 +140,5 @@ namespace API.Client { return this.$http(httpRequestParams); } - } } - diff --git a/samples/client/petstore/typescript-angular/API/Client/Tag.ts b/samples/client/petstore/typescript-angular/API/Client/Tag.ts index 66666719d890..1c0284cce485 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Tag.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Tag.ts @@ -3,22 +3,11 @@ namespace API.Client { 'use strict'; - - - export interface Tag { - - id?: number; - - name?: string; - } - - - } diff --git a/samples/client/petstore/typescript-angular/API/Client/User.ts b/samples/client/petstore/typescript-angular/API/Client/User.ts index 69e94835d302..7c2b0b78b0ce 100644 --- a/samples/client/petstore/typescript-angular/API/Client/User.ts +++ b/samples/client/petstore/typescript-angular/API/Client/User.ts @@ -3,50 +3,26 @@ namespace API.Client { 'use strict'; - - - export interface 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-angular/API/Client/UserApi.ts b/samples/client/petstore/typescript-angular/API/Client/UserApi.ts index 036508eb69d8..376bdb8935aa 100644 --- a/samples/client/petstore/typescript-angular/API/Client/UserApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/UserApi.ts @@ -2,11 +2,9 @@ /* tslint:disable:no-unused-variable member-ordering */ - namespace API.Client { 'use strict'; - export class UserApi { protected basePath = 'http://petstore.swagger.io/v2'; public defaultHeaders : any = {}; @@ -28,26 +26,16 @@ namespace API.Client { return objA; } - /** * Create user * This can only be done by the logged in user. * @param body Created user object - */ public createUser (body?: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - - - - - - let httpRequestParams: any = { method: 'POST', url: path, @@ -65,26 +53,16 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Creates list of users with given input array * * @param body List of user object - */ public createUsersWithArrayInput (body?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user/createWithArray'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - - - - - - let httpRequestParams: any = { method: 'POST', url: path, @@ -102,26 +80,16 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Creates list of users with given input array * * @param body List of user object - */ public createUsersWithListInput (body?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user/createWithList'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - - - - - - let httpRequestParams: any = { method: 'POST', url: path, @@ -139,39 +107,25 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Logs user into the system * * @param username The user name for login * @param password The password for login in clear text - */ public loginUser (username?: string, password?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { const path = this.basePath + '/user/login'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - - - - - if (username !== undefined) { queryParameters['username'] = username; } - if (password !== undefined) { queryParameters['password'] = password; } - - - - let httpRequestParams: any = { method: 'GET', url: path, @@ -188,23 +142,15 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Logs out current logged in user session * - */ public logoutUser (extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user/logout'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - - - - let httpRequestParams: any = { method: 'GET', url: path, @@ -221,12 +167,10 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Get user by user name * * @param username The name that needs to be fetched. Use user1 for testing. - */ public getUserByName (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { const path = this.basePath + '/user/{username}' @@ -234,19 +178,10 @@ namespace API.Client { let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - // verify required parameter 'username' is set if (!username) { throw new Error('Missing required parameter username when calling getUserByName'); } - - - - - - let httpRequestParams: any = { method: 'GET', url: path, @@ -263,13 +198,11 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Updated user * This can only be done by the logged in user. * @param username name that need to be deleted * @param body Updated user object - */ public updateUser (username: string, body?: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user/{username}' @@ -277,21 +210,10 @@ namespace API.Client { let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - // verify required parameter 'username' is set if (!username) { throw new Error('Missing required parameter username when calling updateUser'); } - - - - - - - - let httpRequestParams: any = { method: 'PUT', url: path, @@ -309,12 +231,10 @@ namespace API.Client { return this.$http(httpRequestParams); } - /** * Delete user * This can only be done by the logged in user. * @param username The name that needs to be deleted - */ public deleteUser (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user/{username}' @@ -322,19 +242,10 @@ namespace API.Client { let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - // verify required parameter 'username' is set if (!username) { throw new Error('Missing required parameter username when calling deleteUser'); } - - - - - - let httpRequestParams: any = { method: 'DELETE', url: path, @@ -351,7 +262,5 @@ namespace API.Client { return this.$http(httpRequestParams); } - } } - diff --git a/samples/client/petstore/typescript-angular/API/Client/api.d.ts b/samples/client/petstore/typescript-angular/API/Client/api.d.ts index 7a4f79f38b1e..19c60623dc94 100644 --- a/samples/client/petstore/typescript-angular/API/Client/api.d.ts +++ b/samples/client/petstore/typescript-angular/API/Client/api.d.ts @@ -1,37 +1,9 @@ - - /// - - - /// - - - /// - - - /// - - - /// - - - - - /// - - - -/// - - - /// - - - +/// diff --git a/samples/client/petstore/typescript-node/api.ts b/samples/client/petstore/typescript-node/api.ts index 4728b6f8c147..ab5f05b46cbe 100644 --- a/samples/client/petstore/typescript-node/api.ts +++ b/samples/client/petstore/typescript-node/api.ts @@ -8,181 +8,69 @@ import http = require('http'); /* 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 namespace 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 namespace Order { - - - - - - - - - - export enum StatusEnum { placed = 'placed', approved = 'approved', delivered = 'delivered', } - - - - } - - - interface Authentication { /** * Apply authentication settings to header and query params. @@ -229,10 +117,6 @@ class VoidAuth implements Authentication { } } - - - - export class UserApi { protected basePath = 'http://petstore.swagger.io/v2'; protected defaultHeaders : any = {}; @@ -241,34 +125,13 @@ export class UserApi { public authentications = { 'default': new VoidAuth(), - - - - - 'petstore_auth': new OAuth(), - - - - '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; } @@ -279,20 +142,9 @@ export class UserApi { } } - - - - - - - - set apiKey(key: string) { this.authentications.api_key.apiKey = key; } - - - private extendObj(objA: T1, objB: T2) { for(let key in objB){ if(objB.hasOwnProperty(key)){ @@ -301,12 +153,10 @@ export class UserApi { } return objA; } - /** * Create user * This can only be done by the logged in user. * @param body Created user object - */ public createUser (body?: User) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user'; @@ -315,11 +165,8 @@ export class UserApi { let formParams: any = {}; - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -328,12 +175,9 @@ export class UserApi { headers: headerParams, uri: path, json: true, - body: body, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -358,12 +202,10 @@ export class UserApi { return deferred.promise; } - /** * Creates list of users with given input array * * @param body List of user object - */ public createUsersWithArrayInput (body?: Array) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/createWithArray'; @@ -372,11 +214,8 @@ export class UserApi { let formParams: any = {}; - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -385,12 +224,9 @@ export class UserApi { headers: headerParams, uri: path, json: true, - body: body, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -415,12 +251,10 @@ export class UserApi { return deferred.promise; } - /** * Creates list of users with given input array * * @param body List of user object - */ public createUsersWithListInput (body?: Array) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/createWithList'; @@ -429,11 +263,8 @@ export class UserApi { let formParams: any = {}; - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -442,12 +273,9 @@ export class UserApi { headers: headerParams, uri: path, json: true, - body: body, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -472,13 +300,11 @@ export class UserApi { return deferred.promise; } - /** * Logs user into the system * * @param username The user name for login * @param password The password for login in clear text - */ public loginUser (username?: string, password?: string) : Promise<{ response: http.ClientResponse; body: string; }> { const path = this.url + this.basePath + '/user/login'; @@ -487,21 +313,16 @@ export class UserApi { let formParams: any = {}; - if (username !== undefined) { queryParameters['username'] = username; } - if (password !== undefined) { queryParameters['password'] = password; } - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: string; }>(); let requestOptions: request.Options = { @@ -510,10 +331,8 @@ export class UserApi { headers: headerParams, uri: path, json: true, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -538,11 +357,9 @@ export class UserApi { return deferred.promise; } - /** * Logs out current logged in user session * - */ public logoutUser () : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/logout'; @@ -551,11 +368,8 @@ export class UserApi { let formParams: any = {}; - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -564,10 +378,8 @@ export class UserApi { headers: headerParams, uri: path, json: true, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -592,12 +404,10 @@ export class UserApi { return deferred.promise; } - /** * Get user by user name * * @param username The name that needs to be fetched. Use user1 for testing. - */ public getUserByName (username: string) : Promise<{ response: http.ClientResponse; body: User; }> { const path = this.url + this.basePath + '/user/{username}' @@ -612,11 +422,8 @@ export class UserApi { throw new Error('Missing required parameter username when calling getUserByName'); } - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: User; }>(); let requestOptions: request.Options = { @@ -625,10 +432,8 @@ export class UserApi { headers: headerParams, uri: path, json: true, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -653,13 +458,11 @@ export class UserApi { return deferred.promise; } - /** * Updated user * This can only be done by the logged in user. * @param username name that need to be deleted * @param body Updated user object - */ public updateUser (username: string, body?: User) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/{username}' @@ -674,11 +477,8 @@ export class UserApi { throw new Error('Missing required parameter username when calling updateUser'); } - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -687,12 +487,9 @@ export class UserApi { headers: headerParams, uri: path, json: true, - body: body, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -717,12 +514,10 @@ export class UserApi { return deferred.promise; } - /** * Delete user * This can only be done by the logged in user. * @param username The name that needs to be deleted - */ public deleteUser (username: string) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/{username}' @@ -737,11 +532,8 @@ export class UserApi { throw new Error('Missing required parameter username when calling deleteUser'); } - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -750,10 +542,8 @@ export class UserApi { headers: headerParams, uri: path, json: true, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -778,322 +568,7 @@ export class UserApi { return deferred.promise; } - } - - - - -export class StoreApi { - protected basePath = 'http://petstore.swagger.io/v2'; - protected defaultHeaders : any = {}; - - - - public authentications = { - 'default': new VoidAuth(), - - - - - 'petstore_auth': new OAuth(), - - - - - 'api_key': new ApiKeyAuth('header', 'api_key'), - - - - } - - 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; - } - - - - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - objA[key] = objB[key]; - } - } - return objA; - } - - /** - * Returns pet inventories by status - * Returns a map of status codes to quantities - - */ - public getInventory () : Promise<{ response: http.ClientResponse; body: { [key: string]: number; }; }> { - const path = this.url + this.basePath + '/store/inventory'; - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - - - let useFormData = false; - - - let deferred = promise.defer<{ response: http.ClientResponse; body: { [key: string]: number; }; }>(); - - let 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; - } - - /** - * Place an order for a pet - * - * @param body order placed for purchasing the pet - - */ - public placeOrder (body?: Order) : Promise<{ response: http.ClientResponse; body: Order; }> { - const path = this.url + this.basePath + '/store/order'; - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - - - let useFormData = false; - - - let deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); - - let 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; - } - - /** - * Find purchase order by ID - * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - * @param orderId ID of pet that needs to be fetched - - */ - public getOrderById (orderId: string) : Promise<{ response: http.ClientResponse; body: Order; }> { - const path = this.url + this.basePath + '/store/order/{orderId}' - .replace('{' + 'orderId' + '}', String(orderId)); - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - // verify required parameter 'orderId' is set - if (!orderId) { - throw new Error('Missing required parameter orderId when calling getOrderById'); - } - - - - let useFormData = false; - - - let deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); - - let 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; - } - - /** - * Delete purchase order by ID - * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - * @param orderId ID of the order that needs to be deleted - - */ - public deleteOrder (orderId: string) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.url + this.basePath + '/store/order/{orderId}' - .replace('{' + 'orderId' + '}', String(orderId)); - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - // verify required parameter 'orderId' is set - if (!orderId) { - throw new Error('Missing required parameter orderId when calling deleteOrder'); - } - - - - let useFormData = false; - - - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); - - let 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 { protected basePath = 'http://petstore.swagger.io/v2'; protected defaultHeaders : any = {}; @@ -1102,34 +577,13 @@ export class PetApi { public authentications = { 'default': new VoidAuth(), - - - - - 'petstore_auth': new OAuth(), - - - - '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; } @@ -1140,20 +594,9 @@ export class PetApi { } } - - - - - - - - set apiKey(key: string) { this.authentications.api_key.apiKey = key; } - - - private extendObj(objA: T1, objB: T2) { for(let key in objB){ if(objB.hasOwnProperty(key)){ @@ -1162,12 +605,10 @@ export class PetApi { } return objA; } - /** * Update an existing pet * * @param body Pet object that needs to be added to the store - */ public updatePet (body?: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/pet'; @@ -1176,11 +617,8 @@ export class PetApi { let formParams: any = {}; - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -1189,15 +627,11 @@ export class PetApi { headers: headerParams, uri: path, json: true, - body: body, - } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1222,12 +656,10 @@ export class PetApi { return deferred.promise; } - /** * Add a new pet to the store * * @param body Pet object that needs to be added to the store - */ public addPet (body?: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/pet'; @@ -1236,11 +668,8 @@ export class PetApi { let formParams: any = {}; - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -1249,15 +678,11 @@ export class PetApi { headers: headerParams, uri: path, json: true, - body: body, - } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1282,12 +707,10 @@ export class PetApi { return deferred.promise; } - /** * Finds Pets by status * Multiple status values can be provided with comma seperated strings * @param status Status values that need to be considered for filter - */ public findPetsByStatus (status?: Array) : Promise<{ response: http.ClientResponse; body: Array; }> { const path = this.url + this.basePath + '/pet/findByStatus'; @@ -1296,16 +719,12 @@ export class PetApi { let formParams: any = {}; - if (status !== undefined) { queryParameters['status'] = status; } - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); let requestOptions: request.Options = { @@ -1314,13 +733,10 @@ export class PetApi { headers: headerParams, uri: path, json: true, - } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1345,12 +761,10 @@ export class PetApi { return deferred.promise; } - /** * Finds Pets by tags * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by - */ public findPetsByTags (tags?: Array) : Promise<{ response: http.ClientResponse; body: Array; }> { const path = this.url + this.basePath + '/pet/findByTags'; @@ -1359,16 +773,12 @@ export class PetApi { let formParams: any = {}; - if (tags !== undefined) { queryParameters['tags'] = tags; } - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); let requestOptions: request.Options = { @@ -1377,13 +787,10 @@ export class PetApi { headers: headerParams, uri: path, json: true, - } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1408,12 +815,10 @@ export class PetApi { return deferred.promise; } - /** * Find pet by ID * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions * @param petId ID of pet that needs to be fetched - */ public getPetById (petId: number) : Promise<{ response: http.ClientResponse; body: Pet; }> { const path = this.url + this.basePath + '/pet/{petId}' @@ -1428,11 +833,8 @@ export class PetApi { throw new Error('Missing required parameter petId when calling getPetById'); } - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: Pet; }>(); let requestOptions: request.Options = { @@ -1441,13 +843,10 @@ export class PetApi { headers: headerParams, uri: path, json: true, - } - this.authentications.api_key.applyToRequest(requestOptions); - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1472,14 +871,12 @@ export class PetApi { return deferred.promise; } - /** * Updates a pet in the store with form data * * @param petId ID of pet that needs to be updated * @param name Updated name of the pet * @param status Updated status of the pet - */ public updatePetWithForm (petId: string, name?: string, status?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/pet/{petId}' @@ -1494,23 +891,16 @@ export class PetApi { throw new Error('Missing required parameter petId when calling updatePetWithForm'); } - - let useFormData = false; - if (name !== undefined) { formParams['name'] = name; } - - if (status !== undefined) { formParams['status'] = status; } - - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -1519,13 +909,10 @@ export class PetApi { headers: headerParams, uri: path, json: true, - } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1550,13 +937,11 @@ export class PetApi { return deferred.promise; } - /** * Deletes a pet * * @param petId Pet id to delete * @param apiKey - */ public deletePet (petId: number, apiKey?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/pet/{petId}' @@ -1571,14 +956,10 @@ export class PetApi { throw new Error('Missing required parameter petId when calling deletePet'); } - - headerParams['api_key'] = apiKey; - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -1587,13 +968,10 @@ export class PetApi { headers: headerParams, uri: path, json: true, - } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1618,14 +996,12 @@ export class PetApi { return deferred.promise; } - /** * uploads an image * * @param petId ID of pet to update * @param additionalMetadata Additional data to pass to server * @param file file to upload - */ public uploadFile (petId: number, additionalMetadata?: string, file?: any) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/pet/{petId}/uploadImage' @@ -1640,25 +1016,17 @@ export class PetApi { throw new Error('Missing required parameter petId when calling uploadFile'); } - - let useFormData = false; - if (additionalMetadata !== undefined) { formParams['additionalMetadata'] = additionalMetadata; } - - if (file !== undefined) { formParams['file'] = file; } - useFormData = true; - - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -1667,13 +1035,10 @@ export class PetApi { headers: headerParams, uri: path, json: true, - } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1698,8 +1063,247 @@ export class PetApi { return deferred.promise; } - } +export class StoreApi { + protected basePath = 'http://petstore.swagger.io/v2'; + protected defaultHeaders : any = {}; + 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; + } + private extendObj(objA: T1, objB: T2) { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + */ + public getInventory () : Promise<{ response: http.ClientResponse; body: { [key: string]: number; }; }> { + const path = this.url + this.basePath + '/store/inventory'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + let useFormData = false; + + let deferred = promise.defer<{ response: http.ClientResponse; body: { [key: string]: number; }; }>(); + + let 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; + } + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + */ + public placeOrder (body?: Order) : Promise<{ response: http.ClientResponse; body: Order; }> { + const path = this.url + this.basePath + '/store/order'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + let useFormData = false; + + let deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); + + let 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; + } + /** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param orderId ID of pet that needs to be fetched + */ + public getOrderById (orderId: string) : Promise<{ response: http.ClientResponse; body: Order; }> { + const path = this.url + this.basePath + '/store/order/{orderId}' + .replace('{' + 'orderId' + '}', String(orderId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + // verify required parameter 'orderId' is set + if (!orderId) { + throw new Error('Missing required parameter orderId when calling getOrderById'); + } + + let useFormData = false; + + let deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); + + let 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; + } + /** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param orderId ID of the order that needs to be deleted + */ + public deleteOrder (orderId: string) : Promise<{ response: http.ClientResponse; body?: any; }> { + const path = this.url + this.basePath + '/store/order/{orderId}' + .replace('{' + 'orderId' + '}', String(orderId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + // verify required parameter 'orderId' is set + if (!orderId) { + throw new Error('Missing required parameter orderId when calling deleteOrder'); + } + + let useFormData = false; + + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + + let 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; + } +}