diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java index 1bd02c68d5d..d9f4f1f3aae 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java @@ -14,7 +14,7 @@ public class CodegenOperation { public Boolean hasAuthMethods, hasConsumes, hasProduces, hasParams, hasOptionalParams, returnTypeIsPrimitive, returnSimpleType, subresourceOperation, isMapContainer, isListContainer, isMultipart, hasMore = Boolean.TRUE, - isResponseBinary = Boolean.FALSE, hasReference = Boolean.FALSE, + isResponseBinary = Boolean.FALSE, isResponseFile = Boolean.FALSE, hasReference = Boolean.FALSE, isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy, isRestful; public String path, operationId, returnType, httpMethod, returnBaseType, @@ -215,6 +215,8 @@ public boolean equals(Object o) { return false; if (isResponseBinary != null ? !isResponseBinary.equals(that.isResponseBinary) : that.isResponseBinary != null) return false; + if (isResponseFile != null ? !isResponseFile.equals(that.isResponseFile) : that.isResponseFile != null) + return false; if (hasReference != null ? !hasReference.equals(that.hasReference) : that.hasReference != null) return false; if (path != null ? !path.equals(that.path) : that.path != null) @@ -297,6 +299,7 @@ public int hashCode() { result = 31 * result + (isMultipart != null ? isMultipart.hashCode() : 0); result = 31 * result + (hasMore != null ? hasMore.hashCode() : 0); result = 31 * result + (isResponseBinary != null ? isResponseBinary.hashCode() : 0); + result = 31 * result + (isResponseFile != null ? isResponseFile.hashCode() : 0); result = 31 * result + (hasReference != null ? hasReference.hashCode() : 0); result = 31 * result + (path != null ? path.hashCode() : 0); result = 31 * result + (operationId != null ? operationId.hashCode() : 0); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java index b6a4b9d02da..b92966a9237 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java @@ -35,7 +35,7 @@ public class CodegenProperty implements Cloneable { public Boolean hasMore, required, secondaryParam; public Boolean hasMoreNonReadOnly; // for model constructor, true if next properyt is not readonly public Boolean isPrimitiveType, isContainer, isNotContainer; - public Boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime; + public Boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isFile, isBoolean, isDate, isDateTime; public Boolean isListContainer, isMapContainer; public boolean isEnum; public Boolean isReadOnly = false; @@ -106,6 +106,7 @@ public int hashCode() result = prime * result + ((isDouble == null) ? 0 : isDouble.hashCode()); result = prime * result + ((isByteArray == null) ? 0 : isByteArray.hashCode()); result = prime * result + ((isBinary == null) ? 0 : isBinary.hashCode()); + result = prime * result + ((isFile == null) ? 0 : isFile.hashCode()); result = prime * result + ((isBoolean == null) ? 0 : isBoolean.hashCode()); result = prime * result + ((isDate == null) ? 0 : isDate.hashCode()); result = prime * result + ((isDateTime == null) ? 0 : isDateTime.hashCode()); @@ -262,6 +263,9 @@ public boolean equals(Object obj) { if (this.isBinary != other.isBinary && (this.isBinary == null || !this.isBinary.equals(other.isBinary))) { return false; } + if (this.isFile != other.isFile && (this.isFile == null || !this.isFile.equals(other.isFile))) { + return false; + } if (this.isListContainer != other.isListContainer && (this.isListContainer == null || !this.isListContainer.equals(other.isListContainer))) { return false; } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java index a8a2117a31e..fb09f820be5 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java @@ -16,6 +16,7 @@ public class CodegenResponse { public Boolean isMapContainer; public Boolean isListContainer; public Boolean isBinary = Boolean.FALSE; + public Boolean isFile = Boolean.FALSE; public Object schema; public String jsonSchema; @@ -63,6 +64,8 @@ public boolean equals(Object o) { return false; if (isBinary != null ? !isBinary.equals(that.isBinary) : that.isBinary != null) return false; + if (isFile != null ? !isFile.equals(that.isFile) : that.isFile != null) + return false; if (schema != null ? !schema.equals(that.schema) : that.schema != null) return false; return jsonSchema != null ? jsonSchema.equals(that.jsonSchema) : that.jsonSchema == null; @@ -85,6 +88,7 @@ public int hashCode() { result = 31 * result + (isMapContainer != null ? isMapContainer.hashCode() : 0); result = 31 * result + (isListContainer != null ? isListContainer.hashCode() : 0); result = 31 * result + (isBinary != null ? isBinary.hashCode() : 0); + result = 31 * result + (isFile != null ? isFile.hashCode() : 0); result = 31 * result + (schema != null ? schema.hashCode() : 0); result = 31 * result + (jsonSchema != null ? jsonSchema.hashCode() : 0); return result; 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 63cad401d02..2bb27cef3ff 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 @@ -36,6 +36,7 @@ import io.swagger.models.properties.DateTimeProperty; import io.swagger.models.properties.DecimalProperty; import io.swagger.models.properties.DoubleProperty; +import io.swagger.models.properties.FileProperty; import io.swagger.models.properties.FloatProperty; import io.swagger.models.properties.IntegerProperty; import io.swagger.models.properties.LongProperty; @@ -765,6 +766,7 @@ public DefaultCodegen() { typeMapping.put("integer", "Integer"); typeMapping.put("ByteArray", "byte[]"); typeMapping.put("binary", "byte[]"); + typeMapping.put("file", "File"); instantiationTypes = new HashMap(); @@ -1069,6 +1071,8 @@ public String getSwaggerType(Property p) { datatype = "ByteArray"; } else if (p instanceof BinaryProperty) { datatype = "binary"; + } else if (p instanceof FileProperty) { + datatype = "file"; } else if (p instanceof BooleanProperty) { datatype = "boolean"; } else if (p instanceof DateProperty) { @@ -1536,6 +1540,9 @@ public CodegenProperty fromProperty(String name, Property p) { if (p instanceof BinaryProperty) { property.isBinary = true; } + if (p instanceof FileProperty) { + property.isFile = true; + } if (p instanceof UUIDProperty) { property.isString = true; } @@ -1964,6 +1971,9 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation if (r.isBinary && r.isDefault){ op.isResponseBinary = Boolean.TRUE; } + if (r.isFile && r.isDefault){ + op.isResponseFile = Boolean.TRUE; + } } op.responses.get(op.responses.size() - 1).hasMore = false; @@ -2163,6 +2173,7 @@ public CodegenResponse fromResponse(String responseCode, Response response) { } r.dataType = cm.datatype; r.isBinary = isDataTypeBinary(cm.datatype); + r.isFile = isDataTypeFile(cm.datatype); if (cm.isContainer != null) { r.simpleType = false; r.containerType = cm.containerType; @@ -2343,6 +2354,7 @@ public CodegenParameter fromParameter(Parameter param, Set imports) { p.dataType = cp.datatype; p.isPrimitiveType = cp.isPrimitiveType; p.isBinary = isDataTypeBinary(cp.datatype); + p.isFile = isDataTypeFile(cp.datatype); } // set boolean flag (e.g. isString) @@ -2409,6 +2421,8 @@ public CodegenParameter fromParameter(Parameter param, Set imports) { p.example = "BINARY_DATA_HERE"; } else if (Boolean.TRUE.equals(p.isByteArray)) { p.example = "B"; + } else if (Boolean.TRUE.equals(p.isFile)) { + p.example = "/path/to/file.txt"; } else if (Boolean.TRUE.equals(p.isDate)) { p.example = "2013-10-20"; } else if (Boolean.TRUE.equals(p.isDateTime)) { @@ -2459,6 +2473,10 @@ public boolean isDataTypeBinary(String dataType) { return dataType.toLowerCase().startsWith("byte"); } + public boolean isDataTypeFile(String dataType) { + return dataType.toLowerCase().equals("file"); + } + /** * Convert map of Swagger SecuritySchemeDefinition objects to a list of Codegen Security objects * @@ -3254,6 +3272,10 @@ public void setParameterBooleanFlagWithCodegenProperty(CodegenParameter paramete } else if (Boolean.TRUE.equals(property.isBinary)) { parameter.isByteArray = true; parameter.isPrimitiveType = true; + } else if (Boolean.TRUE.equals(property.isFile)) { + parameter.isFile = true; + // file is *not* a primitive type + //parameter.isPrimitiveType = true; } else if (Boolean.TRUE.equals(property.isDate)) { parameter.isDate = true; parameter.isPrimitiveType = true; diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java index 989d339ccdb..280383961d4 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java @@ -41,7 +41,9 @@ public TypeScriptAngular2ClientCodegen() { embeddedTemplateDir = templateDir = "typescript-angular2"; modelTemplateFiles.put("model.mustache", ".ts"); apiTemplateFiles.put("api.service.mustache", ".ts"); + languageSpecificPrimitives.add("Blob"); typeMapping.put("Date","Date"); + typeMapping.put("file","Blob"); apiPackage = "api"; modelPackage = "model"; @@ -116,6 +118,11 @@ private String getIndexDirectory() { return indexPackage.replace('.', File.separatorChar); } + @Override + public boolean isDataTypeFile(final String dataType) { + return dataType != null && dataType.equals("Blob"); + } + @Override public String getTypeDeclaration(Property p) { Property inner; @@ -127,7 +134,9 @@ public String getTypeDeclaration(Property p) { MapProperty mp = (MapProperty)p; inner = mp.getAdditionalProperties(); return "{ [key: string]: " + this.getTypeDeclaration(inner) + "; }"; - } else if(p instanceof FileProperty || p instanceof ObjectProperty) { + } else if(p instanceof FileProperty) { + return "Blob"; + } else if(p instanceof ObjectProperty) { return "any"; } else { return super.getTypeDeclaration(p); 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 67a6ed0b422..50662a26dd5 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,5 +1,7 @@ package io.swagger.codegen.languages; +import io.swagger.models.properties.FileProperty; +import io.swagger.models.properties.Property; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,6 +29,8 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen public TypeScriptNodeClientCodegen() { super(); + typeMapping.put("file", "Buffer"); + // clear import mapping (from default generator) as TS does not use it // at the moment importMapping.clear(); @@ -92,6 +96,19 @@ public String getHelp() { return "Generates a TypeScript nodejs client library."; } + @Override + public boolean isDataTypeFile(final String dataType) { + return dataType != null && dataType.equals("Buffer"); + } + + @Override + public String getTypeDeclaration(Property p) { + if (p instanceof FileProperty) { + return "Buffer"; + } + return super.getTypeDeclaration(p); + } + public void setNpmName(String npmName) { this.npmName = npmName; diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.service.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.service.mustache index f52b7085dbe..6532fc63707 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.service.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.service.mustache @@ -54,6 +54,20 @@ export class {{classname}} { return objA; } + /** + * @param consumes string[] mime-types + * @return true: consumes contains 'multipart/form-data', false: otherwise + */ + private canConsumeForm(consumes: string[]): boolean { + const form = 'multipart/form-data'; + for (let consume of consumes) { + if (form === consume) { + return true; + } + } + return false; + } + {{#operation}} /** * {{summary}} @@ -66,7 +80,12 @@ export class {{classname}} { if (response.status === 204) { return undefined; } else { +{{^isResponseFile}} return response.json(); +{{/isResponseFile}} +{{#isResponseFile}} + return response.blob(); +{{/isResponseFile}} } }); } @@ -84,10 +103,7 @@ export class {{classname}} { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -{{#hasFormParams}} - let formParams = new URLSearchParams(); -{{/hasFormParams}} {{#allParams}} {{#required}} // verify required parameter '{{paramName}}' is not null or undefined @@ -106,12 +122,24 @@ export class {{classname}} { headers.set('{{baseName}}', String({{paramName}})); {{/headerParams}} +{{#hasFormParams}} // to determine the Content-Type header let consumes: string[] = [ {{#consumes}} '{{{mediaType}}}'{{#hasMore}}, {{/hasMore}} {{/consumes}} ]; + let canConsumeForm = this.canConsumeForm(consumes); + let useForm = false; +{{#formParams}} +{{#isFile}} + useForm = canConsumeForm; +{{/isFile}} +{{/formParams}} + let formParams = new (useForm ? FormData : URLSearchParams as any)() as { + set(param: string, value: any): void; + }; +{{/hasFormParams}} // to determine the Accept header let produces: string[] = [ @@ -152,17 +180,13 @@ export class {{classname}} { {{/isOAuth}} {{/authMethods}} -{{#hasFormParams}} - headers.set('Content-Type', 'application/x-www-form-urlencoded'); -{{/hasFormParams}} - {{#bodyParam}} headers.set('Content-Type', 'application/json'); {{/bodyParam}} {{#formParams}} if ({{paramName}} !== undefined) { - formParams.set('{{baseName}}', {{paramName}}); + formParams.set('{{baseName}}', {{paramName}}); } {{/formParams}} @@ -173,8 +197,11 @@ export class {{classname}} { body: {{paramName}} == null ? '' : JSON.stringify({{paramName}}), // https://github.com/angular/angular/issues/10612 {{/bodyParam}} {{#hasFormParams}} - body: formParams.toString(), + body: formParams, {{/hasFormParams}} +{{#isResponseFile}} + responseType: ResponseContentType.Blob, +{{/isResponseFile}} search: queryParameters }); 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 d501432df28..8817a657fa4 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-node/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-node/api.mustache @@ -235,7 +235,12 @@ export class {{classname}} { headers: headerParams, uri: localVarPath, useQuerystring: this._useQuerystring, +{{^isResponseFile}} json: true, +{{/isResponseFile}} +{{#isResponseFile}} + encoding: null, +{{/isResponseFile}} {{#bodyParam}} body: {{paramName}}, {{/bodyParam}} diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java index 37050a1be4b..5848108055d 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java @@ -43,7 +43,7 @@ public void fileUploadParamTest() { final CodegenParameter file = op.formParams.get(1); Assert.assertTrue(file.isFormParam); - Assert.assertEquals(file.dataType, "file"); + Assert.assertEquals(file.dataType, "File"); Assert.assertNull(file.required); Assert.assertTrue(file.isFile); Assert.assertNull(file.hasMore); @@ -187,6 +187,19 @@ public void binaryDataTest() { Assert.assertTrue(op.bodyParam.isBinary); Assert.assertTrue(op.responses.get(0).isBinary); } + + @Test(description = "return file when response format is file") + public void fileResponeseTest() { + final Swagger model = parseAndPrepareSwagger("src/test/resources/2_0/fileResponseTest.json"); + final DefaultCodegen codegen = new DefaultCodegen(); + final String path = "/tests/fileResponse"; + final Operation p = model.getPaths().get(path).getGet(); + final CodegenOperation op = codegen.fromOperation(path, "get", p, model.getDefinitions()); + + Assert.assertEquals(op.returnType, "File"); + Assert.assertTrue(op.responses.get(0).isFile); + Assert.assertTrue(op.isResponseFile); + } @Test(description = "discriminator is present") public void discriminatorTest() { diff --git a/modules/swagger-codegen/src/test/resources/2_0/fileResponseTest.json b/modules/swagger-codegen/src/test/resources/2_0/fileResponseTest.json new file mode 100644 index 00000000000..ab8237934ef --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/2_0/fileResponseTest.json @@ -0,0 +1,33 @@ +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "File Response Test", + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "basePath": "/v2", + "schemes": [ + "http" + ], + "paths": { + "/tests/fileResponse": { + "get": { + "operationId": "fileresponsetest", + "produces": [ + "application/octet-stream" + ], + "responses": { + "200": { + "description": "OutputFileData", + "schema": { + "type": "file" + } + } + } + } + } + } +} diff --git a/pom.xml b/pom.xml index daabde4fc62..4f80d751106 100644 --- a/pom.xml +++ b/pom.xml @@ -819,7 +819,7 @@ - 1.0.24-SNAPSHOT + 1.0.24 2.11.1 2.3.4 1.5.10 diff --git a/samples/client/petstore/php/SwaggerClient-php/README.md b/samples/client/petstore/php/SwaggerClient-php/README.md index 6089d21da1c..74a60246e9d 100644 --- a/samples/client/petstore/php/SwaggerClient-php/README.md +++ b/samples/client/petstore/php/SwaggerClient-php/README.md @@ -4,7 +4,7 @@ This spec is mainly for testing Petstore server and contains fake endpoints, mod This PHP package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project: - API version: 1.0.0 -- Build package: class io.swagger.codegen.languages.PhpClientCodegen +- Build package: io.swagger.codegen.languages.PhpClientCodegen ## Requirements diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md b/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md index 249841b68e9..4b1f354ff91 100644 --- a/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md @@ -14,6 +14,8 @@ Method | HTTP request | Description To test \"client\" model +To test \"client\" model + ### Example ```php 100.0)) { - throw new \InvalidArgumentException('invalid value for "$integer" when calling FakeApi.testEndpointParameters, must be smaller than or equal to 100.0.'); + if (!is_null($integer) && ($integer > 100)) { + throw new \InvalidArgumentException('invalid value for "$integer" when calling FakeApi.testEndpointParameters, must be smaller than or equal to 100.'); } - if (!is_null($integer) && ($integer < 10.0)) { - throw new \InvalidArgumentException('invalid value for "$integer" when calling FakeApi.testEndpointParameters, must be bigger than or equal to 10.0.'); + if (!is_null($integer) && ($integer < 10)) { + throw new \InvalidArgumentException('invalid value for "$integer" when calling FakeApi.testEndpointParameters, must be bigger than or equal to 10.'); } - if (!is_null($int32) && ($int32 > 200.0)) { - throw new \InvalidArgumentException('invalid value for "$int32" when calling FakeApi.testEndpointParameters, must be smaller than or equal to 200.0.'); + if (!is_null($int32) && ($int32 > 200)) { + throw new \InvalidArgumentException('invalid value for "$int32" when calling FakeApi.testEndpointParameters, must be smaller than or equal to 200.'); } - if (!is_null($int32) && ($int32 < 20.0)) { - throw new \InvalidArgumentException('invalid value for "$int32" when calling FakeApi.testEndpointParameters, must be bigger than or equal to 20.0.'); + if (!is_null($int32) && ($int32 < 20)) { + throw new \InvalidArgumentException('invalid value for "$int32" when calling FakeApi.testEndpointParameters, must be bigger than or equal to 20.'); } if (!is_null($float) && ($float > 987.6)) { @@ -406,7 +406,7 @@ public function testEndpointParametersWithHttpInfo($number, $double, $pattern_wi * @param string $enum_header_string Header parameter enum test (string) (optional, default to -efg) * @param string[] $enum_query_string_array Query parameter enum test (string array) (optional) * @param string $enum_query_string Query parameter enum test (string) (optional, default to -efg) - * @param float $enum_query_integer Query parameter enum test (double) (optional) + * @param int $enum_query_integer Query parameter enum test (double) (optional) * @param double $enum_query_double Query parameter enum test (double) (optional) * @throws \Swagger\Client\ApiException on non-2xx response * @return void @@ -428,7 +428,7 @@ public function testEnumParameters($enum_form_string_array = null, $enum_form_st * @param string $enum_header_string Header parameter enum test (string) (optional, default to -efg) * @param string[] $enum_query_string_array Query parameter enum test (string array) (optional) * @param string $enum_query_string Query parameter enum test (string) (optional, default to -efg) - * @param float $enum_query_integer Query parameter enum test (double) (optional) + * @param int $enum_query_integer Query parameter enum test (double) (optional) * @param double $enum_query_double Query parameter enum test (double) (optional) * @throws \Swagger\Client\ApiException on non-2xx response * @return array of null, HTTP status code, HTTP response headers (array of strings) diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php index 7d34e608139..e1cb74392b6 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -292,11 +292,11 @@ public function getOrderByIdWithHttpInfo($order_id) if ($order_id === null) { throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById'); } - if (($order_id > 5.0)) { - throw new \InvalidArgumentException('invalid value for "$order_id" when calling StoreApi.getOrderById, must be smaller than or equal to 5.0.'); + if (($order_id > 5)) { + throw new \InvalidArgumentException('invalid value for "$order_id" when calling StoreApi.getOrderById, must be smaller than or equal to 5.'); } - if (($order_id < 1.0)) { - throw new \InvalidArgumentException('invalid value for "$order_id" when calling StoreApi.getOrderById, must be bigger than or equal to 1.0.'); + if (($order_id < 1)) { + throw new \InvalidArgumentException('invalid value for "$order_id" when calling StoreApi.getOrderById, must be bigger than or equal to 1.'); } // parse inputs diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php index 76a944104f2..65fe2cdcf48 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php @@ -202,20 +202,20 @@ public function __construct(array $data = null) public function listInvalidProperties() { $invalid_properties = []; - if (!is_null($this->container['integer']) && ($this->container['integer'] > 100.0)) { - $invalid_properties[] = "invalid value for 'integer', must be smaller than or equal to 100.0."; + if (!is_null($this->container['integer']) && ($this->container['integer'] > 100)) { + $invalid_properties[] = "invalid value for 'integer', must be smaller than or equal to 100."; } - if (!is_null($this->container['integer']) && ($this->container['integer'] < 10.0)) { - $invalid_properties[] = "invalid value for 'integer', must be bigger than or equal to 10.0."; + if (!is_null($this->container['integer']) && ($this->container['integer'] < 10)) { + $invalid_properties[] = "invalid value for 'integer', must be bigger than or equal to 10."; } - if (!is_null($this->container['int32']) && ($this->container['int32'] > 200.0)) { - $invalid_properties[] = "invalid value for 'int32', must be smaller than or equal to 200.0."; + if (!is_null($this->container['int32']) && ($this->container['int32'] > 200)) { + $invalid_properties[] = "invalid value for 'int32', must be smaller than or equal to 200."; } - if (!is_null($this->container['int32']) && ($this->container['int32'] < 20.0)) { - $invalid_properties[] = "invalid value for 'int32', must be bigger than or equal to 20.0."; + if (!is_null($this->container['int32']) && ($this->container['int32'] < 20)) { + $invalid_properties[] = "invalid value for 'int32', must be bigger than or equal to 20."; } if ($this->container['number'] === null) { @@ -277,16 +277,16 @@ public function listInvalidProperties() */ public function valid() { - if ($this->container['integer'] > 100.0) { + if ($this->container['integer'] > 100) { return false; } - if ($this->container['integer'] < 10.0) { + if ($this->container['integer'] < 10) { return false; } - if ($this->container['int32'] > 200.0) { + if ($this->container['int32'] > 200) { return false; } - if ($this->container['int32'] < 20.0) { + if ($this->container['int32'] < 20) { return false; } if ($this->container['number'] === null) { @@ -349,11 +349,11 @@ public function getInteger() public function setInteger($integer) { - if (!is_null($integer) && ($integer > 100.0)) { - throw new \InvalidArgumentException('invalid value for $integer when calling FormatTest., must be smaller than or equal to 100.0.'); + if (!is_null($integer) && ($integer > 100)) { + throw new \InvalidArgumentException('invalid value for $integer when calling FormatTest., must be smaller than or equal to 100.'); } - if (!is_null($integer) && ($integer < 10.0)) { - throw new \InvalidArgumentException('invalid value for $integer when calling FormatTest., must be bigger than or equal to 10.0.'); + if (!is_null($integer) && ($integer < 10)) { + throw new \InvalidArgumentException('invalid value for $integer when calling FormatTest., must be bigger than or equal to 10.'); } $this->container['integer'] = $integer; @@ -378,11 +378,11 @@ public function getInt32() public function setInt32($int32) { - if (!is_null($int32) && ($int32 > 200.0)) { - throw new \InvalidArgumentException('invalid value for $int32 when calling FormatTest., must be smaller than or equal to 200.0.'); + if (!is_null($int32) && ($int32 > 200)) { + throw new \InvalidArgumentException('invalid value for $int32 when calling FormatTest., must be smaller than or equal to 200.'); } - if (!is_null($int32) && ($int32 < 20.0)) { - throw new \InvalidArgumentException('invalid value for $int32 when calling FormatTest., must be bigger than or equal to 20.0.'); + if (!is_null($int32) && ($int32 < 20)) { + throw new \InvalidArgumentException('invalid value for $int32 when calling FormatTest., must be bigger than or equal to 20.'); } $this->container['int32'] = $int32; diff --git a/samples/client/petstore/typescript-angular2/default/api/pet.service.ts b/samples/client/petstore/typescript-angular2/default/api/pet.service.ts index bad3f242aaa..5b159f48605 100644 --- a/samples/client/petstore/typescript-angular2/default/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular2/default/api/pet.service.ts @@ -69,6 +69,20 @@ export class PetService { return objA; } + /** + * @param consumes string[] mime-types + * @return true: consumes contains 'multipart/form-data', false: otherwise + */ + private canConsumeForm(consumes: string[]): boolean { + const form = 'multipart/form-data'; + for (let consume of consumes) { + if (form === consume) { + return true; + } + } + return false; + } + /** * Add a new pet to the store * @@ -191,7 +205,7 @@ export class PetService { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFile(petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any): Observable<{}> { + public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable<{}> { return this.uploadFileWithHttpInfo(petId, additionalMetadata, file, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -215,11 +229,7 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - 'application/json', - 'application/xml' - ]; + // to determine the Accept header let produces: string[] = [ @@ -234,7 +244,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + this.configuration.accessToken); } - headers.set('Content-Type', 'application/json'); @@ -264,6 +273,7 @@ export class PetService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); @@ -271,9 +281,6 @@ export class PetService { headers.set('api_key', String(apiKey)); - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -290,7 +297,6 @@ export class PetService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -315,14 +321,12 @@ export class PetService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + if (status !== undefined) { queryParameters.set('status', status); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -339,7 +343,6 @@ export class PetService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -364,14 +367,12 @@ export class PetService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + if (tags !== undefined) { queryParameters.set('tags', tags); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -388,7 +389,6 @@ export class PetService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -413,15 +413,13 @@ export class PetService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling getPetById.'); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -429,21 +427,20 @@ export class PetService { 'application/xml' ]; - // authentication (api_key) required - if (this.configuration.apiKey) - { - headers.set('api_key', this.configuration.apiKey); - } // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { headers.set('Authorization', 'Bearer ' + this.configuration.accessToken); } + // authentication (api_key) required + if (this.configuration.apiKey) + { + headers.set('api_key', this.configuration.apiKey); + } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -470,11 +467,7 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - 'application/json', - 'application/xml' - ]; + // to determine the Accept header let produces: string[] = [ @@ -489,7 +482,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + this.configuration.accessToken); } - headers.set('Content-Type', 'application/json'); @@ -520,7 +512,6 @@ export class PetService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let formParams = new URLSearchParams(); // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -532,6 +523,11 @@ export class PetService { let consumes: string[] = [ 'application/x-www-form-urlencoded' ]; + let canConsumeForm = this.canConsumeForm(consumes); + let useForm = false; + let formParams = new (useForm ? FormData : URLSearchParams as any)() as { + set(param: string, value: any): void; + }; // to determine the Accept header let produces: string[] = [ @@ -546,20 +542,18 @@ export class PetService { headers.set('Authorization', 'Bearer ' + this.configuration.accessToken); } - headers.set('Content-Type', 'application/x-www-form-urlencoded'); - if (name !== undefined) { - formParams.set('name', name); + formParams.set('name', name); } if (status !== undefined) { - formParams.set('status', status); + formParams.set('status', status); } let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: formParams.toString(), + body: formParams, search: queryParameters }); @@ -578,12 +572,11 @@ export class PetService { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any): Observable { + public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { const path = this.basePath + `/pet/${petId}/uploadImage`; let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let formParams = new URLSearchParams(); // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -595,6 +588,12 @@ export class PetService { let consumes: string[] = [ 'multipart/form-data' ]; + let canConsumeForm = this.canConsumeForm(consumes); + let useForm = false; + useForm = canConsumeForm; + let formParams = new (useForm ? FormData : URLSearchParams as any)() as { + set(param: string, value: any): void; + }; // to determine the Accept header let produces: string[] = [ @@ -609,20 +608,18 @@ export class PetService { headers.set('Authorization', 'Bearer ' + this.configuration.accessToken); } - headers.set('Content-Type', 'application/x-www-form-urlencoded'); - if (additionalMetadata !== undefined) { - formParams.set('additionalMetadata', additionalMetadata); + formParams.set('additionalMetadata', additionalMetadata); } if (file !== undefined) { - formParams.set('file', file); + formParams.set('file', file); } let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: formParams.toString(), + body: formParams, search: queryParameters }); diff --git a/samples/client/petstore/typescript-angular2/default/api/store.service.ts b/samples/client/petstore/typescript-angular2/default/api/store.service.ts index f8cab0853c8..8a1477dd08f 100644 --- a/samples/client/petstore/typescript-angular2/default/api/store.service.ts +++ b/samples/client/petstore/typescript-angular2/default/api/store.service.ts @@ -69,6 +69,20 @@ export class StoreService { return objA; } + /** + * @param consumes string[] mime-types + * @return true: consumes contains 'multipart/form-data', false: otherwise + */ + private canConsumeForm(consumes: string[]): boolean { + const form = 'multipart/form-data'; + for (let consume of consumes) { + if (form === consume) { + return true; + } + } + return false; + } + /** * Delete purchase order by ID * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors @@ -143,15 +157,13 @@ export class StoreService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'orderId' is not null or undefined if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -162,7 +174,6 @@ export class StoreService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -188,9 +199,7 @@ export class StoreService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - ]; + // to determine the Accept header let produces: string[] = [ @@ -206,7 +215,6 @@ export class StoreService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -231,15 +239,13 @@ export class StoreService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'orderId' is not null or undefined if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -250,7 +256,6 @@ export class StoreService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -277,9 +282,7 @@ export class StoreService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - ]; + // to determine the Accept header let produces: string[] = [ @@ -288,7 +291,6 @@ export class StoreService { ]; - headers.set('Content-Type', 'application/json'); diff --git a/samples/client/petstore/typescript-angular2/default/api/user.service.ts b/samples/client/petstore/typescript-angular2/default/api/user.service.ts index f77b0768493..b30215d8a6c 100644 --- a/samples/client/petstore/typescript-angular2/default/api/user.service.ts +++ b/samples/client/petstore/typescript-angular2/default/api/user.service.ts @@ -69,6 +69,20 @@ export class UserService { return objA; } + /** + * @param consumes string[] mime-types + * @return true: consumes contains 'multipart/form-data', false: otherwise + */ + private canConsumeForm(consumes: string[]): boolean { + const form = 'multipart/form-data'; + for (let consume of consumes) { + if (form === consume) { + return true; + } + } + return false; + } + /** * Create user * This can only be done by the logged in user. @@ -211,9 +225,7 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - ]; + // to determine the Accept header let produces: string[] = [ @@ -222,7 +234,6 @@ export class UserService { ]; - headers.set('Content-Type', 'application/json'); @@ -253,9 +264,7 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - ]; + // to determine the Accept header let produces: string[] = [ @@ -264,7 +273,6 @@ export class UserService { ]; - headers.set('Content-Type', 'application/json'); @@ -295,9 +303,7 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - ]; + // to determine the Accept header let produces: string[] = [ @@ -306,7 +312,6 @@ export class UserService { ]; - headers.set('Content-Type', 'application/json'); @@ -335,15 +340,13 @@ export class UserService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling deleteUser.'); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -354,7 +357,6 @@ export class UserService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -379,15 +381,13 @@ export class UserService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling getUserByName.'); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -398,7 +398,6 @@ export class UserService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -424,6 +423,7 @@ export class UserService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + if (username !== undefined) { queryParameters.set('username', username); } @@ -432,9 +432,6 @@ export class UserService { } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -445,7 +442,6 @@ export class UserService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -471,9 +467,7 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - ]; + // to determine the Accept header let produces: string[] = [ @@ -484,7 +478,6 @@ export class UserService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -510,15 +503,13 @@ export class UserService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling updateUser.'); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -527,7 +518,6 @@ export class UserService { ]; - headers.set('Content-Type', 'application/json'); diff --git a/samples/client/petstore/typescript-angular2/npm/README.md b/samples/client/petstore/typescript-angular2/npm/README.md index 35dbb6845c0..22b42554025 100644 --- a/samples/client/petstore/typescript-angular2/npm/README.md +++ b/samples/client/petstore/typescript-angular2/npm/README.md @@ -1,4 +1,4 @@ -## @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201612061154 +## @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201701041145 ### Building @@ -19,7 +19,7 @@ navigate to the folder of your consuming project and run one of next commando's. _published:_ ``` -npm install @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201612061154 --save +npm install @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201701041145 --save ``` _unPublished (not recommended):_ diff --git a/samples/client/petstore/typescript-angular2/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular2/npm/api/pet.service.ts index bad3f242aaa..5b159f48605 100644 --- a/samples/client/petstore/typescript-angular2/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular2/npm/api/pet.service.ts @@ -69,6 +69,20 @@ export class PetService { return objA; } + /** + * @param consumes string[] mime-types + * @return true: consumes contains 'multipart/form-data', false: otherwise + */ + private canConsumeForm(consumes: string[]): boolean { + const form = 'multipart/form-data'; + for (let consume of consumes) { + if (form === consume) { + return true; + } + } + return false; + } + /** * Add a new pet to the store * @@ -191,7 +205,7 @@ export class PetService { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFile(petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any): Observable<{}> { + public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable<{}> { return this.uploadFileWithHttpInfo(petId, additionalMetadata, file, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -215,11 +229,7 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - 'application/json', - 'application/xml' - ]; + // to determine the Accept header let produces: string[] = [ @@ -234,7 +244,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + this.configuration.accessToken); } - headers.set('Content-Type', 'application/json'); @@ -264,6 +273,7 @@ export class PetService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); @@ -271,9 +281,6 @@ export class PetService { headers.set('api_key', String(apiKey)); - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -290,7 +297,6 @@ export class PetService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -315,14 +321,12 @@ export class PetService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + if (status !== undefined) { queryParameters.set('status', status); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -339,7 +343,6 @@ export class PetService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -364,14 +367,12 @@ export class PetService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + if (tags !== undefined) { queryParameters.set('tags', tags); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -388,7 +389,6 @@ export class PetService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -413,15 +413,13 @@ export class PetService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling getPetById.'); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -429,21 +427,20 @@ export class PetService { 'application/xml' ]; - // authentication (api_key) required - if (this.configuration.apiKey) - { - headers.set('api_key', this.configuration.apiKey); - } // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { headers.set('Authorization', 'Bearer ' + this.configuration.accessToken); } + // authentication (api_key) required + if (this.configuration.apiKey) + { + headers.set('api_key', this.configuration.apiKey); + } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -470,11 +467,7 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - 'application/json', - 'application/xml' - ]; + // to determine the Accept header let produces: string[] = [ @@ -489,7 +482,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + this.configuration.accessToken); } - headers.set('Content-Type', 'application/json'); @@ -520,7 +512,6 @@ export class PetService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let formParams = new URLSearchParams(); // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -532,6 +523,11 @@ export class PetService { let consumes: string[] = [ 'application/x-www-form-urlencoded' ]; + let canConsumeForm = this.canConsumeForm(consumes); + let useForm = false; + let formParams = new (useForm ? FormData : URLSearchParams as any)() as { + set(param: string, value: any): void; + }; // to determine the Accept header let produces: string[] = [ @@ -546,20 +542,18 @@ export class PetService { headers.set('Authorization', 'Bearer ' + this.configuration.accessToken); } - headers.set('Content-Type', 'application/x-www-form-urlencoded'); - if (name !== undefined) { - formParams.set('name', name); + formParams.set('name', name); } if (status !== undefined) { - formParams.set('status', status); + formParams.set('status', status); } let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: formParams.toString(), + body: formParams, search: queryParameters }); @@ -578,12 +572,11 @@ export class PetService { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any): Observable { + public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { const path = this.basePath + `/pet/${petId}/uploadImage`; let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let formParams = new URLSearchParams(); // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -595,6 +588,12 @@ export class PetService { let consumes: string[] = [ 'multipart/form-data' ]; + let canConsumeForm = this.canConsumeForm(consumes); + let useForm = false; + useForm = canConsumeForm; + let formParams = new (useForm ? FormData : URLSearchParams as any)() as { + set(param: string, value: any): void; + }; // to determine the Accept header let produces: string[] = [ @@ -609,20 +608,18 @@ export class PetService { headers.set('Authorization', 'Bearer ' + this.configuration.accessToken); } - headers.set('Content-Type', 'application/x-www-form-urlencoded'); - if (additionalMetadata !== undefined) { - formParams.set('additionalMetadata', additionalMetadata); + formParams.set('additionalMetadata', additionalMetadata); } if (file !== undefined) { - formParams.set('file', file); + formParams.set('file', file); } let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: formParams.toString(), + body: formParams, search: queryParameters }); diff --git a/samples/client/petstore/typescript-angular2/npm/api/store.service.ts b/samples/client/petstore/typescript-angular2/npm/api/store.service.ts index f8cab0853c8..8a1477dd08f 100644 --- a/samples/client/petstore/typescript-angular2/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular2/npm/api/store.service.ts @@ -69,6 +69,20 @@ export class StoreService { return objA; } + /** + * @param consumes string[] mime-types + * @return true: consumes contains 'multipart/form-data', false: otherwise + */ + private canConsumeForm(consumes: string[]): boolean { + const form = 'multipart/form-data'; + for (let consume of consumes) { + if (form === consume) { + return true; + } + } + return false; + } + /** * Delete purchase order by ID * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors @@ -143,15 +157,13 @@ export class StoreService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'orderId' is not null or undefined if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -162,7 +174,6 @@ export class StoreService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -188,9 +199,7 @@ export class StoreService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - ]; + // to determine the Accept header let produces: string[] = [ @@ -206,7 +215,6 @@ export class StoreService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -231,15 +239,13 @@ export class StoreService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'orderId' is not null or undefined if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -250,7 +256,6 @@ export class StoreService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -277,9 +282,7 @@ export class StoreService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - ]; + // to determine the Accept header let produces: string[] = [ @@ -288,7 +291,6 @@ export class StoreService { ]; - headers.set('Content-Type', 'application/json'); diff --git a/samples/client/petstore/typescript-angular2/npm/api/user.service.ts b/samples/client/petstore/typescript-angular2/npm/api/user.service.ts index f77b0768493..b30215d8a6c 100644 --- a/samples/client/petstore/typescript-angular2/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular2/npm/api/user.service.ts @@ -69,6 +69,20 @@ export class UserService { return objA; } + /** + * @param consumes string[] mime-types + * @return true: consumes contains 'multipart/form-data', false: otherwise + */ + private canConsumeForm(consumes: string[]): boolean { + const form = 'multipart/form-data'; + for (let consume of consumes) { + if (form === consume) { + return true; + } + } + return false; + } + /** * Create user * This can only be done by the logged in user. @@ -211,9 +225,7 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - ]; + // to determine the Accept header let produces: string[] = [ @@ -222,7 +234,6 @@ export class UserService { ]; - headers.set('Content-Type', 'application/json'); @@ -253,9 +264,7 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - ]; + // to determine the Accept header let produces: string[] = [ @@ -264,7 +273,6 @@ export class UserService { ]; - headers.set('Content-Type', 'application/json'); @@ -295,9 +303,7 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - ]; + // to determine the Accept header let produces: string[] = [ @@ -306,7 +312,6 @@ export class UserService { ]; - headers.set('Content-Type', 'application/json'); @@ -335,15 +340,13 @@ export class UserService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling deleteUser.'); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -354,7 +357,6 @@ export class UserService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -379,15 +381,13 @@ export class UserService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling getUserByName.'); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -398,7 +398,6 @@ export class UserService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -424,6 +423,7 @@ export class UserService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + if (username !== undefined) { queryParameters.set('username', username); } @@ -432,9 +432,6 @@ export class UserService { } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -445,7 +442,6 @@ export class UserService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -471,9 +467,7 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - ]; + // to determine the Accept header let produces: string[] = [ @@ -484,7 +478,6 @@ export class UserService { - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -510,15 +503,13 @@ export class UserService { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling updateUser.'); } - // to determine the Content-Type header - let consumes: string[] = [ - ]; // to determine the Accept header let produces: string[] = [ @@ -527,7 +518,6 @@ export class UserService { ]; - headers.set('Content-Type', 'application/json'); diff --git a/samples/client/petstore/typescript-angular2/npm/package.json b/samples/client/petstore/typescript-angular2/npm/package.json index 45217928e74..918e058e194 100644 --- a/samples/client/petstore/typescript-angular2/npm/package.json +++ b/samples/client/petstore/typescript-angular2/npm/package.json @@ -1,6 +1,6 @@ { "name": "@swagger/angular2-typescript-petstore", - "version": "0.0.1-SNAPSHOT.201612061154", + "version": "0.0.1-SNAPSHOT.201701041145", "description": "swagger client for @swagger/angular2-typescript-petstore", "author": "Swagger Codegen Contributors", "keywords": [