diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index aeb7cc5dc942..1f46f227a79b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -9,7 +9,12 @@ "ghcr.io/devcontainers/features/node:1": { "version": "lts" }, - "ghcr.io/snebjorn/devcontainer-feature/chromium:latest": {} + "ghcr.io/snebjorn/devcontainer-feature/chromium:latest": {}, + "docker-in-docker": { + "version": "latest", + "moby": true, + "dockerDashComposeVersion": "v1" + } }, // Configure tool-specific properties. "customizations": { @@ -44,4 +49,4 @@ // "postCreateCommand": "mvn clean package -DskipTests", // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "vscode" -} +} \ No newline at end of file diff --git a/.github/workflows/samples-python-server.yaml b/.github/workflows/samples-python-server.yaml index 4ff5ca98c629..9c751cde5d66 100644 --- a/.github/workflows/samples-python-server.yaml +++ b/.github/workflows/samples-python-server.yaml @@ -3,10 +3,10 @@ name: Python Server on: push: paths: - - samples/server/petstore/python-aiohttp/** + - samples/server/petstore/python-aiohttp-srclayout/** pull_request: paths: - - samples/server/petstore/python-aiohttp/** + - samples/server/petstore/python-aiohttp-srclayout/** jobs: build: name: Test Python server @@ -16,7 +16,7 @@ jobs: matrix: sample: # servers - - samples/server/petstore/python-aiohttp/ + - samples/server/petstore/python-aiohttp-srclayout/ steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v4 diff --git a/bin/configs/unmaintained/jmeter.yaml b/bin/configs/jmeter.yaml similarity index 62% rename from bin/configs/unmaintained/jmeter.yaml rename to bin/configs/jmeter.yaml index 79b5de0e41b3..9fcb1a082175 100644 --- a/bin/configs/unmaintained/jmeter.yaml +++ b/bin/configs/jmeter.yaml @@ -1,4 +1,4 @@ generatorName: jmeter outputDir: samples/client/petstore/jmeter -inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml +inputSpec: modules/openapi-generator/src/test/resources/3_0/jmeter/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/jmeter-client diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java index e4adee10dd48..80b4cea7798e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java @@ -2024,16 +2024,6 @@ private PythonType uuidType(IJsonSchemaValidationProperties cp) { return new PythonType(cp.getDataType()); } - private PythonType freeFormType(IJsonSchemaValidationProperties cp) { - typingImports.add("Dict"); - typingImports.add("Any"); - typingImports.add("Union"); - PythonType pt = new PythonType("Union"); - pt.addTypeParam(new PythonType("str")); - pt.addTypeParam(new PythonType("Any")); - return pt; - } - private PythonType modelType(IJsonSchemaValidationProperties cp) { // add model prefix hasModelsToImport = true; @@ -2056,7 +2046,7 @@ private PythonType fromCommon(IJsonSchemaValidationProperties cp) { if (cp.getIsArray()) { return arrayType(cp); - } else if (cp.getIsMap()) { + } else if (cp.getIsMap() || cp.getIsFreeFormObject()) { return mapType(cp); } else if (cp.getIsString()) { return stringType(cp); @@ -2076,8 +2066,6 @@ private PythonType fromCommon(IJsonSchemaValidationProperties cp) { return dateType(cp); } else if (cp.getIsUuid()) { return uuidType(cp); - } else if (cp.getIsFreeFormObject()) { // type: object - return freeFormType(cp); } return null; diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JMeterClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JMeterClientCodegen.java index b8953d8f9845..5779f9631234 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JMeterClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JMeterClientCodegen.java @@ -163,6 +163,12 @@ public void preprocessOpenAPI(OpenAPI openAPI) { } } + @Override + public String toOperationId(String operationId) { + // replace $ with _ + return super.toOperationId(operationId.replace("$", "_")); + } + /** * Escapes a reserved word as defined in the `reservedWords` array. Handle escaping * those terms here. This logic is only called if a variable matches the reserved words diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java index 3be05eede2ad..1c0e077a0f0a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java @@ -149,7 +149,7 @@ private ModelsMap postProcessModelsMap(ModelsMap objs) { propType = prop.dataType; } - if ((!prop.required || prop.isNullable)) { // optional or nullable + if ((!prop.required || prop.isNullable) && propType != "mixed") { // optional or nullable but not mixed propType = "?" + propType; } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java index 9feb2d3a0743..275a33e0a23e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java @@ -193,7 +193,7 @@ public RustServerCodegen() { typeMapping.put("ByteArray", bytesType); typeMapping.put("binary", bytesType); typeMapping.put("boolean", "bool"); - typeMapping.put("date", "chrono::DateTime::"); + typeMapping.put("date", "chrono::naive::NaiveDate"); typeMapping.put("DateTime", "chrono::DateTime::"); typeMapping.put("password", "String"); typeMapping.put("File", bytesType); diff --git a/modules/openapi-generator/src/main/resources/Java/auth/HttpBearerAuth.mustache b/modules/openapi-generator/src/main/resources/Java/auth/HttpBearerAuth.mustache index 322281f8716a..6ed21107ddff 100644 --- a/modules/openapi-generator/src/main/resources/Java/auth/HttpBearerAuth.mustache +++ b/modules/openapi-generator/src/main/resources/Java/auth/HttpBearerAuth.mustache @@ -4,13 +4,15 @@ package {{invokerPackage}}.auth; import {{invokerPackage}}.Pair; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; {{>generatedAnnotation}} public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -22,7 +24,7 @@ public class HttpBearerAuth implements Authentication { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -31,12 +33,22 @@ public class HttpBearerAuth implements Authentication { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams) { - if(bearerToken == null) { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); + if (bearerToken == null) { return; } diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/ApiClient.mustache index 7a78f616c777..edb36a84774f 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/ApiClient.mustache @@ -49,6 +49,7 @@ import java.util.List; import java.util.Arrays; import java.util.ArrayList; import java.util.Date; +import java.util.function.Supplier; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -335,6 +336,20 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { throw new RuntimeException("No Bearer authentication configured!"); } + /** + * Helper method to set the supplier of access tokens for Bearer authentication. + * + * @param tokenSupplier the token supplier function + */ + public void setBearerToken(Supplier tokenSupplier) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBearerAuth) { + ((HttpBearerAuth) auth).setBearerToken(tokenSupplier); + return; + } + } + throw new RuntimeException("No Bearer authentication configured!"); + } {{/hasHttpBearerMethods}} {{#hasHttpBasicMethods}} diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache index 4ae744398e3f..a2f52dbc5cca 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache @@ -2,6 +2,7 @@ package {{invokerPackage}}; import java.util.LinkedHashMap; import java.util.Map; +import java.util.function.Supplier; import java.util.logging.Level; import java.util.logging.Logger; @@ -265,6 +266,15 @@ public class ApiClient { apiAuthorization.setBearerToken(bearerToken); } + /** + * Helper method to configure the supplier of bearer tokens. + * @param tokenSupplier the supplier of bearer tokens. + */ + public void setBearerToken(Supplier tokenSupplier) { + HttpBearerAuth apiAuthorization = getAuthorization(HttpBearerAuth.class); + apiAuthorization.setBearerToken(tokenSupplier); + } + /** * Helper method to configure the first api key found * @param apiKey API key diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/feign/auth/HttpBearerAuth.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/feign/auth/HttpBearerAuth.mustache index 2240a5518b55..ae3427e0e87f 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/feign/auth/HttpBearerAuth.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/feign/auth/HttpBearerAuth.mustache @@ -2,13 +2,15 @@ package {{invokerPackage}}.auth; import feign.RequestInterceptor; import feign.RequestTemplate; +import java.util.Optional; +import java.util.function.Supplier; /** * An interceptor that adds the request header needed to use HTTP bearer authentication. */ public class HttpBearerAuth implements RequestInterceptor { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -16,21 +18,35 @@ public class HttpBearerAuth implements RequestInterceptor { /** * Gets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** * Sets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void apply(RequestTemplate template) { - if(bearerToken == null) { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); + if (bearerToken == null) { return; } diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache index d0ee6b629ccb..b31b02382e6b 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache @@ -53,6 +53,7 @@ import java.time.format.DateTimeFormatter; import java.util.*; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -528,14 +529,23 @@ public class ApiClient { } {{#hasHttpBearerMethods}} - /** - * Helper method to set access token for the first Bearer authentication. - * @param bearerToken Bearer token - */ + /** + * Helper method to set access token for the first Bearer authentication. + * @param bearerToken Bearer token + */ public void setBearerToken(String bearerToken) { + setBearerToken(() -> bearerToken); + } + + /** + * Helper method to set the supplier of access tokens for Bearer authentication. + * + * @param tokenSupplier The supplier of bearer tokens + */ + public void setBearerToken(Supplier tokenSupplier) { for (Authentication auth : authentications.values()) { if (auth instanceof HttpBearerAuth) { - ((HttpBearerAuth) auth).setBearerToken(bearerToken); + ((HttpBearerAuth) auth).setBearerToken(tokenSupplier); return; } } diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/HttpBearerAuth.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/HttpBearerAuth.mustache index c8a9fce29650..abe1cb8b878f 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/HttpBearerAuth.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/HttpBearerAuth.mustache @@ -6,13 +6,15 @@ import {{invokerPackage}}.ApiException; import {{invokerPackage}}.Pair; import java.net.URI; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; {{>generatedAnnotation}} public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -24,7 +26,7 @@ public class HttpBearerAuth implements Authentication { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -33,12 +35,22 @@ public class HttpBearerAuth implements Authentication { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams, String payload, String method, URI uri) throws ApiException { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); if (bearerToken == null) { return; } diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache index 261ace14f6f0..383a4904c8ec 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache @@ -188,18 +188,18 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { {{#hasHttpBearerMethods}} /** - * Helper method to set token for HTTP bearer authentication. + * Helper method to set access token for the first Bearer authentication. * - * @param bearerToken the token + * @param bearerToken Bearer token */ public void setBearerToken(String bearerToken) { setBearerToken(() -> bearerToken); } /** - * Helper method to set the token supplier for HTTP bearer authentication. + * Helper method to set the supplier of access tokens for Bearer authentication. * - * @param tokenSupplier the token supplier function + * @param tokenSupplier The supplier of bearer tokens */ public void setBearerToken(Supplier tokenSupplier) { for (Authentication auth : authentications.values()) { diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/auth/HttpBearerAuth.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/auth/HttpBearerAuth.mustache index e0924aaf8e1f..e67e76fbf4a7 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/auth/HttpBearerAuth.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/auth/HttpBearerAuth.mustache @@ -14,14 +14,29 @@ public class HttpBearerAuth implements Authentication { this.scheme = scheme; } + /** + * Gets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @return The bearer token + */ public String getBearerToken() { return tokenSupplier.get(); } + /** + * Sets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param bearerToken The bearer token to send in the Authorization header + */ public void setBearerToken(String bearerToken) { this.tokenSupplier = () -> bearerToken; } - + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ public void setBearerToken(Supplier tokenSupplier) { this.tokenSupplier = tokenSupplier; } diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/httpclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/httpclient/ApiClient.mustache index 021fcb79a383..22993e54336c 100644 --- a/modules/openapi-generator/src/main/resources/csharp/libraries/httpclient/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/httpclient/ApiClient.mustache @@ -91,7 +91,18 @@ namespace {{packageName}}.Client /// Object representation of the JSON string. internal async Task Deserialize(HttpResponseMessage response, Type type) { - IList headers = response.Headers.Select(x => x.Key + "=" + x.Value).ToList(); + IList headers = new List(); + // process response headers, e.g. Access-Control-Allow-Methods + foreach (var responseHeader in response.Headers) + { + headers.Add(responseHeader.Key + "=" + ClientUtils.ParameterToString(responseHeader.Value)); + } + + // process response content headers, e.g. Content-Type + foreach (var responseHeader in response.Content.Headers) + { + headers.Add(responseHeader.Key + "=" + ClientUtils.ParameterToString(responseHeader.Value)); + } if (type == typeof(byte[])) // return byte array { diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/analysis_options.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/analysis_options.mustache index 865b3404b402..b625c648d600 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/analysis_options.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/analysis_options.mustache @@ -2,9 +2,7 @@ analyzer: language: strict-inference: true strict-raw-types: true - strong-mode: - implicit-dynamic: false - implicit-casts: false + strict-casts: false exclude: - test/*.dart{{#useJsonSerializable}} - lib/{{sourceFolder}}/model/*.g.dart{{/useJsonSerializable}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/build.gradle.kts.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/build.gradle.kts.mustache index 2bbb82981704..2f26144342b2 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/build.gradle.kts.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/build.gradle.kts.mustache @@ -20,6 +20,7 @@ repositories { kotlin { jvm() ios { binaries { framework { freeCompilerArgs += "-Xobjc-generics" } } } + iosSimulatorArm64 { binaries { framework { freeCompilerArgs += "-Xobjc-generics" } } } js { browser() nodejs() @@ -66,6 +67,10 @@ kotlin { val iosTest by getting + val iosSimulatorArm64Main by getting + + val iosSimulatorArm64Test by getting + val jsMain by getting { dependencies { api("io.ktor:ktor-client-js:$ktor_version") diff --git a/modules/openapi-generator/src/main/resources/php-nextgen/ObjectSerializer.mustache b/modules/openapi-generator/src/main/resources/php-nextgen/ObjectSerializer.mustache index ff602e48338d..8c8b10a39343 100644 --- a/modules/openapi-generator/src/main/resources/php-nextgen/ObjectSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/php-nextgen/ObjectSerializer.mustache @@ -417,10 +417,7 @@ class ObjectSerializer return $deserialized; } - if ($class === 'object') { - settype($data, 'array'); - return $data; - } elseif ($class === 'mixed') { + if ($class === 'mixed') { settype($data, gettype($data)); return $data; } diff --git a/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache b/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache index 9a0a713963fe..fc8819c0ba6b 100644 --- a/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache +++ b/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache @@ -162,7 +162,7 @@ use {{invokerPackage}}\ObjectSerializer; {{/servers}} * @param string $contentType The value for the Content-Type header. Check self::contentTypes['{{{operationId}}}'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return {{#returnType}}{{#responses}}{{#dataType}}{{^-first}}|{{/-first}}{{/dataType}}{{{dataType}}}{{/responses}}{{/returnType}}{{^returnType}}void{{/returnType}} {{#isDeprecated}} @@ -237,7 +237,7 @@ use {{invokerPackage}}\ObjectSerializer; {{/servers}} * @param string $contentType The value for the Content-Type header. Check self::contentTypes['{{{operationId}}}'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of {{#returnType}}{{#responses}}{{#dataType}}{{^-first}}|{{/-first}}{{/dataType}}{{{dataType}}}{{/responses}}{{/returnType}}{{^returnType}}null{{/returnType}}, HTTP status code, HTTP response headers (array of strings) {{#isDeprecated}} @@ -311,7 +311,19 @@ use {{invokerPackage}}\ObjectSerializer; } else { $content = (string) $response->getBody(); if ('{{{dataType}}}' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -332,7 +344,19 @@ use {{invokerPackage}}\ObjectSerializer; } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } diff --git a/modules/openapi-generator/src/main/resources/php-nextgen/model_generic.mustache b/modules/openapi-generator/src/main/resources/php-nextgen/model_generic.mustache index 0a199d959f74..109c5ea42933 100644 --- a/modules/openapi-generator/src/main/resources/php-nextgen/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/php-nextgen/model_generic.mustache @@ -446,7 +446,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}}{{/parentSchema}}{{^par } {{/minimum}} {{#pattern}} - if ({{#isNullable}}!is_null(${{name}}) && {{/isNullable}}(!preg_match("{{{pattern}}}", ${{name}}))) { + if ({{#isNullable}}!is_null(${{name}}) && {{/isNullable}}(!preg_match("{{{pattern}}}", ObjectSerializer::toString(${{name}})))) { throw new InvalidArgumentException("invalid value for \${{name}} when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}."); } {{/pattern}} diff --git a/modules/openapi-generator/src/main/resources/python-aiohttp/controller_test.mustache b/modules/openapi-generator/src/main/resources/python-aiohttp/controller_test.mustache index 7b89e168eb7e..b0360ee0a90a 100644 --- a/modules/openapi-generator/src/main/resources/python-aiohttp/controller_test.mustache +++ b/modules/openapi-generator/src/main/resources/python-aiohttp/controller_test.mustache @@ -17,6 +17,8 @@ from aiohttp import FormData {{#operations}} {{#operation}} +pytestmark = pytest.mark.asyncio + {{#vendorExtensions.x-skip-test}} @pytest.mark.skip("{{reason}}") {{/vendorExtensions.x-skip-test}} diff --git a/modules/openapi-generator/src/main/resources/python-aiohttp/requirements.mustache b/modules/openapi-generator/src/main/resources/python-aiohttp/requirements.mustache index e2ef30b1d41e..ae81351135d8 100644 --- a/modules/openapi-generator/src/main/resources/python-aiohttp/requirements.mustache +++ b/modules/openapi-generator/src/main/resources/python-aiohttp/requirements.mustache @@ -1,4 +1,4 @@ -connexion[aiohttp,swagger-ui] >= 2.6.0; python_version>="3.6" +connexion[aiohttp,swagger-ui] >= 2.6.0, <3; python_version>="3.6" # 2.3 is the last version that supports python 3.5 connexion[aiohttp,swagger-ui] <= 2.3.0; python_version=="3.5" or python_version=="3.4" # connexion requires werkzeug but connexion < 2.4.0 does not install werkzeug @@ -10,3 +10,4 @@ aiohttp_jinja2 == 1.5.0 {{#featureCORS}} aiohttp_cors >= 0.7.0 {{/featureCORS}} +Flask < 2.3 \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/python-aiohttp/tox.mustache b/modules/openapi-generator/src/main/resources/python-aiohttp/tox.mustache index dfebe7024ae0..994b6210b451 100644 --- a/modules/openapi-generator/src/main/resources/python-aiohttp/tox.mustache +++ b/modules/openapi-generator/src/main/resources/python-aiohttp/tox.mustache @@ -8,4 +8,4 @@ deps=-r{toxinidir}/requirements.txt {toxinidir} commands= - {{^useNose}}pytest --cov={{#lambda.forwardslash}}{{{pythonSrcRoot}}}{{/lambda.forwardslash}}{{{packageName}}}{{/useNose}}{{#useNose}}nosetests{{/useNose}} + {{^useNose}}pytest --cov={{{packageName}}}{{/useNose}}{{#useNose}}nosetests{{/useNose}} diff --git a/modules/openapi-generator/src/main/resources/rust-server/client-operation.mustache b/modules/openapi-generator/src/main/resources/rust-server/client-operation.mustache index c858295ce903..f74833a77a51 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/client-operation.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/client-operation.mustache @@ -310,7 +310,7 @@ match auth_data { {{#authMethods}} {{#isBasicBasic}} - &AuthData::Basic(ref basic_header) => { + AuthData::Basic(basic_header) => { let auth = swagger::auth::Header(basic_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, @@ -322,7 +322,7 @@ }, {{/isBasicBasic}} {{#isBasicBearer}} - &AuthData::Bearer(ref bearer_header) => { + AuthData::Bearer(bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, @@ -335,7 +335,7 @@ {{/isBasicBearer}} {{#isOAuth}} {{^isBasicBearer}} - &AuthData::Bearer(ref bearer_header) => { + AuthData::Bearer(bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, diff --git a/modules/openapi-generator/src/main/resources/rust-server/models.mustache b/modules/openapi-generator/src/main/resources/rust-server/models.mustache index 6472dd601de5..4d383f658b07 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/models.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/models.mustache @@ -389,7 +389,7 @@ impl std::string::ToString for {{{classname}}} { {{/required}} {{^required}} self.{{{name}}}.as_ref().map(|{{{name}}}| { - vec![ + [ "{{{baseName}}}".to_string(), {{^isArray}} {{#isNullable}} diff --git a/modules/openapi-generator/src/main/resources/rust-server/server-operation.mustache b/modules/openapi-generator/src/main/resources/rust-server/server-operation.mustache index e7175b1745e9..f0ba616a9abc 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/server-operation.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/server-operation.mustache @@ -574,27 +574,27 @@ {{#vendorExtensions}} {{#x-produces-xml}} {{^x-has-namespace}} - let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); + let body_content = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); {{/x-has-namespace}} {{#x-has-namespace}} let mut namespaces = std::collections::BTreeMap::new(); // An empty string is used to indicate a global namespace in xmltree. namespaces.insert("".to_string(), {{{dataType}}}::NAMESPACE.to_string()); - let body = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize"); + let body_content = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize"); {{/x-has-namespace}} {{/x-produces-xml}} {{#x-produces-json}} - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); {{/x-produces-json}} {{#x-produces-bytes}} - let body = body.0; + let body_content = body.0; {{/x-produces-bytes}} {{#x-produces-plain-text}} - let body = body; + let body_content = body; {{/x-produces-plain-text}} {{/vendorExtensions}} - *response.body_mut() = Body::from(body); + *response.body_mut() = Body::from(body_content); {{/dataType}} }, {{/responses}} diff --git a/modules/openapi-generator/src/main/resources/zapier/model.mustache b/modules/openapi-generator/src/main/resources/zapier/model.mustache index cf0fb34c6777..0d9e0e787697 100644 --- a/modules/openapi-generator/src/main/resources/zapier/model.mustache +++ b/modules/openapi-generator/src/main/resources/zapier/model.mustache @@ -30,6 +30,9 @@ module.exports = { { key: `${keyPrefix}{{baseName}}`, label: `{{#description}}{{{.}}} - {{/description}}[${labelPrefix}{{baseName}}]`, + {{#required}} + required: true, + {{/required}} {{#isArray}} list: true, type: '{{#items}}{{baseType}}{{/items}}', @@ -56,6 +59,9 @@ module.exports = { { key: `${keyPrefix}{{baseName}}`,{{#items}}{{^isEnumRef}} label: `{{#description}}{{{.}}} - {{/description}}[${labelPrefix}{{baseName}}]`, + {{#required}} + required: true, + {{/required}} children: {{complexType}}.fields(`${keyPrefix}{{baseName}}${!isInput ? '[]' : ''}`, isInput, true), {{/isEnumRef}}{{#isEnumRef}} list: true, type: 'string', diff --git a/modules/openapi-generator/src/test/resources/3_0/jmeter/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/jmeter/petstore.yaml new file mode 100644 index 000000000000..0876844df34d --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/jmeter/petstore.yaml @@ -0,0 +1,751 @@ +openapi: 3.0.0 +servers: + - url: 'http://petstore.swagger.io/v2' +info: + description: >- + This is a sample server Petstore server. For this sample, you can use the api key + `special-key` to test the authorization filters. + version: 1.0.0 + title: OpenAPI Petstore + license: + name: Apache-2.0 + url: 'https://www.apache.org/licenses/LICENSE-2.0.html' +tags: + - name: pet + description: Everything about your Pets + - name: store + description: Access to Petstore orders + - name: user + description: Operations about user +paths: + /pet: + post: + tags: + - pet + summary: Add a new pet to the store + description: '' + operationId: addPet + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + $ref: '#/components/requestBodies/Pet' + put: + tags: + - pet + summary: Update an existing pet + description: '' + operationId: updatePet + externalDocs: + url: "http://petstore.swagger.io/v2/doc/updatePet" + description: "API documentation for the updatePet operation" + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid ID supplied + '404': + description: Pet not found + '405': + description: Validation exception + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + $ref: '#/components/requestBodies/Pet' + /pet/findByStatus: + get: + tags: + - pet + summary: Finds Pets by status + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - name: status + in: query + description: Status values that need to be considered for filter + required: true + style: form + explode: false + deprecated: true + schema: + type: array + items: + type: string + enum: + - available + - pending + - sold + default: available + responses: + '200': + description: successful operation + content: + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid status value + security: + - petstore_auth: + - 'read:pets' + /pet/findByTags: + get: + tags: + - pet + summary: Finds Pets by tags + description: >- + Multiple tags can be provided with comma separated strings. Use tag1, + tag2, tag3 for testing. + operationId: findPetsByTags + parameters: + - name: tags + in: query + description: Tags to filter by + required: true + style: form + explode: false + schema: + type: array + items: + type: string + responses: + '200': + description: successful operation + content: + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid tag value + security: + - petstore_auth: + - 'read:pets' + deprecated: true + '/pet/{petId}': + get: + tags: + - pet + summary: Find pet by ID + description: Returns a single pet + operationId: getPetById + parameters: + - name: petId + in: path + description: ID of pet to return + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid ID supplied + '404': + description: Pet not found + security: + - api_key: [] + post: + tags: + - pet + summary: Updates a pet in the store with form data + description: '' + operationId: updatePetWithForm + parameters: + - name: petId + in: path + description: ID of pet that needs to be updated + required: true + schema: + type: integer + format: int64 + responses: + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + delete: + tags: + - pet + summary: Deletes a pet + description: '' + operationId: deletePet + parameters: + - name: api_key + in: header + required: false + schema: + type: string + - name: petId + in: path + description: Pet id to delete + required: true + schema: + type: integer + format: int64 + responses: + '400': + description: Invalid pet value + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + '/pet/{petId}/uploadImage': + post: + tags: + - pet + summary: uploads an image + description: '' + operationId: uploadFile + parameters: + - name: petId + in: path + description: ID of pet to update + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + multipart/form-data: + schema: + type: object + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + type: string + format: binary + /store/inventory: + get: + tags: + - store + summary: Returns pet inventories by status + description: Returns a map of status codes to quantities + operationId: getInventory + responses: + '200': + description: successful operation + content: + application/json: + schema: + type: object + additionalProperties: + type: integer + format: int32 + security: + - api_key: [] + /store/order: + post: + tags: + - store + summary: Place an order for a pet + description: '' + operationId: placeOrder + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + '400': + description: Invalid Order + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Order' + description: order placed for purchasing the pet + required: true + '/store/order/{orderId}': + get: + tags: + - store + summary: Find purchase order by ID + description: >- + For valid response try integer IDs with value <= 5 or > 10. Other values + will generate exceptions + operationId: getOrderById + parameters: + - name: orderId + in: path + description: ID of pet that needs to be fetched + required: true + schema: + type: integer + format: int64 + minimum: 1 + maximum: 5 + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + '400': + description: Invalid ID supplied + '404': + description: Order not found + delete: + tags: + - store + summary: Delete purchase order by ID + description: >- + For valid response try integer IDs with value < 1000. Anything above + 1000 or nonintegers will generate API errors + operationId: deleteOrder + parameters: + - name: orderId + in: path + description: ID of the order that needs to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid ID supplied + '404': + description: Order not found + /user: + post: + tags: + - user + summary: Create user + description: This can only be done by the logged in user. + operationId: createUser + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + /user/createWithArray: + post: + tags: + - user + summary: Creates list of users with given input array + description: '' + operationId: createUsersWithArrayInput + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + $ref: '#/components/requestBodies/UserArray' + /user/createWithList: + post: + tags: + - user + summary: Creates list of users with given input array + description: '' + operationId: createUsersWithListInput + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + $ref: '#/components/requestBodies/UserArray' + /user/login: + get: + tags: + - user + summary: Logs user into the system + description: '' + operationId: loginUser + parameters: + - name: username + in: query + description: The user name for login + required: true + schema: + type: string + pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$' + - name: password + in: query + description: The password for login in clear text + required: true + schema: + type: string + responses: + '200': + description: successful operation + headers: + Set-Cookie: + description: >- + Cookie authentication key for use with the `api_key` + apiKey authentication. + schema: + type: string + example: AUTH_KEY=abcde12345; Path=/; HttpOnly + X-Rate-Limit: + description: calls per hour allowed by the user + schema: + type: integer + format: int32 + X-Expires-After: + description: date in UTC when token expires + schema: + type: string + format: date-time + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string + '400': + description: Invalid username/password supplied + /user/logout: + get: + tags: + - user + summary: Logs out current logged in user session + description: '' + operationId: logoutUser + responses: + default: + description: successful operation + security: + - api_key: [] + '/user/{username}': + get: + tags: + - user + summary: Get user by user name + description: '' + operationId: getUserByName + parameters: + - name: username + in: path + description: The name that needs to be fetched. Use user1 for testing. + required: true + schema: + type: string + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + '400': + description: Invalid username supplied + '404': + description: User not found + put: + tags: + - user + summary: Updated user + description: This can only be done by the logged in user. + operationId: updateUser + parameters: + - name: username + in: path + description: name that need to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid user supplied + '404': + description: User not found + security: + - api_key: [] + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Updated user object + required: true + delete: + tags: + - user + summary: Delete user + description: This can only be done by the logged in user. + operationId: deleteUser + parameters: + - name: username + in: path + description: The name that needs to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid username supplied + '404': + description: User not found + security: + - api_key: [] + /fake/operation_id_dollar_sign: + get: + tags: + - fake + summary: operationId dollar sign + description: operationId dollar sign + operationId: operationId$DollarSign + responses: + '400': + description: Invalid username supplied +externalDocs: + description: Find out more about Swagger + url: 'http://swagger.io' +components: + requestBodies: + UserArray: + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/User' + description: List of user object + required: true + Pet: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + required: true + securitySchemes: + petstore_auth: + type: oauth2 + flows: + implicit: + authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog' + scopes: + 'write:pets': modify pets in your account + 'read:pets': read your pets + api_key: + type: apiKey + name: api_key + in: header + schemas: + Order: + title: Pet Order + description: An order for a pets from the pet store + type: object + properties: + id: + type: integer + format: int64 + petId: + type: integer + format: int64 + quantity: + type: integer + format: int32 + shipDate: + type: string + format: date-time + status: + type: string + description: Order Status + enum: + - placed + - approved + - delivered + complete: + type: boolean + default: false + xml: + name: Order + Category: + title: Pet category + description: A category for a pet + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$' + xml: + name: Category + User: + title: a User + description: A User who is purchasing from the pet store + type: object + properties: + id: + type: integer + format: int64 + username: + type: string + firstName: + type: string + lastName: + type: string + email: + type: string + password: + type: string + phone: + type: string + userStatus: + type: integer + format: int32 + description: User Status + xml: + name: User + Tag: + title: Pet Tag + description: A tag for a pet + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + xml: + name: Tag + Pet: + title: a Pet + description: A pet for sale in the pet store + type: object + required: + - name + - photoUrls + properties: + id: + type: integer + format: int64 + category: + $ref: '#/components/schemas/Category' + name: + type: string + example: doggie + photoUrls: + type: array + xml: + name: photoUrl + wrapped: true + items: + type: string + tags: + type: array + xml: + name: tag + wrapped: true + items: + $ref: '#/components/schemas/Tag' + status: + type: string + description: pet status in the store + deprecated: true + enum: + - available + - pending + - sold + xml: + name: Pet + ApiResponse: + title: An uploaded response + description: Describes the result of uploading an image resource + type: object + properties: + code: + type: integer + format: int32 + type: + type: string + message: + type: string diff --git a/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java index 5dcbcce005b3..81b1cc166d17 100644 --- a/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java @@ -55,6 +55,7 @@ import java.util.Arrays; import java.util.ArrayList; import java.util.Date; +import java.util.function.Supplier; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -305,6 +306,20 @@ public ApiClient setBearerToken(String bearerToken) { throw new RuntimeException("No Bearer authentication configured!"); } + /** + * Helper method to set the supplier of access tokens for Bearer authentication. + * + * @param tokenSupplier the token supplier function + */ + public void setBearerToken(Supplier tokenSupplier) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBearerAuth) { + ((HttpBearerAuth) auth).setBearerToken(tokenSupplier); + return; + } + } + throw new RuntimeException("No Bearer authentication configured!"); + } /** * Helper method to set username for the first HTTP basic authentication. diff --git a/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index 8c7cdd743e18..0f1f505b7de3 100644 --- a/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -15,13 +15,15 @@ import org.openapitools.client.Pair; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -33,7 +35,7 @@ public HttpBearerAuth(String scheme) { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -42,12 +44,22 @@ public String getBearerToken() { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams) { - if(bearerToken == null) { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); + if (bearerToken == null) { return; } diff --git a/samples/client/echo_api/java/apache-httpclient/src/test/java/org/openapitools/client/api/AuthApiTest.java b/samples/client/echo_api/java/apache-httpclient/src/test/java/org/openapitools/client/api/AuthApiTest.java index ac4fa203fbc5..7fc2956fce23 100644 --- a/samples/client/echo_api/java/apache-httpclient/src/test/java/org/openapitools/client/api/AuthApiTest.java +++ b/samples/client/echo_api/java/apache-httpclient/src/test/java/org/openapitools/client/api/AuthApiTest.java @@ -28,7 +28,6 @@ /** * API tests for AuthApi */ -@Ignore public class AuthApiTest { private final AuthApi api = new AuthApi(); @@ -47,4 +46,23 @@ public void testAuthHttpBasicTest() throws ApiException { // TODO: test validations } + /** + * To test HTTP bearer authentication + * + * To test HTTP bearer authentication + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void testAuthHttpBearerTest() throws ApiException { + String response; + api.getApiClient().setBearerToken("fixed token"); + response = api.testAuthHttpBearer(); + Assert.assertTrue(response.contains("Authorization: Bearer fixed token")); + + api.getApiClient().setBearerToken(() -> "dynamic token"); + response = api.testAuthHttpBearer(); + Assert.assertTrue(response.contains("Authorization: Bearer dynamic token")); + } } diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/ApiClient.java index 44e015746bcb..c4f0909810ff 100644 --- a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/ApiClient.java @@ -2,6 +2,7 @@ import java.util.LinkedHashMap; import java.util.Map; +import java.util.function.Supplier; import java.util.logging.Level; import java.util.logging.Logger; @@ -155,6 +156,15 @@ public void setBearerToken(String bearerToken) { apiAuthorization.setBearerToken(bearerToken); } + /** + * Helper method to configure the supplier of bearer tokens. + * @param tokenSupplier the supplier of bearer tokens. + */ + public void setBearerToken(Supplier tokenSupplier) { + HttpBearerAuth apiAuthorization = getAuthorization(HttpBearerAuth.class); + apiAuthorization.setBearerToken(tokenSupplier); + } + /** * Helper method to configure the first api key found * @param apiKey API key diff --git a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index d4c9cbe6361e..43c1a722ad9f 100644 --- a/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/echo_api/java/feign-gson/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -2,13 +2,15 @@ import feign.RequestInterceptor; import feign.RequestTemplate; +import java.util.Optional; +import java.util.function.Supplier; /** * An interceptor that adds the request header needed to use HTTP bearer authentication. */ public class HttpBearerAuth implements RequestInterceptor { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -16,21 +18,35 @@ public HttpBearerAuth(String scheme) { /** * Gets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** * Sets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void apply(RequestTemplate template) { - if(bearerToken == null) { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); + if (bearerToken == null) { return; } diff --git a/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/api/AuthApiTest.java b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/api/AuthApiTest.java index 2c33d9c32dce..f53e1f75b5df 100644 --- a/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/api/AuthApiTest.java +++ b/samples/client/echo_api/java/feign-gson/src/test/java/org/openapitools/client/api/AuthApiTest.java @@ -1,5 +1,7 @@ package org.openapitools.client.api; +import feign.codec.StringDecoder; +import org.junit.jupiter.api.Assertions; import org.openapitools.client.ApiClient; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeEach; @@ -37,4 +39,28 @@ void testAuthHttpBasicTest() { } + /** + * To test HTTP bearer authentication + * + * To test HTTP bearer authentication + */ + @Test + void testAuthHttpBearerTest() { + ApiClient client = new ApiClient("http_bearer_auth"); + client.getFeignBuilder().decoder(new StringDecoder()); + { + client.setBearerToken("fixed token"); + AuthApi api = client.buildClient(AuthApi.class); + String response = api.testAuthHttpBearer(); + Assertions.assertTrue(response.contains("Authorization: Bearer fixed token")); + } + { + client.setBearerToken(() -> "dynamic token"); + AuthApi api = client.buildClient(AuthApi.class); + String response = api.testAuthHttpBearer(); + Assertions.assertTrue(response.contains("Authorization: Bearer dynamic token")); + } + } + + } diff --git a/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/api/AuthApiTest.java b/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/api/AuthApiTest.java index 3e6f3a79b758..35d1b0316c71 100644 --- a/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/api/AuthApiTest.java +++ b/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/api/AuthApiTest.java @@ -49,4 +49,20 @@ public void testAuthHttpBasicTest() throws ApiException { // TODO: test validations } + /** + * To test HTTP bearer authentication + * + * To test HTTP bearer authentication + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void testAuthHttpBearerTest() throws ApiException { + String response = + api.testAuthHttpBearer(); + + // TODO: test validations + } + } diff --git a/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java index f89aa2664b7e..faac0e455a78 100644 --- a/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java @@ -47,6 +47,7 @@ import java.util.*; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -386,14 +387,23 @@ public Authentication getAuthentication(String authName) { return authentications.get(authName); } - /** - * Helper method to set access token for the first Bearer authentication. - * @param bearerToken Bearer token - */ + /** + * Helper method to set access token for the first Bearer authentication. + * @param bearerToken Bearer token + */ public void setBearerToken(String bearerToken) { + setBearerToken(() -> bearerToken); + } + + /** + * Helper method to set the supplier of access tokens for Bearer authentication. + * + * @param tokenSupplier The supplier of bearer tokens + */ + public void setBearerToken(Supplier tokenSupplier) { for (Authentication auth : authentications.values()) { if (auth instanceof HttpBearerAuth) { - ((HttpBearerAuth) auth).setBearerToken(bearerToken); + ((HttpBearerAuth) auth).setBearerToken(tokenSupplier); return; } } diff --git a/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index 7eb3566fcce9..5147daf61c0e 100644 --- a/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -17,13 +17,15 @@ import org.openapitools.client.Pair; import java.net.URI; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -35,7 +37,7 @@ public HttpBearerAuth(String scheme) { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -44,12 +46,22 @@ public String getBearerToken() { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams, String payload, String method, URI uri) throws ApiException { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); if (bearerToken == null) { return; } diff --git a/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/api/AuthApiTest.java b/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/api/AuthApiTest.java index 7d5e92b75a50..69083155b5af 100644 --- a/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/api/AuthApiTest.java +++ b/samples/client/echo_api/java/okhttp-gson/src/test/java/org/openapitools/client/api/AuthApiTest.java @@ -13,6 +13,8 @@ package org.openapitools.client.api; +import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.openapitools.client.ApiException; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -21,11 +23,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.openapitools.client.ApiResponse; /** * API tests for AuthApi */ -@Disabled public class AuthApiTest { private final AuthApi api = new AuthApi(); @@ -43,4 +45,23 @@ public void testAuthHttpBasicTest() throws ApiException { // TODO: test validations } + /** + * To test HTTP bearer authentication + * + * To test HTTP bearer authentication + * + * @throws ApiException if the Api call fails + */ + @Test + public void testAuthHttpBearerTest() throws ApiException { + String response; + api.getApiClient().setBearerToken("fixed token"); + response = api.testAuthHttpBearer(); + Assertions.assertTrue(response.contains("Authorization: Bearer fixed token")); + + api.getApiClient().setBearerToken(() -> "dynamic token"); + response = api.testAuthHttpBearer(); + Assertions.assertTrue(response.contains("Authorization: Bearer dynamic token")); + } + } diff --git a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java index d399c723c4bf..220e61461c76 100644 --- a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java @@ -156,18 +156,18 @@ public Authentication getAuthentication(String authName) { } /** - * Helper method to set token for HTTP bearer authentication. + * Helper method to set access token for the first Bearer authentication. * - * @param bearerToken the token + * @param bearerToken Bearer token */ public void setBearerToken(String bearerToken) { setBearerToken(() -> bearerToken); } /** - * Helper method to set the token supplier for HTTP bearer authentication. + * Helper method to set the supplier of access tokens for Bearer authentication. * - * @param tokenSupplier the token supplier function + * @param tokenSupplier The supplier of bearer tokens */ public void setBearerToken(Supplier tokenSupplier) { for (Authentication auth : authentications.values()) { diff --git a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index 51d5e3278ef7..4678c06efd7c 100644 --- a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -14,14 +14,29 @@ public HttpBearerAuth(String scheme) { this.scheme = scheme; } + /** + * Gets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @return The bearer token + */ public String getBearerToken() { return tokenSupplier.get(); } + /** + * Sets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param bearerToken The bearer token to send in the Authorization header + */ public void setBearerToken(String bearerToken) { this.tokenSupplier = () -> bearerToken; } - + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ public void setBearerToken(Supplier tokenSupplier) { this.tokenSupplier = tokenSupplier; } diff --git a/samples/client/echo_api/php-nextgen/src/Api/AuthApi.php b/samples/client/echo_api/php-nextgen/src/Api/AuthApi.php index e79fd9ecf3df..9a00878c8a4e 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/AuthApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/AuthApi.php @@ -133,7 +133,7 @@ public function getConfig(): Configuration * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testAuthHttpBasic'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -152,7 +152,7 @@ public function testAuthHttpBasic( * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testAuthHttpBasic'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -204,7 +204,19 @@ public function testAuthHttpBasicWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -221,7 +233,19 @@ public function testAuthHttpBasicWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -410,7 +434,7 @@ public function testAuthHttpBasicRequest( * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testAuthHttpBearer'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -429,7 +453,7 @@ public function testAuthHttpBearer( * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testAuthHttpBearer'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -481,7 +505,19 @@ public function testAuthHttpBearerWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -498,7 +534,19 @@ public function testAuthHttpBearerWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } diff --git a/samples/client/echo_api/php-nextgen/src/Api/BodyApi.php b/samples/client/echo_api/php-nextgen/src/Api/BodyApi.php index 6b6ed8287a86..5e3fbb3d8ff8 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/BodyApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/BodyApi.php @@ -151,7 +151,7 @@ public function getConfig(): Configuration * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBinaryGif'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \SplFileObject */ @@ -170,7 +170,7 @@ public function testBinaryGif( * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBinaryGif'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \SplFileObject, HTTP status code, HTTP response headers (array of strings) */ @@ -222,7 +222,19 @@ public function testBinaryGifWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\SplFileObject' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -239,7 +251,19 @@ public function testBinaryGifWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -425,7 +449,7 @@ public function testBinaryGifRequest( * @param \SplFileObject|null $body body (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyApplicationOctetstreamBinary'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -446,7 +470,7 @@ public function testBodyApplicationOctetstreamBinary( * @param \SplFileObject|null $body (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyApplicationOctetstreamBinary'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -499,7 +523,19 @@ public function testBodyApplicationOctetstreamBinaryWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -516,7 +552,19 @@ public function testBodyApplicationOctetstreamBinaryWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -716,7 +764,7 @@ public function testBodyApplicationOctetstreamBinaryRequest( * @param \SplFileObject[] $files files (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyMultipartFormdataArrayOfBinary'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -737,7 +785,7 @@ public function testBodyMultipartFormdataArrayOfBinary( * @param \SplFileObject[] $files (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyMultipartFormdataArrayOfBinary'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -790,7 +838,19 @@ public function testBodyMultipartFormdataArrayOfBinaryWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -807,7 +867,19 @@ public function testBodyMultipartFormdataArrayOfBinaryWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1018,7 +1090,7 @@ public function testBodyMultipartFormdataArrayOfBinaryRequest( * @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyAllOfPet'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\Pet */ @@ -1039,7 +1111,7 @@ public function testEchoBodyAllOfPet( * @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyAllOfPet'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings) */ @@ -1092,7 +1164,19 @@ public function testEchoBodyAllOfPetWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\Pet' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1109,7 +1193,19 @@ public function testEchoBodyAllOfPetWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1309,7 +1405,7 @@ public function testEchoBodyAllOfPetRequest( * @param object|null $body Free form object (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyFreeFormObjectResponseString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -1330,7 +1426,7 @@ public function testEchoBodyFreeFormObjectResponseString( * @param object|null $body Free form object (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyFreeFormObjectResponseString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -1383,7 +1479,19 @@ public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1400,7 +1508,19 @@ public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1600,7 +1720,7 @@ public function testEchoBodyFreeFormObjectResponseStringRequest( * @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyPet'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\Pet */ @@ -1621,7 +1741,7 @@ public function testEchoBodyPet( * @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyPet'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings) */ @@ -1674,7 +1794,19 @@ public function testEchoBodyPetWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\Pet' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1691,7 +1823,19 @@ public function testEchoBodyPetWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1891,7 +2035,7 @@ public function testEchoBodyPetRequest( * @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyPetResponseString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -1912,7 +2056,7 @@ public function testEchoBodyPetResponseString( * @param \OpenAPI\Client\Model\Pet|null $pet Pet object that needs to be added to the store (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyPetResponseString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -1965,7 +2109,19 @@ public function testEchoBodyPetResponseStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1982,7 +2138,19 @@ public function testEchoBodyPetResponseStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -2182,7 +2350,7 @@ public function testEchoBodyPetResponseStringRequest( * @param \OpenAPI\Client\Model\Tag|null $tag Tag object (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyTagResponseString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -2203,7 +2371,7 @@ public function testEchoBodyTagResponseString( * @param \OpenAPI\Client\Model\Tag|null $tag Tag object (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEchoBodyTagResponseString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -2256,7 +2424,19 @@ public function testEchoBodyTagResponseStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -2273,7 +2453,19 @@ public function testEchoBodyTagResponseStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } diff --git a/samples/client/echo_api/php-nextgen/src/Api/FormApi.php b/samples/client/echo_api/php-nextgen/src/Api/FormApi.php index d1bf5dd5f3d3..7b05d269b342 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/FormApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/FormApi.php @@ -136,7 +136,7 @@ public function getConfig(): Configuration * @param string|null $string_form string_form (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testFormIntegerBooleanString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -161,7 +161,7 @@ public function testFormIntegerBooleanString( * @param string|null $string_form (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testFormIntegerBooleanString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -216,7 +216,19 @@ public function testFormIntegerBooleanStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -233,7 +245,19 @@ public function testFormIntegerBooleanStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -457,7 +481,7 @@ public function testFormIntegerBooleanStringRequest( * @param string|null $name name (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testFormOneof'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -488,7 +512,7 @@ public function testFormOneof( * @param string|null $name (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testFormOneof'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -546,7 +570,19 @@ public function testFormOneofWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -563,7 +599,19 @@ public function testFormOneofWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } diff --git a/samples/client/echo_api/php-nextgen/src/Api/HeaderApi.php b/samples/client/echo_api/php-nextgen/src/Api/HeaderApi.php index e8518ef9f4bb..ccd1934afbc0 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/HeaderApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/HeaderApi.php @@ -135,7 +135,7 @@ public function getConfig(): Configuration * @param StringEnumRef|null $enum_ref_string_header enum_ref_string_header (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testHeaderIntegerBooleanStringEnums'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -164,7 +164,7 @@ public function testHeaderIntegerBooleanStringEnums( * @param StringEnumRef|null $enum_ref_string_header (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testHeaderIntegerBooleanStringEnums'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -221,7 +221,19 @@ public function testHeaderIntegerBooleanStringEnumsWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -238,7 +250,19 @@ public function testHeaderIntegerBooleanStringEnumsWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } diff --git a/samples/client/echo_api/php-nextgen/src/Api/PathApi.php b/samples/client/echo_api/php-nextgen/src/Api/PathApi.php index 89abd9004326..d9c9352b144b 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/PathApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/PathApi.php @@ -134,7 +134,7 @@ public function getConfig(): Configuration * @param StringEnumRef $enum_ref_string_path enum_ref_string_path (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -161,7 +161,7 @@ public function testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathE * @param StringEnumRef $enum_ref_string_path (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -217,7 +217,19 @@ public function testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathE } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -234,7 +246,19 @@ public function testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathE } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } diff --git a/samples/client/echo_api/php-nextgen/src/Api/QueryApi.php b/samples/client/echo_api/php-nextgen/src/Api/QueryApi.php index 4f556ae7814e..49a6c0f981d0 100644 --- a/samples/client/echo_api/php-nextgen/src/Api/QueryApi.php +++ b/samples/client/echo_api/php-nextgen/src/Api/QueryApi.php @@ -153,7 +153,7 @@ public function getConfig(): Configuration * @param StringEnumRef|null $enum_ref_string_query enum_ref_string_query (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEnumRefString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -176,7 +176,7 @@ public function testEnumRefString( * @param StringEnumRef|null $enum_ref_string_query (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEnumRefString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -230,7 +230,19 @@ public function testEnumRefStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -247,7 +259,19 @@ public function testEnumRefStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -467,7 +491,7 @@ public function testEnumRefStringRequest( * @param string|null $string_query string_query (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryDatetimeDateString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -492,7 +516,7 @@ public function testQueryDatetimeDateString( * @param string|null $string_query (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryDatetimeDateString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -547,7 +571,19 @@ public function testQueryDatetimeDateStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -564,7 +600,19 @@ public function testQueryDatetimeDateStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -800,7 +848,7 @@ public function testQueryDatetimeDateStringRequest( * @param string|null $string_query string_query (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryIntegerBooleanString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -825,7 +873,7 @@ public function testQueryIntegerBooleanString( * @param string|null $string_query (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryIntegerBooleanString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -880,7 +928,19 @@ public function testQueryIntegerBooleanStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -897,7 +957,19 @@ public function testQueryIntegerBooleanStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1131,7 +1203,7 @@ public function testQueryIntegerBooleanStringRequest( * @param Pet|null $query_object query_object (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleDeepObjectExplodeTrueObject'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -1152,7 +1224,7 @@ public function testQueryStyleDeepObjectExplodeTrueObject( * @param Pet|null $query_object (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleDeepObjectExplodeTrueObject'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -1205,7 +1277,19 @@ public function testQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1222,7 +1306,19 @@ public function testQueryStyleDeepObjectExplodeTrueObjectWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1424,7 +1520,7 @@ public function testQueryStyleDeepObjectExplodeTrueObjectRequest( * @param TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter|null $query_object query_object (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleDeepObjectExplodeTrueObjectAllOf'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -1445,7 +1541,7 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOf( * @param TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter|null $query_object (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleDeepObjectExplodeTrueObjectAllOf'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -1498,7 +1594,19 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1515,7 +1623,19 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1717,7 +1837,7 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfRequest( * @param TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter|null $query_object query_object (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeTrueArrayString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -1738,7 +1858,7 @@ public function testQueryStyleFormExplodeTrueArrayString( * @param TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter|null $query_object (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeTrueArrayString'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -1791,7 +1911,19 @@ public function testQueryStyleFormExplodeTrueArrayStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1808,7 +1940,19 @@ public function testQueryStyleFormExplodeTrueArrayStringWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -2010,7 +2154,7 @@ public function testQueryStyleFormExplodeTrueArrayStringRequest( * @param Pet|null $query_object query_object (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeTrueObject'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -2031,7 +2175,7 @@ public function testQueryStyleFormExplodeTrueObject( * @param Pet|null $query_object (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeTrueObject'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -2084,7 +2228,19 @@ public function testQueryStyleFormExplodeTrueObjectWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -2101,7 +2257,19 @@ public function testQueryStyleFormExplodeTrueObjectWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -2303,7 +2471,7 @@ public function testQueryStyleFormExplodeTrueObjectRequest( * @param DataQuery|null $query_object query_object (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeTrueObjectAllOf'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -2324,7 +2492,7 @@ public function testQueryStyleFormExplodeTrueObjectAllOf( * @param DataQuery|null $query_object (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryStyleFormExplodeTrueObjectAllOf'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -2377,7 +2545,19 @@ public function testQueryStyleFormExplodeTrueObjectAllOfWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -2394,7 +2574,19 @@ public function testQueryStyleFormExplodeTrueObjectAllOfWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } diff --git a/samples/client/echo_api/php-nextgen/src/ObjectSerializer.php b/samples/client/echo_api/php-nextgen/src/ObjectSerializer.php index d998ebb2ad8f..b71e92702097 100644 --- a/samples/client/echo_api/php-nextgen/src/ObjectSerializer.php +++ b/samples/client/echo_api/php-nextgen/src/ObjectSerializer.php @@ -427,10 +427,7 @@ public static function deserialize(mixed $data, string $class, array $httpHeader return $deserialized; } - if ($class === 'object') { - settype($data, 'array'); - return $data; - } elseif ($class === 'mixed') { + if ($class === 'mixed') { settype($data, gettype($data)); return $data; } diff --git a/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/ApiClient.java index 424c5cbc5b67..ccbf706598db 100644 --- a/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/ApiClient.java @@ -47,6 +47,7 @@ import java.util.*; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index 0f030d7b1910..255c1d77d45f 100644 --- a/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -17,13 +17,15 @@ import org.openapitools.client.Pair; import java.net.URI; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -35,7 +37,7 @@ public HttpBearerAuth(String scheme) { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -44,12 +46,22 @@ public String getBearerToken() { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams, String payload, String method, URI uri) throws ApiException { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); if (bearerToken == null) { return; } diff --git a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/ApiClient.java index b382d2da2c9d..f61594f02b96 100644 --- a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/ApiClient.java @@ -47,6 +47,7 @@ import java.util.*; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index 96f57427e9fd..ba32ab551f31 100644 --- a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -17,13 +17,15 @@ import org.openapitools.client.Pair; import java.net.URI; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -35,7 +37,7 @@ public HttpBearerAuth(String scheme) { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -44,12 +46,22 @@ public String getBearerToken() { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams, String payload, String method, URI uri) throws ApiException { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); if (bearerToken == null) { return; } diff --git a/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index 51d5e3278ef7..4678c06efd7c 100644 --- a/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -14,14 +14,29 @@ public HttpBearerAuth(String scheme) { this.scheme = scheme; } + /** + * Gets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @return The bearer token + */ public String getBearerToken() { return tokenSupplier.get(); } + /** + * Sets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param bearerToken The bearer token to send in the Authorization header + */ public void setBearerToken(String bearerToken) { this.tokenSupplier = () -> bearerToken; } - + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ public void setBearerToken(Supplier tokenSupplier) { this.tokenSupplier = tokenSupplier; } diff --git a/samples/client/petstore/csharp/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/petstore/csharp/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs index f6e3372563a8..b814e218a612 100644 --- a/samples/client/petstore/csharp/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs +++ b/samples/client/petstore/csharp/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs @@ -94,7 +94,18 @@ public async Task Deserialize(HttpResponseMessage response) /// Object representation of the JSON string. internal async Task Deserialize(HttpResponseMessage response, Type type) { - IList headers = response.Headers.Select(x => x.Key + "=" + x.Value).ToList(); + IList headers = new List(); + // process response headers, e.g. Access-Control-Allow-Methods + foreach (var responseHeader in response.Headers) + { + headers.Add(responseHeader.Key + "=" + ClientUtils.ParameterToString(responseHeader.Value)); + } + + // process response content headers, e.g. Content-Type + foreach (var responseHeader in response.Content.Headers) + { + headers.Add(responseHeader.Key + "=" + ClientUtils.ParameterToString(responseHeader.Value)); + } if (type == typeof(byte[])) // return byte array { diff --git a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java index 1a938cde9593..d92b2555617f 100644 --- a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java @@ -55,6 +55,7 @@ import java.util.Arrays; import java.util.ArrayList; import java.util.Date; +import java.util.function.Supplier; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -353,6 +354,20 @@ public ApiClient setBearerToken(String bearerToken) { throw new RuntimeException("No Bearer authentication configured!"); } + /** + * Helper method to set the supplier of access tokens for Bearer authentication. + * + * @param tokenSupplier the token supplier function + */ + public void setBearerToken(Supplier tokenSupplier) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBearerAuth) { + ((HttpBearerAuth) auth).setBearerToken(tokenSupplier); + return; + } + } + throw new RuntimeException("No Bearer authentication configured!"); + } /** * Helper method to set username for the first HTTP basic authentication. diff --git a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index e9d4c678963a..a0083b8cf989 100644 --- a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -15,13 +15,15 @@ import org.openapitools.client.Pair; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -33,7 +35,7 @@ public HttpBearerAuth(String scheme) { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -42,12 +44,22 @@ public String getBearerToken() { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams) { - if(bearerToken == null) { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); + if (bearerToken == null) { return; } diff --git a/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/ApiClient.java index 020dc860b05a..5a8e49298187 100644 --- a/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/ApiClient.java @@ -2,6 +2,7 @@ import java.util.LinkedHashMap; import java.util.Map; +import java.util.function.Supplier; import java.util.logging.Level; import java.util.logging.Logger; @@ -206,6 +207,15 @@ public void setBearerToken(String bearerToken) { apiAuthorization.setBearerToken(bearerToken); } + /** + * Helper method to configure the supplier of bearer tokens. + * @param tokenSupplier the supplier of bearer tokens. + */ + public void setBearerToken(Supplier tokenSupplier) { + HttpBearerAuth apiAuthorization = getAuthorization(HttpBearerAuth.class); + apiAuthorization.setBearerToken(tokenSupplier); + } + /** * Helper method to configure the first api key found * @param apiKey API key diff --git a/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index d4c9cbe6361e..43c1a722ad9f 100644 --- a/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -2,13 +2,15 @@ import feign.RequestInterceptor; import feign.RequestTemplate; +import java.util.Optional; +import java.util.function.Supplier; /** * An interceptor that adds the request header needed to use HTTP bearer authentication. */ public class HttpBearerAuth implements RequestInterceptor { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -16,21 +18,35 @@ public HttpBearerAuth(String scheme) { /** * Gets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** * Sets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void apply(RequestTemplate template) { - if(bearerToken == null) { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); + if (bearerToken == null) { return; } diff --git a/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/ApiClient.java index 43f12eea390c..f62a3ba56080 100644 --- a/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/ApiClient.java @@ -2,6 +2,7 @@ import java.util.LinkedHashMap; import java.util.Map; +import java.util.function.Supplier; import java.util.logging.Level; import java.util.logging.Logger; @@ -212,6 +213,15 @@ public void setBearerToken(String bearerToken) { apiAuthorization.setBearerToken(bearerToken); } + /** + * Helper method to configure the supplier of bearer tokens. + * @param tokenSupplier the supplier of bearer tokens. + */ + public void setBearerToken(Supplier tokenSupplier) { + HttpBearerAuth apiAuthorization = getAuthorization(HttpBearerAuth.class); + apiAuthorization.setBearerToken(tokenSupplier); + } + /** * Helper method to configure the first api key found * @param apiKey API key diff --git a/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index d4c9cbe6361e..43c1a722ad9f 100644 --- a/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -2,13 +2,15 @@ import feign.RequestInterceptor; import feign.RequestTemplate; +import java.util.Optional; +import java.util.function.Supplier; /** * An interceptor that adds the request header needed to use HTTP bearer authentication. */ public class HttpBearerAuth implements RequestInterceptor { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -16,21 +18,35 @@ public HttpBearerAuth(String scheme) { /** * Gets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** * Sets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void apply(RequestTemplate template) { - if(bearerToken == null) { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); + if (bearerToken == null) { return; } diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/ApiClient.java index 6d1cc62db7e7..08a6cfe9ddd5 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/ApiClient.java @@ -49,6 +49,7 @@ import java.util.*; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index b282a35e1a1f..627c09689cf5 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -17,13 +17,15 @@ import org.openapitools.client.Pair; import java.net.URI; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -35,7 +37,7 @@ public HttpBearerAuth(String scheme) { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -44,12 +46,22 @@ public String getBearerToken() { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams, String payload, String method, URI uri) throws ApiException { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); if (bearerToken == null) { return; } diff --git a/samples/client/petstore/java/okhttp-gson-awsv4signature/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson-awsv4signature/src/main/java/org/openapitools/client/ApiClient.java index 21ac39664037..209f378884b6 100644 --- a/samples/client/petstore/java/okhttp-gson-awsv4signature/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson-awsv4signature/src/main/java/org/openapitools/client/ApiClient.java @@ -49,6 +49,7 @@ import java.util.*; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/samples/client/petstore/java/okhttp-gson-awsv4signature/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/okhttp-gson-awsv4signature/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index b282a35e1a1f..627c09689cf5 100644 --- a/samples/client/petstore/java/okhttp-gson-awsv4signature/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/okhttp-gson-awsv4signature/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -17,13 +17,15 @@ import org.openapitools.client.Pair; import java.net.URI; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -35,7 +37,7 @@ public HttpBearerAuth(String scheme) { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -44,12 +46,22 @@ public String getBearerToken() { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams, String payload, String method, URI uri) throws ApiException { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); if (bearerToken == null) { return; } diff --git a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/ApiClient.java index 3b744150e977..01dc3cbbbf92 100644 --- a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/ApiClient.java @@ -55,6 +55,7 @@ import java.util.*; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index 460ad224963c..e6ae1d454c79 100644 --- a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -17,13 +17,15 @@ import org.openapitools.client.Pair; import java.net.URI; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -35,7 +37,7 @@ public HttpBearerAuth(String scheme) { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -44,12 +46,22 @@ public String getBearerToken() { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams, String payload, String method, URI uri) throws ApiException { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); if (bearerToken == null) { return; } diff --git a/samples/client/petstore/java/okhttp-gson-group-parameter/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson-group-parameter/src/main/java/org/openapitools/client/ApiClient.java index 6d1cc62db7e7..08a6cfe9ddd5 100644 --- a/samples/client/petstore/java/okhttp-gson-group-parameter/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson-group-parameter/src/main/java/org/openapitools/client/ApiClient.java @@ -49,6 +49,7 @@ import java.util.*; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/samples/client/petstore/java/okhttp-gson-group-parameter/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/okhttp-gson-group-parameter/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index b282a35e1a1f..627c09689cf5 100644 --- a/samples/client/petstore/java/okhttp-gson-group-parameter/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/okhttp-gson-group-parameter/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -17,13 +17,15 @@ import org.openapitools.client.Pair; import java.net.URI; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -35,7 +37,7 @@ public HttpBearerAuth(String scheme) { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -44,12 +46,22 @@ public String getBearerToken() { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams, String payload, String method, URI uri) throws ApiException { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); if (bearerToken == null) { return; } diff --git a/samples/client/petstore/java/okhttp-gson-nullable-required/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson-nullable-required/src/main/java/org/openapitools/client/ApiClient.java index 3f95f4861622..bccc06dde46a 100644 --- a/samples/client/petstore/java/okhttp-gson-nullable-required/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson-nullable-required/src/main/java/org/openapitools/client/ApiClient.java @@ -49,6 +49,7 @@ import java.util.*; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/samples/client/petstore/java/okhttp-gson-nullable-required/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/okhttp-gson-nullable-required/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index b282a35e1a1f..627c09689cf5 100644 --- a/samples/client/petstore/java/okhttp-gson-nullable-required/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/okhttp-gson-nullable-required/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -17,13 +17,15 @@ import org.openapitools.client.Pair; import java.net.URI; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -35,7 +37,7 @@ public HttpBearerAuth(String scheme) { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -44,12 +46,22 @@ public String getBearerToken() { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams, String payload, String method, URI uri) throws ApiException { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); if (bearerToken == null) { return; } diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/ApiClient.java index ccc405823612..f211421d38b4 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/ApiClient.java @@ -49,6 +49,7 @@ import java.util.*; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index 460ad224963c..e6ae1d454c79 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -17,13 +17,15 @@ import org.openapitools.client.Pair; import java.net.URI; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -35,7 +37,7 @@ public HttpBearerAuth(String scheme) { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -44,12 +46,22 @@ public String getBearerToken() { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams, String payload, String method, URI uri) throws ApiException { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); if (bearerToken == null) { return; } diff --git a/samples/client/petstore/java/okhttp-gson-swagger1/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson-swagger1/src/main/java/org/openapitools/client/ApiClient.java index 6d1cc62db7e7..08a6cfe9ddd5 100644 --- a/samples/client/petstore/java/okhttp-gson-swagger1/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson-swagger1/src/main/java/org/openapitools/client/ApiClient.java @@ -49,6 +49,7 @@ import java.util.*; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/samples/client/petstore/java/okhttp-gson-swagger1/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/okhttp-gson-swagger1/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index b282a35e1a1f..627c09689cf5 100644 --- a/samples/client/petstore/java/okhttp-gson-swagger1/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/okhttp-gson-swagger1/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -17,13 +17,15 @@ import org.openapitools.client.Pair; import java.net.URI; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -35,7 +37,7 @@ public HttpBearerAuth(String scheme) { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -44,12 +46,22 @@ public String getBearerToken() { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams, String payload, String method, URI uri) throws ApiException { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); if (bearerToken == null) { return; } diff --git a/samples/client/petstore/java/okhttp-gson-swagger2/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson-swagger2/src/main/java/org/openapitools/client/ApiClient.java index 6d1cc62db7e7..08a6cfe9ddd5 100644 --- a/samples/client/petstore/java/okhttp-gson-swagger2/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson-swagger2/src/main/java/org/openapitools/client/ApiClient.java @@ -49,6 +49,7 @@ import java.util.*; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/samples/client/petstore/java/okhttp-gson-swagger2/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/okhttp-gson-swagger2/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index b282a35e1a1f..627c09689cf5 100644 --- a/samples/client/petstore/java/okhttp-gson-swagger2/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/okhttp-gson-swagger2/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -17,13 +17,15 @@ import org.openapitools.client.Pair; import java.net.URI; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -35,7 +37,7 @@ public HttpBearerAuth(String scheme) { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -44,12 +46,22 @@ public String getBearerToken() { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams, String payload, String method, URI uri) throws ApiException { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); if (bearerToken == null) { return; } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java index 8593e66829db..b74876964ed0 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java @@ -49,6 +49,7 @@ import java.util.*; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -510,14 +511,23 @@ public Authentication getAuthentication(String authName) { return authentications.get(authName); } - /** - * Helper method to set access token for the first Bearer authentication. - * @param bearerToken Bearer token - */ + /** + * Helper method to set access token for the first Bearer authentication. + * @param bearerToken Bearer token + */ public void setBearerToken(String bearerToken) { + setBearerToken(() -> bearerToken); + } + + /** + * Helper method to set the supplier of access tokens for Bearer authentication. + * + * @param tokenSupplier The supplier of bearer tokens + */ + public void setBearerToken(Supplier tokenSupplier) { for (Authentication auth : authentications.values()) { if (auth instanceof HttpBearerAuth) { - ((HttpBearerAuth) auth).setBearerToken(bearerToken); + ((HttpBearerAuth) auth).setBearerToken(tokenSupplier); return; } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index 460ad224963c..e6ae1d454c79 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -17,13 +17,15 @@ import org.openapitools.client.Pair; import java.net.URI; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -35,7 +37,7 @@ public HttpBearerAuth(String scheme) { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -44,12 +46,22 @@ public String getBearerToken() { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams, String payload, String method, URI uri) throws ApiException { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); if (bearerToken == null) { return; } diff --git a/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index e9d4c678963a..a0083b8cf989 100644 --- a/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -15,13 +15,15 @@ import org.openapitools.client.Pair; -import java.util.Map; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class HttpBearerAuth implements Authentication { private final String scheme; - private String bearerToken; + private Supplier tokenSupplier; public HttpBearerAuth(String scheme) { this.scheme = scheme; @@ -33,7 +35,7 @@ public HttpBearerAuth(String scheme) { * @return The bearer token */ public String getBearerToken() { - return bearerToken; + return tokenSupplier.get(); } /** @@ -42,12 +44,22 @@ public String getBearerToken() { * @param bearerToken The bearer token to send in the Authorization header */ public void setBearerToken(String bearerToken) { - this.bearerToken = bearerToken; + this.tokenSupplier = () -> bearerToken; + } + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ + public void setBearerToken(Supplier tokenSupplier) { + this.tokenSupplier = tokenSupplier; } @Override public void applyToParams(List queryParams, Map headerParams, Map cookieParams) { - if(bearerToken == null) { + String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null); + if (bearerToken == null) { return; } diff --git a/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index 45ef724bd645..e78b00018017 100644 --- a/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -14,14 +14,29 @@ public HttpBearerAuth(String scheme) { this.scheme = scheme; } + /** + * Gets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @return The bearer token + */ public String getBearerToken() { return tokenSupplier.get(); } + /** + * Sets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param bearerToken The bearer token to send in the Authorization header + */ public void setBearerToken(String bearerToken) { this.tokenSupplier = () -> bearerToken; } - + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ public void setBearerToken(Supplier tokenSupplier) { this.tokenSupplier = tokenSupplier; } diff --git a/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index 51d5e3278ef7..4678c06efd7c 100644 --- a/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -14,14 +14,29 @@ public HttpBearerAuth(String scheme) { this.scheme = scheme; } + /** + * Gets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @return The bearer token + */ public String getBearerToken() { return tokenSupplier.get(); } + /** + * Sets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param bearerToken The bearer token to send in the Authorization header + */ public void setBearerToken(String bearerToken) { this.tokenSupplier = () -> bearerToken; } - + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ public void setBearerToken(Supplier tokenSupplier) { this.tokenSupplier = tokenSupplier; } diff --git a/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index 51d5e3278ef7..4678c06efd7c 100644 --- a/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -14,14 +14,29 @@ public HttpBearerAuth(String scheme) { this.scheme = scheme; } + /** + * Gets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @return The bearer token + */ public String getBearerToken() { return tokenSupplier.get(); } + /** + * Sets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param bearerToken The bearer token to send in the Authorization header + */ public void setBearerToken(String bearerToken) { this.tokenSupplier = () -> bearerToken; } - + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ public void setBearerToken(Supplier tokenSupplier) { this.tokenSupplier = tokenSupplier; } diff --git a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java index 0a73b802d4c2..6de08db3168b 100644 --- a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java @@ -166,18 +166,18 @@ public Authentication getAuthentication(String authName) { } /** - * Helper method to set token for HTTP bearer authentication. + * Helper method to set access token for the first Bearer authentication. * - * @param bearerToken the token + * @param bearerToken Bearer token */ public void setBearerToken(String bearerToken) { setBearerToken(() -> bearerToken); } /** - * Helper method to set the token supplier for HTTP bearer authentication. + * Helper method to set the supplier of access tokens for Bearer authentication. * - * @param tokenSupplier the token supplier function + * @param tokenSupplier The supplier of bearer tokens */ public void setBearerToken(Supplier tokenSupplier) { for (Authentication auth : authentications.values()) { diff --git a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index 51d5e3278ef7..4678c06efd7c 100644 --- a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -14,14 +14,29 @@ public HttpBearerAuth(String scheme) { this.scheme = scheme; } + /** + * Gets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @return The bearer token + */ public String getBearerToken() { return tokenSupplier.get(); } + /** + * Sets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param bearerToken The bearer token to send in the Authorization header + */ public void setBearerToken(String bearerToken) { this.tokenSupplier = () -> bearerToken; } - + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ public void setBearerToken(Supplier tokenSupplier) { this.tokenSupplier = tokenSupplier; } diff --git a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java index d6e6a8b07d2f..1dbc33b8f2d5 100644 --- a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java @@ -161,18 +161,18 @@ public Authentication getAuthentication(String authName) { } /** - * Helper method to set token for HTTP bearer authentication. + * Helper method to set access token for the first Bearer authentication. * - * @param bearerToken the token + * @param bearerToken Bearer token */ public void setBearerToken(String bearerToken) { setBearerToken(() -> bearerToken); } /** - * Helper method to set the token supplier for HTTP bearer authentication. + * Helper method to set the supplier of access tokens for Bearer authentication. * - * @param tokenSupplier the token supplier function + * @param tokenSupplier The supplier of bearer tokens */ public void setBearerToken(Supplier tokenSupplier) { for (Authentication auth : authentications.values()) { diff --git a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java index 51d5e3278ef7..4678c06efd7c 100644 --- a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java +++ b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java @@ -14,14 +14,29 @@ public HttpBearerAuth(String scheme) { this.scheme = scheme; } + /** + * Gets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @return The bearer token + */ public String getBearerToken() { return tokenSupplier.get(); } + /** + * Sets the token, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param bearerToken The bearer token to send in the Authorization header + */ public void setBearerToken(String bearerToken) { this.tokenSupplier = () -> bearerToken; } - + + /** + * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header. + * + * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header + */ public void setBearerToken(Supplier tokenSupplier) { this.tokenSupplier = tokenSupplier; } diff --git a/samples/client/petstore/jmeter/.openapi-generator/FILES b/samples/client/petstore/jmeter/.openapi-generator/FILES index 87541f4daaa9..0377bec67288 100644 --- a/samples/client/petstore/jmeter/.openapi-generator/FILES +++ b/samples/client/petstore/jmeter/.openapi-generator/FILES @@ -1,3 +1,5 @@ +FakeApi.csv +FakeApi.jmx PetApi.csv PetApi.jmx StoreApi.csv diff --git a/samples/client/petstore/jmeter/.openapi-generator/VERSION b/samples/client/petstore/jmeter/.openapi-generator/VERSION index c30f0ec2be7f..0f78c31cdc77 100644 --- a/samples/client/petstore/jmeter/.openapi-generator/VERSION +++ b/samples/client/petstore/jmeter/.openapi-generator/VERSION @@ -1 +1 @@ -5.1.0-SNAPSHOT \ No newline at end of file +7.2.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/jmeter/FakeApi.csv b/samples/client/petstore/jmeter/FakeApi.csv new file mode 100644 index 000000000000..48a90826d529 --- /dev/null +++ b/samples/client/petstore/jmeter/FakeApi.csv @@ -0,0 +1,2 @@ +testCase,httpStatusCode +Success,200 \ No newline at end of file diff --git a/samples/client/petstore/jmeter/FakeApi.jmx b/samples/client/petstore/jmeter/FakeApi.jmx new file mode 100644 index 000000000000..918182e4e1c5 --- /dev/null +++ b/samples/client/petstore/jmeter/FakeApi.jmx @@ -0,0 +1,171 @@ + + + + + + false + false + + + + + + + + + + threads + ${__P(threads,1)} + = + + + rampup + ${__P(rampup,1)} + = + + + duration + ${__P(duration,1)} + = + + + testCases + ${__P(testCases,10)} + = + + + host + ${__P(host,localhost)} + = + + + port + ${__P(port,8080)} + = + + + testData.operationId_DollarSignFile + ${__P(testData.operationId_DollarSignFile,FakeApi.csv)} + = + + + + + + + + + ${host} + ${port} + + + + + + 4 + + + + continue + + false + ${testCases} + + ${threads} + ${rampup} + 1448391617000 + 1448391617000 + true + ${duration} + 5 + + + + + + + + + + + + + + + + + + + + /v2/fake/operation_id_dollar_sign + GET + true + false + true + false + + false + + operationId dollar sign operationId dollar sign + + + + , + + ${testData.operationId_DollarSignFile} + true + true + shareMode.group + false + + true + + + + + + ${httpStatusCode} + + Assertion.response_code + false + 8 + + + + + + false + + saveConfig + + + true + true + true + + true + true + true + true + false + true + true + false + false + false + false + false + false + false + false + 0 + true + true + + + + + + + + diff --git a/samples/client/petstore/jmeter/PetApi.csv b/samples/client/petstore/jmeter/PetApi.csv index 29b09a1715de..2ab795b50f75 100644 --- a/samples/client/petstore/jmeter/PetApi.csv +++ b/samples/client/petstore/jmeter/PetApi.csv @@ -1,2 +1,2 @@ -testCase,httpStatusCode,body,petId,apiKey,status,tags,petId,body,petId,name,status,petId,additionalMetadata,file +testCase,httpStatusCode,pet,petId,apiKey,status,tags,petId,pet,petId,name,status,petId,additionalMetadata,file Success,200,0,0,0,0,0,0,0,0,0,0,0,0,0 \ No newline at end of file diff --git a/samples/client/petstore/jmeter/PetApi.jmx b/samples/client/petstore/jmeter/PetApi.jmx index 69c4866afab6..15efcf2b2849 100644 --- a/samples/client/petstore/jmeter/PetApi.jmx +++ b/samples/client/petstore/jmeter/PetApi.jmx @@ -121,6 +121,10 @@ Content-Type application/json + + accept + application/xml + Bearer ${__P(oathToken,token)} @@ -132,9 +136,9 @@ true - + false - ${__javaScript("${body}".replace(/'/g\, '"'),)} + ${__javaScript("${pet}".replace(/'/g\, '"'),)} = @@ -515,6 +519,10 @@ Content-Type application/json + + accept + application/xml + Bearer ${__P(oathToken,token)} @@ -526,9 +534,9 @@ true - + false - ${__javaScript("${body}".replace(/'/g\, '"'),)} + ${__javaScript("${pet}".replace(/'/g\, '"'),)} = diff --git a/samples/client/petstore/jmeter/StoreApi.csv b/samples/client/petstore/jmeter/StoreApi.csv index 70fd54e2b204..2ccf8884aff0 100644 --- a/samples/client/petstore/jmeter/StoreApi.csv +++ b/samples/client/petstore/jmeter/StoreApi.csv @@ -1,2 +1,2 @@ -testCase,httpStatusCode,orderId,orderId,body +testCase,httpStatusCode,orderId,orderId,order Success,200,0,0,0 \ No newline at end of file diff --git a/samples/client/petstore/jmeter/StoreApi.jmx b/samples/client/petstore/jmeter/StoreApi.jmx index a30bca1219ee..7cb9f20967f2 100644 --- a/samples/client/petstore/jmeter/StoreApi.jmx +++ b/samples/client/petstore/jmeter/StoreApi.jmx @@ -310,6 +310,10 @@ + + Content-Type + application/json + accept application/xml @@ -321,9 +325,9 @@ true - + false - ${__javaScript("${body}".replace(/'/g\, '"'),)} + ${__javaScript("${order}".replace(/'/g\, '"'),)} = diff --git a/samples/client/petstore/jmeter/UserApi.csv b/samples/client/petstore/jmeter/UserApi.csv index 92242d4077c7..66fcc84a5901 100644 --- a/samples/client/petstore/jmeter/UserApi.csv +++ b/samples/client/petstore/jmeter/UserApi.csv @@ -1,2 +1,2 @@ -testCase,httpStatusCode,body,body,body,username,username,username,password,username,body +testCase,httpStatusCode,user,user,user,username,username,username,password,username,user Success,200,0,0,0,0,0,0,0,0,0 \ No newline at end of file diff --git a/samples/client/petstore/jmeter/UserApi.jmx b/samples/client/petstore/jmeter/UserApi.jmx index 0ab9b304880d..47eb9867b304 100644 --- a/samples/client/petstore/jmeter/UserApi.jmx +++ b/samples/client/petstore/jmeter/UserApi.jmx @@ -117,6 +117,14 @@ + + Content-Type + application/json + + + api_key + ${__P(apiKey,key)} + @@ -124,9 +132,9 @@ true - + false - ${__javaScript("${body}".replace(/'/g\, '"'),)} + ${__javaScript("${user}".replace(/'/g\, '"'),)} = @@ -189,6 +197,14 @@ + + Content-Type + application/json + + + api_key + ${__P(apiKey,key)} + @@ -196,9 +212,9 @@ true - + false - ${__javaScript("${body}".replace(/'/g\, '"'),)} + ${__javaScript("${user}".replace(/'/g\, '"'),)} = @@ -261,6 +277,14 @@ + + Content-Type + application/json + + + api_key + ${__P(apiKey,key)} + @@ -268,9 +292,9 @@ true - + false - ${__javaScript("${body}".replace(/'/g\, '"'),)} + ${__javaScript("${user}".replace(/'/g\, '"'),)} = @@ -333,6 +357,10 @@ + + api_key + ${__P(apiKey,key)} + @@ -556,6 +584,10 @@ + + api_key + ${__P(apiKey,key)} + @@ -623,6 +655,14 @@ + + Content-Type + application/json + + + api_key + ${__P(apiKey,key)} + @@ -630,9 +670,9 @@ true - + false - ${__javaScript("${body}".replace(/'/g\, '"'),)} + ${__javaScript("${user}".replace(/'/g\, '"'),)} = diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/build.gradle.kts b/samples/client/petstore/kotlin-array-simple-string-multiplatform/build.gradle.kts index f8781e4f61ce..99fef0b6756a 100644 --- a/samples/client/petstore/kotlin-array-simple-string-multiplatform/build.gradle.kts +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/build.gradle.kts @@ -20,6 +20,7 @@ repositories { kotlin { jvm() ios { binaries { framework { freeCompilerArgs += "-Xobjc-generics" } } } + iosSimulatorArm64 { binaries { framework { freeCompilerArgs += "-Xobjc-generics" } } } js { browser() nodejs() @@ -66,6 +67,10 @@ kotlin { val iosTest by getting + val iosSimulatorArm64Main by getting + + val iosSimulatorArm64Test by getting + val jsMain by getting { dependencies { api("io.ktor:ktor-client-js:$ktor_version") diff --git a/samples/client/petstore/kotlin-bigdecimal-default-multiplatform/build.gradle.kts b/samples/client/petstore/kotlin-bigdecimal-default-multiplatform/build.gradle.kts index f8781e4f61ce..99fef0b6756a 100644 --- a/samples/client/petstore/kotlin-bigdecimal-default-multiplatform/build.gradle.kts +++ b/samples/client/petstore/kotlin-bigdecimal-default-multiplatform/build.gradle.kts @@ -20,6 +20,7 @@ repositories { kotlin { jvm() ios { binaries { framework { freeCompilerArgs += "-Xobjc-generics" } } } + iosSimulatorArm64 { binaries { framework { freeCompilerArgs += "-Xobjc-generics" } } } js { browser() nodejs() @@ -66,6 +67,10 @@ kotlin { val iosTest by getting + val iosSimulatorArm64Main by getting + + val iosSimulatorArm64Test by getting + val jsMain by getting { dependencies { api("io.ktor:ktor-client-js:$ktor_version") diff --git a/samples/client/petstore/kotlin-default-values-multiplatform/build.gradle.kts b/samples/client/petstore/kotlin-default-values-multiplatform/build.gradle.kts index f8781e4f61ce..99fef0b6756a 100644 --- a/samples/client/petstore/kotlin-default-values-multiplatform/build.gradle.kts +++ b/samples/client/petstore/kotlin-default-values-multiplatform/build.gradle.kts @@ -20,6 +20,7 @@ repositories { kotlin { jvm() ios { binaries { framework { freeCompilerArgs += "-Xobjc-generics" } } } + iosSimulatorArm64 { binaries { framework { freeCompilerArgs += "-Xobjc-generics" } } } js { browser() nodejs() @@ -66,6 +67,10 @@ kotlin { val iosTest by getting + val iosSimulatorArm64Main by getting + + val iosSimulatorArm64Test by getting + val jsMain by getting { dependencies { api("io.ktor:ktor-client-js:$ktor_version") diff --git a/samples/client/petstore/kotlin-multiplatform/build.gradle.kts b/samples/client/petstore/kotlin-multiplatform/build.gradle.kts index f8781e4f61ce..99fef0b6756a 100644 --- a/samples/client/petstore/kotlin-multiplatform/build.gradle.kts +++ b/samples/client/petstore/kotlin-multiplatform/build.gradle.kts @@ -20,6 +20,7 @@ repositories { kotlin { jvm() ios { binaries { framework { freeCompilerArgs += "-Xobjc-generics" } } } + iosSimulatorArm64 { binaries { framework { freeCompilerArgs += "-Xobjc-generics" } } } js { browser() nodejs() @@ -66,6 +67,10 @@ kotlin { val iosTest by getting + val iosSimulatorArm64Main by getting + + val iosSimulatorArm64Test by getting + val jsMain by getting { dependencies { api("io.ktor:ktor-client-js:$ktor_version") diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/AnotherFakeApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/AnotherFakeApi.php index 0bed73dc6ada..5d9011f1eb20 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/AnotherFakeApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/AnotherFakeApi.php @@ -130,7 +130,7 @@ public function getConfig(): Configuration * @param \OpenAPI\Client\Model\Client $client client model (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['call123TestSpecialTags'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\Client */ @@ -151,7 +151,7 @@ public function call123TestSpecialTags( * @param \OpenAPI\Client\Model\Client $client client model (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['call123TestSpecialTags'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\Client, HTTP status code, HTTP response headers (array of strings) */ @@ -204,7 +204,19 @@ public function call123TestSpecialTagsWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\Client' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -221,7 +233,19 @@ public function call123TestSpecialTagsWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/DefaultApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/DefaultApi.php index da027e2c37f7..8d81e22bd13d 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/DefaultApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/DefaultApi.php @@ -127,7 +127,7 @@ public function getConfig(): Configuration * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fooGet'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\FooGetDefaultResponse */ @@ -144,7 +144,7 @@ public function fooGet( * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fooGet'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\FooGetDefaultResponse, HTTP status code, HTTP response headers (array of strings) */ @@ -196,7 +196,19 @@ public function fooGetWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\FooGetDefaultResponse' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -213,7 +225,19 @@ public function fooGetWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php index b681d6660c8d..8f63741965dd 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeApi.php @@ -185,7 +185,7 @@ public function getConfig(): Configuration * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeBigDecimalMap'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\FakeBigDecimalMap200Response */ @@ -202,7 +202,7 @@ public function fakeBigDecimalMap( * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeBigDecimalMap'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\FakeBigDecimalMap200Response, HTTP status code, HTTP response headers (array of strings) */ @@ -254,7 +254,19 @@ public function fakeBigDecimalMapWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\FakeBigDecimalMap200Response' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -271,7 +283,19 @@ public function fakeBigDecimalMapWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -452,7 +476,7 @@ public function fakeBigDecimalMapRequest( * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeHealthGet'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\HealthCheckResult */ @@ -471,7 +495,7 @@ public function fakeHealthGet( * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeHealthGet'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\HealthCheckResult, HTTP status code, HTTP response headers (array of strings) */ @@ -523,7 +547,19 @@ public function fakeHealthGetWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\HealthCheckResult' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -540,7 +576,19 @@ public function fakeHealthGetWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -728,7 +776,7 @@ public function fakeHealthGetRequest( * @param string|null $header_1 header parameter (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeHttpSignatureTest'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -752,7 +800,7 @@ public function fakeHttpSignatureTest( * @param string|null $header_1 header parameter (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeHttpSignatureTest'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -1002,7 +1050,7 @@ public function fakeHttpSignatureTestRequest( * @param bool|null $body Input boolean as post body (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterBooleanSerialize'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return bool */ @@ -1021,7 +1069,7 @@ public function fakeOuterBooleanSerialize( * @param bool|null $body Input boolean as post body (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterBooleanSerialize'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of bool, HTTP status code, HTTP response headers (array of strings) */ @@ -1074,7 +1122,19 @@ public function fakeOuterBooleanSerializeWithHttpInfo( } else { $content = (string) $response->getBody(); if ('bool' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1091,7 +1151,19 @@ public function fakeOuterBooleanSerializeWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1285,7 +1357,7 @@ public function fakeOuterBooleanSerializeRequest( * @param \OpenAPI\Client\Model\OuterComposite|null $outer_composite Input composite as post body (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterCompositeSerialize'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\OuterComposite */ @@ -1304,7 +1376,7 @@ public function fakeOuterCompositeSerialize( * @param \OpenAPI\Client\Model\OuterComposite|null $outer_composite Input composite as post body (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterCompositeSerialize'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\OuterComposite, HTTP status code, HTTP response headers (array of strings) */ @@ -1357,7 +1429,19 @@ public function fakeOuterCompositeSerializeWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\OuterComposite' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1374,7 +1458,19 @@ public function fakeOuterCompositeSerializeWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1568,7 +1664,7 @@ public function fakeOuterCompositeSerializeRequest( * @param float|null $body Input number as post body (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterNumberSerialize'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return float */ @@ -1587,7 +1683,7 @@ public function fakeOuterNumberSerialize( * @param float|null $body Input number as post body (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterNumberSerialize'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of float, HTTP status code, HTTP response headers (array of strings) */ @@ -1640,7 +1736,19 @@ public function fakeOuterNumberSerializeWithHttpInfo( } else { $content = (string) $response->getBody(); if ('float' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1657,7 +1765,19 @@ public function fakeOuterNumberSerializeWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1851,7 +1971,7 @@ public function fakeOuterNumberSerializeRequest( * @param string|null $body Input string as post body (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterStringSerialize'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -1870,7 +1990,7 @@ public function fakeOuterStringSerialize( * @param string|null $body Input string as post body (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakeOuterStringSerialize'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -1923,7 +2043,19 @@ public function fakeOuterStringSerializeWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1940,7 +2072,19 @@ public function fakeOuterStringSerializeWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -2134,7 +2278,7 @@ public function fakeOuterStringSerializeRequest( * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakePropertyEnumIntegerSerialize'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\OuterObjectWithEnumProperty */ @@ -2153,7 +2297,7 @@ public function fakePropertyEnumIntegerSerialize( * @param \OpenAPI\Client\Model\OuterObjectWithEnumProperty $outer_object_with_enum_property Input enum (int) as post body (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['fakePropertyEnumIntegerSerialize'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\OuterObjectWithEnumProperty, HTTP status code, HTTP response headers (array of strings) */ @@ -2206,7 +2350,19 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\OuterObjectWithEnumProperty' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -2223,7 +2379,19 @@ public function fakePropertyEnumIntegerSerializeWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -2423,7 +2591,7 @@ public function fakePropertyEnumIntegerSerializeRequest( * @param \SplFileObject $body image to upload (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyWithBinary'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -2441,7 +2609,7 @@ public function testBodyWithBinary( * @param \SplFileObject $body image to upload (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyWithBinary'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -2658,7 +2826,7 @@ public function testBodyWithBinaryRequest( * @param \OpenAPI\Client\Model\FileSchemaTestClass $file_schema_test_class file_schema_test_class (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyWithFileSchema'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -2676,7 +2844,7 @@ public function testBodyWithFileSchema( * @param \OpenAPI\Client\Model\FileSchemaTestClass $file_schema_test_class (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyWithFileSchema'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -2894,7 +3062,7 @@ public function testBodyWithFileSchemaRequest( * @param \OpenAPI\Client\Model\User $user user (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyWithQueryParams'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -2914,7 +3082,7 @@ public function testBodyWithQueryParams( * @param \OpenAPI\Client\Model\User $user (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testBodyWithQueryParams'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -3156,7 +3324,7 @@ public function testBodyWithQueryParamsRequest( * @param \OpenAPI\Client\Model\Client $client client model (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testClientModel'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\Client */ @@ -3177,7 +3345,7 @@ public function testClientModel( * @param \OpenAPI\Client\Model\Client $client client model (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testClientModel'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\Client, HTTP status code, HTTP response headers (array of strings) */ @@ -3230,7 +3398,19 @@ public function testClientModelWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\Client' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -3247,7 +3427,19 @@ public function testClientModelWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -3466,7 +3658,7 @@ public function testClientModelRequest( * @param string|null $callback None (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEndpointParameters'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -3512,7 +3704,7 @@ public function testEndpointParameters( * @param string|null $callback None (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEndpointParameters'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -3965,7 +4157,7 @@ public function testEndpointParametersRequest( * @param string|null $enum_form_string Form parameter enum test (string) (optional, default to '-efg') * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEnumParameters'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -4001,7 +4193,7 @@ public function testEnumParameters( * @param string|null $enum_form_string Form parameter enum test (string) (optional, default to '-efg') * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEnumParameters'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -4346,7 +4538,7 @@ public function testEnumParametersRequest( * @param int|null $int64_group Integer in group parameters (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testGroupParameters'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -4372,7 +4564,7 @@ public function testGroupParameters( * @param int|null $int64_group Integer in group parameters (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testGroupParameters'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -4678,7 +4870,7 @@ public function testGroupParametersRequest( * @param array $request_body request body (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testInlineAdditionalProperties'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -4698,7 +4890,7 @@ public function testInlineAdditionalProperties( * @param array $request_body request body (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testInlineAdditionalProperties'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -4921,7 +5113,7 @@ public function testInlineAdditionalPropertiesRequest( * @param \OpenAPI\Client\Model\TestInlineFreeformAdditionalPropertiesRequest $test_inline_freeform_additional_properties_request request body (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testInlineFreeformAdditionalProperties'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -4941,7 +5133,7 @@ public function testInlineFreeformAdditionalProperties( * @param \OpenAPI\Client\Model\TestInlineFreeformAdditionalPropertiesRequest $test_inline_freeform_additional_properties_request request body (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testInlineFreeformAdditionalProperties'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -5165,7 +5357,7 @@ public function testInlineFreeformAdditionalPropertiesRequest( * @param string $param2 field2 (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testJsonFormData'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -5187,7 +5379,7 @@ public function testJsonFormData( * @param string $param2 field2 (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testJsonFormData'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -5425,7 +5617,7 @@ public function testJsonFormDataRequest( * @param \OpenAPI\Client\Model\ChildWithNullable $child_with_nullable request body (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testNullable'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -5445,7 +5637,7 @@ public function testNullable( * @param \OpenAPI\Client\Model\ChildWithNullable $child_with_nullable request body (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testNullable'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -5672,7 +5864,7 @@ public function testNullableRequest( * @param array|null $language language (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryParameterCollectionFormat'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -5702,7 +5894,7 @@ public function testQueryParameterCollectionFormat( * @param array|null $language (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testQueryParameterCollectionFormat'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeClassnameTags123Api.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeClassnameTags123Api.php index 776c4747cb01..94822327c19e 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeClassnameTags123Api.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/FakeClassnameTags123Api.php @@ -130,7 +130,7 @@ public function getConfig(): Configuration * @param \OpenAPI\Client\Model\Client $client client model (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testClassname'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\Client */ @@ -151,7 +151,7 @@ public function testClassname( * @param \OpenAPI\Client\Model\Client $client client model (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['testClassname'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\Client, HTTP status code, HTTP response headers (array of strings) */ @@ -204,7 +204,19 @@ public function testClassnameWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\Client' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -221,7 +233,19 @@ public function testClassnameWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php index 193bc94d3116..16aafd97e7a6 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php @@ -174,7 +174,7 @@ public function getConfig(): Configuration * @param array $variables Associative array of variables to pass to the host. Defaults to empty array. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['addPet'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -214,7 +214,7 @@ public function addPet( * @param array $variables Associative array of variables to pass to the host. Defaults to empty array. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['addPet'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -556,7 +556,7 @@ protected function getHostSettingsForaddPet(): array * @param string|null $api_key api_key (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deletePet'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -578,7 +578,7 @@ public function deletePet( * @param string|null $api_key (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deletePet'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -818,7 +818,7 @@ public function deletePetRequest( * @param string[] $status Status values that need to be considered for filter (required) (deprecated) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['findPetsByStatus'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\Pet[] */ @@ -839,7 +839,7 @@ public function findPetsByStatus( * @param string[] $status Status values that need to be considered for filter (required) (deprecated) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['findPetsByStatus'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\Pet[], HTTP status code, HTTP response headers (array of strings) */ @@ -892,7 +892,19 @@ public function findPetsByStatusWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\Pet[]' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -909,7 +921,19 @@ public function findPetsByStatusWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1121,7 +1145,7 @@ public function findPetsByStatusRequest( * @param string[] $tags Tags to filter by (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['findPetsByTags'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\Pet[] * @deprecated @@ -1143,7 +1167,7 @@ public function findPetsByTags( * @param string[] $tags Tags to filter by (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['findPetsByTags'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\Pet[], HTTP status code, HTTP response headers (array of strings) * @deprecated @@ -1197,7 +1221,19 @@ public function findPetsByTagsWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\Pet[]' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1214,7 +1250,19 @@ public function findPetsByTagsWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1429,7 +1477,7 @@ public function findPetsByTagsRequest( * @param int $pet_id ID of pet to return (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getPetById'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\Pet */ @@ -1450,7 +1498,7 @@ public function getPetById( * @param int $pet_id ID of pet to return (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getPetById'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings) */ @@ -1503,7 +1551,19 @@ public function getPetByIdWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\Pet' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1520,7 +1580,19 @@ public function getPetByIdWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1750,7 +1822,7 @@ public function getPetByIdRequest( * @param array $variables Associative array of variables to pass to the host. Defaults to empty array. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updatePet'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -1790,7 +1862,7 @@ public function updatePet( * @param array $variables Associative array of variables to pass to the host. Defaults to empty array. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updatePet'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -2133,7 +2205,7 @@ protected function getHostSettingsForupdatePet(): array * @param string|null $status Updated status of the pet (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updatePetWithForm'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -2157,7 +2229,7 @@ public function updatePetWithForm( * @param string|null $status Updated status of the pet (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updatePetWithForm'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -2411,7 +2483,7 @@ public function updatePetWithFormRequest( * @param \SplFileObject|null $file file to upload (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['uploadFile'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\ApiResponse */ @@ -2436,7 +2508,7 @@ public function uploadFile( * @param \SplFileObject|null $file file to upload (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['uploadFile'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\ApiResponse, HTTP status code, HTTP response headers (array of strings) */ @@ -2491,7 +2563,19 @@ public function uploadFileWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\ApiResponse' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -2508,7 +2592,19 @@ public function uploadFileWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -2751,7 +2847,7 @@ public function uploadFileRequest( * @param string|null $additional_metadata Additional data to pass to server (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['uploadFileWithRequiredFile'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\ApiResponse */ @@ -2776,7 +2872,7 @@ public function uploadFileWithRequiredFile( * @param string|null $additional_metadata Additional data to pass to server (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['uploadFileWithRequiredFile'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\ApiResponse, HTTP status code, HTTP response headers (array of strings) */ @@ -2831,7 +2927,19 @@ public function uploadFileWithRequiredFileWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\ApiResponse' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -2848,7 +2956,19 @@ public function uploadFileWithRequiredFileWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/StoreApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/StoreApi.php index b5ee394b771f..b2ec167a667c 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/StoreApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/StoreApi.php @@ -139,7 +139,7 @@ public function getConfig(): Configuration * @param string $order_id ID of the order that needs to be deleted (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteOrder'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -159,7 +159,7 @@ public function deleteOrder( * @param string $order_id ID of the order that needs to be deleted (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteOrder'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -382,7 +382,7 @@ public function deleteOrderRequest( * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInventory'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array */ @@ -401,7 +401,7 @@ public function getInventory( * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInventory'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of array, HTTP status code, HTTP response headers (array of strings) */ @@ -453,7 +453,19 @@ public function getInventoryWithHttpInfo( } else { $content = (string) $response->getBody(); if ('array' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -470,7 +482,19 @@ public function getInventoryWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -661,7 +685,7 @@ public function getInventoryRequest( * @param int $order_id ID of pet that needs to be fetched (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderById'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\Order */ @@ -682,7 +706,7 @@ public function getOrderById( * @param int $order_id ID of pet that needs to be fetched (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderById'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\Order, HTTP status code, HTTP response headers (array of strings) */ @@ -735,7 +759,19 @@ public function getOrderByIdWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\Order' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -752,7 +788,19 @@ public function getOrderByIdWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -965,7 +1013,7 @@ public function getOrderByIdRequest( * @param \OpenAPI\Client\Model\Order $order order placed for purchasing the pet (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\Order */ @@ -986,7 +1034,7 @@ public function placeOrder( * @param \OpenAPI\Client\Model\Order $order order placed for purchasing the pet (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\Order, HTTP status code, HTTP response headers (array of strings) */ @@ -1039,7 +1087,19 @@ public function placeOrderWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\Order' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1056,7 +1116,19 @@ public function placeOrderWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/UserApi.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/UserApi.php index 3acc81701e37..630fbf536476 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/UserApi.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/UserApi.php @@ -151,7 +151,7 @@ public function getConfig(): Configuration * @param \OpenAPI\Client\Model\User $user Created user object (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUser'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -171,7 +171,7 @@ public function createUser( * @param \OpenAPI\Client\Model\User $user Created user object (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUser'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -394,7 +394,7 @@ public function createUserRequest( * @param \OpenAPI\Client\Model\User[] $user List of user object (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUsersWithArrayInput'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -414,7 +414,7 @@ public function createUsersWithArrayInput( * @param \OpenAPI\Client\Model\User[] $user List of user object (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUsersWithArrayInput'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -637,7 +637,7 @@ public function createUsersWithArrayInputRequest( * @param \OpenAPI\Client\Model\User[] $user List of user object (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUsersWithListInput'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -657,7 +657,7 @@ public function createUsersWithListInput( * @param \OpenAPI\Client\Model\User[] $user List of user object (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['createUsersWithListInput'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -880,7 +880,7 @@ public function createUsersWithListInputRequest( * @param string $username The name that needs to be deleted (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteUser'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -900,7 +900,7 @@ public function deleteUser( * @param string $username The name that needs to be deleted (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['deleteUser'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -1124,7 +1124,7 @@ public function deleteUserRequest( * @param string $username The name that needs to be fetched. Use user1 for testing. (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserByName'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return \OpenAPI\Client\Model\User */ @@ -1145,7 +1145,7 @@ public function getUserByName( * @param string $username The name that needs to be fetched. Use user1 for testing. (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserByName'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of \OpenAPI\Client\Model\User, HTTP status code, HTTP response headers (array of strings) */ @@ -1198,7 +1198,19 @@ public function getUserByNameWithHttpInfo( } else { $content = (string) $response->getBody(); if ('\OpenAPI\Client\Model\User' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1215,7 +1227,19 @@ public function getUserByNameWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1423,7 +1447,7 @@ public function getUserByNameRequest( * @param string $password The password for login in clear text (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['loginUser'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return string */ @@ -1446,7 +1470,7 @@ public function loginUser( * @param string $password The password for login in clear text (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['loginUser'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of string, HTTP status code, HTTP response headers (array of strings) */ @@ -1500,7 +1524,19 @@ public function loginUserWithHttpInfo( } else { $content = (string) $response->getBody(); if ('string' !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1517,7 +1553,19 @@ public function loginUserWithHttpInfo( } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { - $content = json_decode($content); + try { + $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $exception) { + throw new ApiException( + sprintf( + 'Error JSON decoding server response (%s)', + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $content + ); + } } } @@ -1746,7 +1794,7 @@ public function loginUserRequest( * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['logoutUser'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -1764,7 +1812,7 @@ public function logoutUser( * * @param string $contentType The value for the Content-Type header. Check self::contentTypes['logoutUser'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ @@ -1967,7 +2015,7 @@ public function logoutUserRequest( * @param \OpenAPI\Client\Model\User $user Updated user object (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateUser'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return void */ @@ -1989,7 +2037,7 @@ public function updateUser( * @param \OpenAPI\Client\Model\User $user Updated user object (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['updateUser'] to see the possible values for this operation * - * @throws ApiException on non-2xx response + * @throws ApiException on non-2xx response or if the response body is not in the expected format * @throws InvalidArgumentException * @return array of null, HTTP status code, HTTP response headers (array of strings) */ diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/FormatTest.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/FormatTest.php index 83f78ff27a84..1deda3bbc717 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/FormatTest.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/FormatTest.php @@ -716,7 +716,7 @@ public function setString(?string $string): static throw new InvalidArgumentException('non-nullable string cannot be null'); } - if ((!preg_match("/[a-z]/i", $string))) { + if ((!preg_match("/[a-z]/i", ObjectSerializer::toString($string)))) { throw new InvalidArgumentException("invalid value for \$string when calling FormatTest., must conform to the pattern /[a-z]/i."); } @@ -917,7 +917,7 @@ public function setPatternWithDigits(?string $pattern_with_digits): static throw new InvalidArgumentException('non-nullable pattern_with_digits cannot be null'); } - if ((!preg_match("/^\\d{10}$/", $pattern_with_digits))) { + if ((!preg_match("/^\\d{10}$/", ObjectSerializer::toString($pattern_with_digits)))) { throw new InvalidArgumentException("invalid value for \$pattern_with_digits when calling FormatTest., must conform to the pattern /^\\d{10}$/."); } @@ -949,7 +949,7 @@ public function setPatternWithDigitsAndDelimiter(?string $pattern_with_digits_an throw new InvalidArgumentException('non-nullable pattern_with_digits_and_delimiter cannot be null'); } - if ((!preg_match("/^image_\\d{1,3}$/i", $pattern_with_digits_and_delimiter))) { + if ((!preg_match("/^image_\\d{1,3}$/i", ObjectSerializer::toString($pattern_with_digits_and_delimiter)))) { throw new InvalidArgumentException("invalid value for \$pattern_with_digits_and_delimiter when calling FormatTest., must conform to the pattern /^image_\\d{1,3}$/i."); } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/ObjectSerializer.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/ObjectSerializer.php index 69bc6074cd23..81f07e6f9746 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/ObjectSerializer.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/ObjectSerializer.php @@ -426,10 +426,7 @@ public static function deserialize(mixed $data, string $class, array $httpHeader return $deserialized; } - if ($class === 'object') { - settype($data, 'array'); - return $data; - } elseif ($class === 'mixed') { + if ($class === 'mixed') { settype($data, gettype($data)); return $data; } diff --git a/samples/client/petstore/rust/reqwest/petstore/tests/type_testing.rs b/samples/client/petstore/rust/reqwest/petstore/tests/type_testing.rs index e89187b170cc..186ae1acade0 100644 --- a/samples/client/petstore/rust/reqwest/petstore/tests/type_testing.rs +++ b/samples/client/petstore/rust/reqwest/petstore/tests/type_testing.rs @@ -1,10 +1,19 @@ extern crate petstore_reqwest; use petstore_reqwest::models::TypeTesting; +use uuid::Uuid; #[test] fn test_types() { - let tt = TypeTesting::default(); + let tt = TypeTesting { + int32: 123, + int64: 456, + float: 12.34, + double: 45.56, + string: String::from("something"), + boolean: true, + uuid: Uuid::new_v4() + }; assert_eq!(type_of(tt.int32), "i32"); assert_eq!(type_of(tt.int64), "i64"); assert_eq!(type_of(tt.float), "f32"); diff --git a/samples/client/petstore/zapier/models/Pet.js b/samples/client/petstore/zapier/models/Pet.js index 48467248dd4b..c66305545cb2 100644 --- a/samples/client/petstore/zapier/models/Pet.js +++ b/samples/client/petstore/zapier/models/Pet.js @@ -15,11 +15,13 @@ module.exports = { { key: `${keyPrefix}name`, label: `[${labelPrefix}name]`, + required: true, type: 'string', }, { key: `${keyPrefix}photoUrls`, label: `[${labelPrefix}photoUrls]`, + required: true, list: true, type: 'string', }, diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/analysis_options.yaml b/samples/openapi3/client/petstore/dart-dio/oneof/analysis_options.yaml index 139ad7abf559..16a95850087a 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof/analysis_options.yaml +++ b/samples/openapi3/client/petstore/dart-dio/oneof/analysis_options.yaml @@ -2,9 +2,7 @@ analyzer: language: strict-inference: true strict-raw-types: true - strong-mode: - implicit-dynamic: false - implicit-casts: false + strict-casts: false exclude: - test/*.dart errors: diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/analysis_options.yaml b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/analysis_options.yaml index 139ad7abf559..16a95850087a 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/analysis_options.yaml +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/analysis_options.yaml @@ -2,9 +2,7 @@ analyzer: language: strict-inference: true strict-raw-types: true - strong-mode: - implicit-dynamic: false - implicit-casts: false + strict-casts: false exclude: - test/*.dart errors: diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/analysis_options.yaml b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/analysis_options.yaml index 139ad7abf559..16a95850087a 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/analysis_options.yaml +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/analysis_options.yaml @@ -2,9 +2,7 @@ analyzer: language: strict-inference: true strict-raw-types: true - strong-mode: - implicit-dynamic: false - implicit-casts: false + strict-casts: false exclude: - test/*.dart errors: diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/analysis_options.yaml b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/analysis_options.yaml index ac01482530cc..70524126e3fe 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/analysis_options.yaml +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/analysis_options.yaml @@ -2,9 +2,7 @@ analyzer: language: strict-inference: true strict-raw-types: true - strong-mode: - implicit-dynamic: false - implicit-casts: false + strict-casts: false exclude: - test/*.dart - lib/src/model/*.g.dart diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/analysis_options.yaml b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/analysis_options.yaml index 139ad7abf559..16a95850087a 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/analysis_options.yaml +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/analysis_options.yaml @@ -2,9 +2,7 @@ analyzer: language: strict-inference: true strict-raw-types: true - strong-mode: - implicit-dynamic: false - implicit-casts: false + strict-casts: false exclude: - test/*.dart errors: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/inner_dict_with_property.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/inner_dict_with_property.py index 106fbbbb9889..f93d19de93c2 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/inner_dict_with_property.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/inner_dict_with_property.py @@ -18,7 +18,7 @@ import json -from typing import Any, ClassVar, Dict, List, Optional, Union +from typing import Any, ClassVar, Dict, List, Optional from pydantic import BaseModel from pydantic import Field try: @@ -30,7 +30,7 @@ class InnerDictWithProperty(BaseModel): """ InnerDictWithProperty """ # noqa: E501 - a_property: Optional[Union[str, Any]] = Field(default=None, alias="aProperty") + a_property: Optional[Dict[str, Any]] = Field(default=None, alias="aProperty") __properties: ClassVar[List[str]] = ["aProperty"] model_config = { diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_class.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_class.py index 67d7f00f9e6b..d30916976ba2 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_class.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_class.py @@ -18,7 +18,7 @@ import json from datetime import date, datetime -from typing import Any, ClassVar, Dict, List, Optional, Union +from typing import Any, ClassVar, Dict, List, Optional from pydantic import BaseModel, StrictBool, StrictInt, StrictStr try: from typing import Self @@ -36,12 +36,12 @@ class NullableClass(BaseModel): string_prop: Optional[StrictStr] = None date_prop: Optional[date] = None datetime_prop: Optional[datetime] = None - array_nullable_prop: Optional[List[Union[str, Any]]] = None - array_and_items_nullable_prop: Optional[List[Union[str, Any]]] = None - array_items_nullable: Optional[List[Union[str, Any]]] = None - object_nullable_prop: Optional[Dict[str, Union[str, Any]]] = None - object_and_items_nullable_prop: Optional[Dict[str, Union[str, Any]]] = None - object_items_nullable: Optional[Dict[str, Union[str, Any]]] = None + array_nullable_prop: Optional[List[Dict[str, Any]]] = None + array_and_items_nullable_prop: Optional[List[Dict[str, Any]]] = None + array_items_nullable: Optional[List[Dict[str, Any]]] = None + object_nullable_prop: Optional[Dict[str, Dict[str, Any]]] = None + object_and_items_nullable_prop: Optional[Dict[str, Dict[str, Any]]] = None + object_items_nullable: Optional[Dict[str, Dict[str, Any]]] = None additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["required_integer_prop", "integer_prop", "number_prop", "boolean_prop", "string_prop", "date_prop", "datetime_prop", "array_nullable_prop", "array_and_items_nullable_prop", "array_items_nullable", "object_nullable_prop", "object_and_items_nullable_prop", "object_items_nullable"] diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/inner_dict_with_property.py b/samples/openapi3/client/petstore/python/petstore_api/models/inner_dict_with_property.py index 08fceba1ad30..c4e52c32e4d7 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/inner_dict_with_property.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/inner_dict_with_property.py @@ -18,7 +18,7 @@ import json -from typing import Any, ClassVar, Dict, List, Optional, Union +from typing import Any, ClassVar, Dict, List, Optional from pydantic import BaseModel from pydantic import Field try: @@ -30,7 +30,7 @@ class InnerDictWithProperty(BaseModel): """ InnerDictWithProperty """ # noqa: E501 - a_property: Optional[Union[str, Any]] = Field(default=None, alias="aProperty") + a_property: Optional[Dict[str, Any]] = Field(default=None, alias="aProperty") additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["aProperty"] diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/nullable_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/nullable_class.py index fc38db22ac01..88c5ee219988 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/nullable_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/nullable_class.py @@ -18,7 +18,7 @@ import json from datetime import date, datetime -from typing import Any, ClassVar, Dict, List, Optional, Union +from typing import Any, ClassVar, Dict, List, Optional from pydantic import BaseModel, StrictBool, StrictFloat, StrictInt, StrictStr try: from typing import Self @@ -36,12 +36,12 @@ class NullableClass(BaseModel): string_prop: Optional[StrictStr] = None date_prop: Optional[date] = None datetime_prop: Optional[datetime] = None - array_nullable_prop: Optional[List[Union[str, Any]]] = None - array_and_items_nullable_prop: Optional[List[Union[str, Any]]] = None - array_items_nullable: Optional[List[Union[str, Any]]] = None - object_nullable_prop: Optional[Dict[str, Union[str, Any]]] = None - object_and_items_nullable_prop: Optional[Dict[str, Union[str, Any]]] = None - object_items_nullable: Optional[Dict[str, Union[str, Any]]] = None + array_nullable_prop: Optional[List[Dict[str, Any]]] = None + array_and_items_nullable_prop: Optional[List[Dict[str, Any]]] = None + array_items_nullable: Optional[List[Dict[str, Any]]] = None + object_nullable_prop: Optional[Dict[str, Dict[str, Any]]] = None + object_and_items_nullable_prop: Optional[Dict[str, Dict[str, Any]]] = None + object_items_nullable: Optional[Dict[str, Dict[str, Any]]] = None additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["required_integer_prop", "integer_prop", "number_prop", "boolean_prop", "string_prop", "date_prop", "datetime_prop", "array_nullable_prop", "array_and_items_nullable_prop", "array_items_nullable", "object_nullable_prop", "object_and_items_nullable_prop", "object_items_nullable"] diff --git a/samples/openapi3/client/petstore/python/tests/test_model.py b/samples/openapi3/client/petstore/python/tests/test_model.py index c96ec890acc2..646755b7f1dd 100644 --- a/samples/openapi3/client/petstore/python/tests/test_model.py +++ b/samples/openapi3/client/petstore/python/tests/test_model.py @@ -8,8 +8,10 @@ import unittest from pydantic import ValidationError +import pytest import petstore_api +from petstore_api import InnerDictWithProperty class ModelTests(unittest.TestCase): @@ -508,6 +510,19 @@ def test_object_with_optional_dict(self): self.assertFalse(b is None) self.assertEqual(b.optional_dict["key"].a_property["a"], "b") + def test_freeform_object(self): + # Allows dict[str, Any] and is nullable + a = InnerDictWithProperty.from_dict({"aProperty": {"a": 12}}) + a = InnerDictWithProperty.from_dict({"aProperty": None}) + + # Allows no other values + with pytest.raises(ValidationError): + a = InnerDictWithProperty.from_dict({"aProperty": {123: 45}}) + with pytest.raises(ValidationError): + a = InnerDictWithProperty.from_dict({"aProperty": "abc"}) + with pytest.raises(ValidationError): + a = InnerDictWithProperty.from_dict({"aProperty": 12}) + def test_object_with_dict_of_dict_of_object(self): # for https://github.com/OpenAPITools/openapi-generator/issues/15135 d = {"optionalDict": {"a": {"b": {"aProperty": "value"}}}} diff --git a/samples/server/petstore/python-aiohttp-srclayout/requirements.txt b/samples/server/petstore/python-aiohttp-srclayout/requirements.txt index 70c264978d3b..aaaaeb756eac 100644 --- a/samples/server/petstore/python-aiohttp-srclayout/requirements.txt +++ b/samples/server/petstore/python-aiohttp-srclayout/requirements.txt @@ -1,4 +1,4 @@ -connexion[aiohttp,swagger-ui] >= 2.6.0; python_version>="3.6" +connexion[aiohttp,swagger-ui] >= 2.6.0, <3; python_version>="3.6" # 2.3 is the last version that supports python 3.5 connexion[aiohttp,swagger-ui] <= 2.3.0; python_version=="3.5" or python_version=="3.4" # connexion requires werkzeug but connexion < 2.4.0 does not install werkzeug @@ -7,3 +7,4 @@ connexion[aiohttp,swagger-ui] <= 2.3.0; python_version=="3.5" or python_version= werkzeug == 0.16.1; python_version=="3.5" or python_version=="3.4" swagger-ui-bundle == 0.0.9 aiohttp_jinja2 == 1.5.0 +Flask < 2.3 \ No newline at end of file diff --git a/samples/server/petstore/python-aiohttp-srclayout/test_python3.sh b/samples/server/petstore/python-aiohttp-srclayout/test_python3.sh index 43fab931f00f..95b8f7173f00 100755 --- a/samples/server/petstore/python-aiohttp-srclayout/test_python3.sh +++ b/samples/server/petstore/python-aiohttp-srclayout/test_python3.sh @@ -23,7 +23,7 @@ pip install -r $REQUIREMENTS_FILE | tee -a $REQUIREMENTS_OUT tox || exit 1 ### static analysis of code -flake8 --show-source petstore_api/ +flake8 --show-source ./src ### deactivate virtualenv if [ $DEACTIVE == true ]; then diff --git a/samples/server/petstore/python-aiohttp-srclayout/tests/test_pet_controller.py b/samples/server/petstore/python-aiohttp-srclayout/tests/test_pet_controller.py index 3cac35cc24cb..898181839f42 100644 --- a/samples/server/petstore/python-aiohttp-srclayout/tests/test_pet_controller.py +++ b/samples/server/petstore/python-aiohttp-srclayout/tests/test_pet_controller.py @@ -8,6 +8,7 @@ from openapi_server.models.api_response import ApiResponse from openapi_server.models.pet import Pet +pytestmark = pytest.mark.asyncio @pytest.mark.skip("Connexion does not support multiple consumes. See https://github.com/zalando/connexion/pull/760") async def test_add_pet(client): diff --git a/samples/server/petstore/python-aiohttp-srclayout/tests/test_store_controller.py b/samples/server/petstore/python-aiohttp-srclayout/tests/test_store_controller.py index 9d376a5f7a5b..9cbe796815f9 100644 --- a/samples/server/petstore/python-aiohttp-srclayout/tests/test_store_controller.py +++ b/samples/server/petstore/python-aiohttp-srclayout/tests/test_store_controller.py @@ -6,6 +6,7 @@ from openapi_server.models.order import Order +pytestmark = pytest.mark.asyncio async def test_delete_order(client): """Test case for delete_order diff --git a/samples/server/petstore/python-aiohttp-srclayout/tests/test_user_controller.py b/samples/server/petstore/python-aiohttp-srclayout/tests/test_user_controller.py index 6564329315ed..ae97db8ea413 100644 --- a/samples/server/petstore/python-aiohttp-srclayout/tests/test_user_controller.py +++ b/samples/server/petstore/python-aiohttp-srclayout/tests/test_user_controller.py @@ -6,6 +6,7 @@ from openapi_server.models.user import User +pytestmark = pytest.mark.asyncio @pytest.mark.skip("*/* not supported by Connexion. Use application/json instead. See https://github.com/zalando/connexion/pull/760") async def test_create_user(client): diff --git a/samples/server/petstore/python-aiohttp-srclayout/tox.ini b/samples/server/petstore/python-aiohttp-srclayout/tox.ini index 25d12bb84c0b..f66b2d84cdaa 100644 --- a/samples/server/petstore/python-aiohttp-srclayout/tox.ini +++ b/samples/server/petstore/python-aiohttp-srclayout/tox.ini @@ -8,4 +8,4 @@ deps=-r{toxinidir}/requirements.txt {toxinidir} commands= - pytest --cov=src/openapi_server + pytest --cov=openapi_server diff --git a/samples/server/petstore/rust-server/output/multipart-v3/src/models.rs b/samples/server/petstore/rust-server/output/multipart-v3/src/models.rs index d296010d7210..ea0267cbe021 100644 --- a/samples/server/petstore/rust-server/output/multipart-v3/src/models.rs +++ b/samples/server/petstore/rust-server/output/multipart-v3/src/models.rs @@ -180,7 +180,7 @@ impl std::string::ToString for MultipartRequestObjectField { self.field_b.as_ref().map(|field_b| { - vec![ + [ "field_b".to_string(), field_b.iter().map(|x| x.to_string()).collect::>().join(","), ].join(",") diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs index 71a4af713398..b71408c2422f 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs @@ -1165,7 +1165,7 @@ impl Api for Client where // Currently only authentication with Basic and Bearer are supported #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { - &AuthData::Bearer(ref bearer_header) => { + AuthData::Bearer(bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, @@ -1489,7 +1489,7 @@ impl Api for Client where // Currently only authentication with Basic and Bearer are supported #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { - &AuthData::Bearer(ref bearer_header) => { + AuthData::Bearer(bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs index d1e67d2949af..62c17efd9819 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs @@ -295,7 +295,7 @@ impl std::string::ToString for AnotherXmlObject { let params: Vec> = vec![ self.inner_string.as_ref().map(|inner_string| { - vec![ + [ "inner_string".to_string(), inner_string.to_string(), ].join(",") @@ -815,7 +815,7 @@ impl std::string::ToString for DuplicateXmlObject { let params: Vec> = vec![ self.inner_string.as_ref().map(|inner_string| { - vec![ + [ "inner_string".to_string(), inner_string.to_string(), ].join(",") @@ -1233,7 +1233,7 @@ impl std::string::ToString for MultigetGet201Response { let params: Vec> = vec![ self.foo.as_ref().map(|foo| { - vec![ + [ "foo".to_string(), foo.to_string(), ].join(",") @@ -1574,7 +1574,7 @@ impl std::string::ToString for NullableTest { self.nullable_with_null_default.as_ref().map(|nullable_with_null_default| { - vec![ + [ "nullableWithNullDefault".to_string(), nullable_with_null_default.as_ref().map_or("null".to_string(), |x| x.to_string()), ].join(",") @@ -1582,7 +1582,7 @@ impl std::string::ToString for NullableTest { self.nullable_with_present_default.as_ref().map(|nullable_with_present_default| { - vec![ + [ "nullableWithPresentDefault".to_string(), nullable_with_present_default.as_ref().map_or("null".to_string(), |x| x.to_string()), ].join(",") @@ -1590,7 +1590,7 @@ impl std::string::ToString for NullableTest { self.nullable_with_no_default.as_ref().map(|nullable_with_no_default| { - vec![ + [ "nullableWithNoDefault".to_string(), nullable_with_no_default.as_ref().map_or("null".to_string(), |x| x.to_string()), ].join(",") @@ -1598,7 +1598,7 @@ impl std::string::ToString for NullableTest { self.nullable_array.as_ref().map(|nullable_array| { - vec![ + [ "nullableArray".to_string(), nullable_array.as_ref().map_or("null".to_string(), |x| x.iter().map(|x| x.to_string()).collect::>().join(",")), ].join(",") @@ -1750,7 +1750,7 @@ impl std::string::ToString for ObjectHeader { self.optional_object_header.as_ref().map(|optional_object_header| { - vec![ + [ "optionalObjectHeader".to_string(), optional_object_header.to_string(), ].join(",") @@ -1895,7 +1895,7 @@ impl std::string::ToString for ObjectParam { self.optional_param.as_ref().map(|optional_param| { - vec![ + [ "optionalParam".to_string(), optional_param.to_string(), ].join(",") @@ -2189,7 +2189,7 @@ impl std::string::ToString for ObjectWithArrayOfObjects { let params: Vec> = vec![ self.object_array.as_ref().map(|object_array| { - vec![ + [ "objectArray".to_string(), object_array.iter().map(|x| x.to_string()).collect::>().join(","), ].join(",") @@ -2963,7 +2963,7 @@ impl std::string::ToString for XmlObject { let params: Vec> = vec![ self.inner_string.as_ref().map(|inner_string| { - vec![ + [ "innerString".to_string(), inner_string.to_string(), ].join(",") @@ -2971,7 +2971,7 @@ impl std::string::ToString for XmlObject { self.other_inner_rename.as_ref().map(|other_inner_rename| { - vec![ + [ "other_inner_rename".to_string(), other_inner_rename.to_string(), ].join(",") diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs index 0d8be00926b7..3808a67d7573 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/server/mod.rs @@ -257,8 +257,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for ANY_OF_GET_SUCCESS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, AnyOfGetResponse::AlternateSuccess (body) @@ -268,8 +268,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for ANY_OF_GET_ALTERNATE_SUCCESS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, AnyOfGetResponse::AnyOfSuccess (body) @@ -279,8 +279,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for ANY_OF_GET_ANY_OF_SUCCESS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -569,8 +569,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/merge-patch+json") .expect("Unable to create Content-Type header for MERGE_PATCH_JSON_GET_MERGE")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -605,8 +605,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for MULTIGET_GET_JSON_RSP")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, MultigetGetResponse::XMLRsp (body) @@ -616,8 +616,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/xml") .expect("Unable to create Content-Type header for MULTIGET_GET_XML_RSP")); - let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, MultigetGetResponse::OctetRsp (body) @@ -627,8 +627,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/octet-stream") .expect("Unable to create Content-Type header for MULTIGET_GET_OCTET_RSP")); - let body = body.0; - *response.body_mut() = Body::from(body); + let body_content = body.0; + *response.body_mut() = Body::from(body_content); }, MultigetGetResponse::StringRsp (body) @@ -638,8 +638,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("text/plain") .expect("Unable to create Content-Type header for MULTIGET_GET_STRING_RSP")); - let body = body; - *response.body_mut() = Body::from(body); + let body_content = body; + *response.body_mut() = Body::from(body_content); }, MultigetGetResponse::DuplicateResponseLongText (body) @@ -649,8 +649,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for MULTIGET_GET_DUPLICATE_RESPONSE_LONG_TEXT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, MultigetGetResponse::DuplicateResponseLongText_2 (body) @@ -660,8 +660,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for MULTIGET_GET_DUPLICATE_RESPONSE_LONG_TEXT_2")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, MultigetGetResponse::DuplicateResponseLongText_3 (body) @@ -671,8 +671,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for MULTIGET_GET_DUPLICATE_RESPONSE_LONG_TEXT_3")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -766,8 +766,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for ONE_OF_GET_SUCCESS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -888,8 +888,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for PARAMGET_GET_JSON_RSP")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -1145,8 +1145,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for RESPONSES_WITH_HEADERS_GET_SUCCESS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, ResponsesWithHeadersGetResponse::PreconditionFailed { @@ -1221,8 +1221,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for RFC7807_GET_OK")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, Rfc7807GetResponse::NotFound (body) @@ -1232,8 +1232,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/problem+json") .expect("Unable to create Content-Type header for RFC7807_GET_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, Rfc7807GetResponse::NotAcceptable (body) @@ -1243,8 +1243,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/problem+xml") .expect("Unable to create Content-Type header for RFC7807_GET_NOT_ACCEPTABLE")); - let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -1342,8 +1342,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for UUID_GET_DUPLICATE_RESPONSE_LONG_TEXT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -1477,8 +1477,8 @@ impl hyper::service::Service<(Request, C)> for Service where // An empty string is used to indicate a global namespace in xmltree. namespaces.insert("".to_string(), models::AnotherXmlObject::NAMESPACE.to_string()); - let body = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, XmlOtherPostResponse::BadRequest => { @@ -1821,8 +1821,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_REPO_INFO_OK")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/docs/FormatTest.md b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/docs/FormatTest.md index 604bf73686b8..ec568846bcbf 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/docs/FormatTest.md +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **String** | | [optional] [default to None] **byte** | [***swagger::ByteArray**](ByteArray.md) | | **binary** | [***swagger::ByteArray**](file.md) | | [optional] [default to None] -**date** | [***chrono::DateTime::**](date.md) | | +**date** | [***chrono::naive::NaiveDate**](date.md) | | **date_time** | [**chrono::DateTime::**](DateTime.md) | | [optional] [default to None] **uuid** | [***uuid::Uuid**](UUID.md) | | [optional] [default to None] **password** | **String** | | diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/docs/fake_api.md b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/docs/fake_api.md index 1937f562e8cf..ddc0786bbe06 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/docs/fake_api.md +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/docs/fake_api.md @@ -311,7 +311,7 @@ Name | Type | Description | Notes **float** | **f32**| None | **string** | **String**| None | **binary** | **swagger::ByteArray**| None | - **date** | **chrono::DateTime::**| None | + **date** | **chrono::naive::NaiveDate**| None | **date_time** | **chrono::DateTime::**| None | **password** | **String**| None | **callback** | **String**| None | diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server/server.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server/server.rs index 4892cfd49566..5a89df7a6b69 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server/server.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server/server.rs @@ -241,7 +241,7 @@ impl Api for Server where C: Has + Send + Sync float: Option, string: Option, binary: Option, - date: Option>, + date: Option, date_time: Option>, password: Option, callback: Option, diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs index 27c40c08de79..625e7aea9fa3 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs @@ -1250,7 +1250,7 @@ impl Api for Client where param_float: Option, param_string: Option, param_binary: Option, - param_date: Option>, + param_date: Option, param_date_time: Option>, param_password: Option, param_callback: Option, @@ -1320,7 +1320,7 @@ impl Api for Client where // Currently only authentication with Basic and Bearer are supported #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { - &AuthData::Basic(ref basic_header) => { + AuthData::Basic(basic_header) => { let auth = swagger::auth::Header(basic_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, @@ -1824,7 +1824,7 @@ impl Api for Client where // Currently only authentication with Basic and Bearer are supported #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { - &AuthData::Bearer(ref bearer_header) => { + AuthData::Bearer(bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, @@ -1914,7 +1914,7 @@ impl Api for Client where // Currently only authentication with Basic and Bearer are supported #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { - &AuthData::Bearer(ref bearer_header) => { + AuthData::Bearer(bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, @@ -2022,7 +2022,7 @@ impl Api for Client where // Currently only authentication with Basic and Bearer are supported #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { - &AuthData::Bearer(ref bearer_header) => { + AuthData::Bearer(bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, @@ -2127,7 +2127,7 @@ impl Api for Client where // Currently only authentication with Basic and Bearer are supported #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { - &AuthData::Bearer(ref bearer_header) => { + AuthData::Bearer(bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, @@ -2337,7 +2337,7 @@ impl Api for Client where // Currently only authentication with Basic and Bearer are supported #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { - &AuthData::Bearer(ref bearer_header) => { + AuthData::Bearer(bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, @@ -2450,7 +2450,7 @@ impl Api for Client where // Currently only authentication with Basic and Bearer are supported #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { - &AuthData::Bearer(ref bearer_header) => { + AuthData::Bearer(bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, @@ -2596,7 +2596,7 @@ impl Api for Client where // Currently only authentication with Basic and Bearer are supported #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { - &AuthData::Bearer(ref bearer_header) => { + AuthData::Bearer(bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs index f652f1580e55..17501af77f4e 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs @@ -387,7 +387,7 @@ pub trait Api { float: Option, string: Option, binary: Option, - date: Option>, + date: Option, date_time: Option>, password: Option, callback: Option, @@ -624,7 +624,7 @@ pub trait ApiNoContext { float: Option, string: Option, binary: Option, - date: Option>, + date: Option, date_time: Option>, password: Option, callback: Option, @@ -915,7 +915,7 @@ impl + Send + Sync, C: Clone + Send + Sync> ApiNoContext for Contex float: Option, string: Option, binary: Option, - date: Option>, + date: Option, date_time: Option>, password: Option, callback: Option, diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs index beec39b5c335..c77a7acf8384 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs @@ -178,7 +178,7 @@ impl std::string::ToString for Animal { self.color.as_ref().map(|color| { - vec![ + [ "color".to_string(), color.to_string(), ].join(",") @@ -463,7 +463,7 @@ impl std::string::ToString for ApiResponse { let params: Vec> = vec![ self.code.as_ref().map(|code| { - vec![ + [ "code".to_string(), code.to_string(), ].join(",") @@ -471,7 +471,7 @@ impl std::string::ToString for ApiResponse { self.r#type.as_ref().map(|r#type| { - vec![ + [ "type".to_string(), r#type.to_string(), ].join(",") @@ -479,7 +479,7 @@ impl std::string::ToString for ApiResponse { self.message.as_ref().map(|message| { - vec![ + [ "message".to_string(), message.to_string(), ].join(",") @@ -746,7 +746,7 @@ impl std::string::ToString for ArrayOfNumberOnly { let params: Vec> = vec![ self.array_number.as_ref().map(|array_number| { - vec![ + [ "ArrayNumber".to_string(), array_number.iter().map(|x| x.to_string()).collect::>().join(","), ].join(",") @@ -894,7 +894,7 @@ impl std::string::ToString for ArrayTest { let params: Vec> = vec![ self.array_of_string.as_ref().map(|array_of_string| { - vec![ + [ "array_of_string".to_string(), array_of_string.iter().map(|x| x.to_string()).collect::>().join(","), ].join(",") @@ -906,7 +906,7 @@ impl std::string::ToString for ArrayTest { self.array_of_enum.as_ref().map(|array_of_enum| { - vec![ + [ "array_of_enum".to_string(), array_of_enum.iter().map(|x| x.to_string()).collect::>().join(","), ].join(",") @@ -1073,7 +1073,7 @@ impl std::string::ToString for Capitalization { let params: Vec> = vec![ self.small_camel.as_ref().map(|small_camel| { - vec![ + [ "smallCamel".to_string(), small_camel.to_string(), ].join(",") @@ -1081,7 +1081,7 @@ impl std::string::ToString for Capitalization { self.capital_camel.as_ref().map(|capital_camel| { - vec![ + [ "CapitalCamel".to_string(), capital_camel.to_string(), ].join(",") @@ -1089,7 +1089,7 @@ impl std::string::ToString for Capitalization { self.small_snake.as_ref().map(|small_snake| { - vec![ + [ "small_Snake".to_string(), small_snake.to_string(), ].join(",") @@ -1097,7 +1097,7 @@ impl std::string::ToString for Capitalization { self.capital_snake.as_ref().map(|capital_snake| { - vec![ + [ "Capital_Snake".to_string(), capital_snake.to_string(), ].join(",") @@ -1105,7 +1105,7 @@ impl std::string::ToString for Capitalization { self.sca_eth_flow_points.as_ref().map(|sca_eth_flow_points| { - vec![ + [ "SCA_ETH_Flow_Points".to_string(), sca_eth_flow_points.to_string(), ].join(",") @@ -1113,7 +1113,7 @@ impl std::string::ToString for Capitalization { self.att_name.as_ref().map(|att_name| { - vec![ + [ "ATT_NAME".to_string(), att_name.to_string(), ].join(",") @@ -1279,7 +1279,7 @@ impl std::string::ToString for Cat { self.color.as_ref().map(|color| { - vec![ + [ "color".to_string(), color.to_string(), ].join(",") @@ -1287,7 +1287,7 @@ impl std::string::ToString for Cat { self.declawed.as_ref().map(|declawed| { - vec![ + [ "declawed".to_string(), declawed.to_string(), ].join(",") @@ -1434,7 +1434,7 @@ impl std::string::ToString for Category { let params: Vec> = vec![ self.id.as_ref().map(|id| { - vec![ + [ "id".to_string(), id.to_string(), ].join(",") @@ -1442,7 +1442,7 @@ impl std::string::ToString for Category { self.name.as_ref().map(|name| { - vec![ + [ "name".to_string(), name.to_string(), ].join(",") @@ -1580,7 +1580,7 @@ impl std::string::ToString for ClassModel { let params: Vec> = vec![ self._class.as_ref().map(|_class| { - vec![ + [ "_class".to_string(), _class.to_string(), ].join(",") @@ -1713,7 +1713,7 @@ impl std::string::ToString for Client { let params: Vec> = vec![ self.client.as_ref().map(|client| { - vec![ + [ "client".to_string(), client.to_string(), ].join(",") @@ -1859,7 +1859,7 @@ impl std::string::ToString for Dog { self.color.as_ref().map(|color| { - vec![ + [ "color".to_string(), color.to_string(), ].join(",") @@ -1867,7 +1867,7 @@ impl std::string::ToString for Dog { self.breed.as_ref().map(|breed| { - vec![ + [ "breed".to_string(), breed.to_string(), ].join(",") @@ -2009,7 +2009,7 @@ impl std::string::ToString for DollarSpecialLeftSquareBracketModelPeriodNameRigh let params: Vec> = vec![ self.dollar_special_left_square_bracket_property_period_name_right_square_bracket.as_ref().map(|dollar_special_left_square_bracket_property_period_name_right_square_bracket| { - vec![ + [ "$special[property.name]".to_string(), dollar_special_left_square_bracket_property_period_name_right_square_bracket.to_string(), ].join(",") @@ -2155,7 +2155,7 @@ impl std::string::ToString for EnumArrays { let params: Vec> = vec![ self.just_symbol.as_ref().map(|just_symbol| { - vec![ + [ "just_symbol".to_string(), just_symbol.to_string(), ].join(",") @@ -2163,7 +2163,7 @@ impl std::string::ToString for EnumArrays { self.array_enum.as_ref().map(|array_enum| { - vec![ + [ "array_enum".to_string(), array_enum.iter().map(|x| x.to_string()).collect::>().join(","), ].join(",") @@ -2375,7 +2375,7 @@ impl std::string::ToString for EnumTest { let params: Vec> = vec![ self.enum_string.as_ref().map(|enum_string| { - vec![ + [ "enum_string".to_string(), enum_string.to_string(), ].join(",") @@ -2387,7 +2387,7 @@ impl std::string::ToString for EnumTest { self.enum_integer.as_ref().map(|enum_integer| { - vec![ + [ "enum_integer".to_string(), enum_integer.to_string(), ].join(",") @@ -2395,7 +2395,7 @@ impl std::string::ToString for EnumTest { self.enum_number.as_ref().map(|enum_number| { - vec![ + [ "enum_number".to_string(), enum_number.to_string(), ].join(",") @@ -2578,7 +2578,7 @@ pub struct FormatTest { pub binary: Option, #[serde(rename = "date")] - pub date: chrono::DateTime::, + pub date: chrono::naive::NaiveDate, #[serde(rename = "dateTime")] #[serde(skip_serializing_if="Option::is_none")] @@ -2613,7 +2613,7 @@ fn validate_byte_formattest_byte( impl FormatTest { #[allow(clippy::new_without_default)] - pub fn new(number: f64, byte: swagger::ByteArray, date: chrono::DateTime::, password: String, ) -> FormatTest { + pub fn new(number: f64, byte: swagger::ByteArray, date: chrono::naive::NaiveDate, password: String, ) -> FormatTest { FormatTest { integer: None, int32: None, @@ -2640,7 +2640,7 @@ impl std::string::ToString for FormatTest { let params: Vec> = vec![ self.integer.as_ref().map(|integer| { - vec![ + [ "integer".to_string(), integer.to_string(), ].join(",") @@ -2648,7 +2648,7 @@ impl std::string::ToString for FormatTest { self.int32.as_ref().map(|int32| { - vec![ + [ "int32".to_string(), int32.to_string(), ].join(",") @@ -2656,7 +2656,7 @@ impl std::string::ToString for FormatTest { self.int64.as_ref().map(|int64| { - vec![ + [ "int64".to_string(), int64.to_string(), ].join(",") @@ -2668,7 +2668,7 @@ impl std::string::ToString for FormatTest { self.float.as_ref().map(|float| { - vec![ + [ "float".to_string(), float.to_string(), ].join(",") @@ -2676,7 +2676,7 @@ impl std::string::ToString for FormatTest { self.double.as_ref().map(|double| { - vec![ + [ "double".to_string(), double.to_string(), ].join(",") @@ -2684,7 +2684,7 @@ impl std::string::ToString for FormatTest { self.string.as_ref().map(|string| { - vec![ + [ "string".to_string(), string.to_string(), ].join(",") @@ -2732,7 +2732,7 @@ impl std::str::FromStr for FormatTest { pub string: Vec, pub byte: Vec, pub binary: Vec, - pub date: Vec>, + pub date: Vec, pub date_time: Vec>, pub uuid: Vec, pub password: Vec, @@ -2770,7 +2770,7 @@ impl std::str::FromStr for FormatTest { "byte" => return std::result::Result::Err("Parsing binary data in this style is not supported in FormatTest".to_string()), "binary" => return std::result::Result::Err("Parsing binary data in this style is not supported in FormatTest".to_string()), #[allow(clippy::redundant_clone)] - "date" => intermediate_rep.date.push( as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?), + "date" => intermediate_rep.date.push(::from_str(val).map_err(|x| x.to_string())?), #[allow(clippy::redundant_clone)] "dateTime" => intermediate_rep.date_time.push( as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?), #[allow(clippy::redundant_clone)] @@ -2884,7 +2884,7 @@ impl std::string::ToString for HasOnlyReadOnly { let params: Vec> = vec![ self.bar.as_ref().map(|bar| { - vec![ + [ "bar".to_string(), bar.to_string(), ].join(",") @@ -2892,7 +2892,7 @@ impl std::string::ToString for HasOnlyReadOnly { self.foo.as_ref().map(|foo| { - vec![ + [ "foo".to_string(), foo.to_string(), ].join(",") @@ -3029,7 +3029,7 @@ impl std::string::ToString for List { let params: Vec> = vec![ self.param_123_list.as_ref().map(|param_123_list| { - vec![ + [ "123-list".to_string(), param_123_list.to_string(), ].join(",") @@ -3468,7 +3468,7 @@ impl std::string::ToString for Model200Response { let params: Vec> = vec![ self.name.as_ref().map(|name| { - vec![ + [ "name".to_string(), name.to_string(), ].join(",") @@ -3476,7 +3476,7 @@ impl std::string::ToString for Model200Response { self.class.as_ref().map(|class| { - vec![ + [ "class".to_string(), class.to_string(), ].join(",") @@ -3633,7 +3633,7 @@ impl std::string::ToString for Name { self.snake_case.as_ref().map(|snake_case| { - vec![ + [ "snake_case".to_string(), snake_case.to_string(), ].join(",") @@ -3641,7 +3641,7 @@ impl std::string::ToString for Name { self.property.as_ref().map(|property| { - vec![ + [ "property".to_string(), property.to_string(), ].join(",") @@ -3649,7 +3649,7 @@ impl std::string::ToString for Name { self.param_123_number.as_ref().map(|param_123_number| { - vec![ + [ "123Number".to_string(), param_123_number.to_string(), ].join(",") @@ -3794,7 +3794,7 @@ impl std::string::ToString for NumberOnly { let params: Vec> = vec![ self.just_number.as_ref().map(|just_number| { - vec![ + [ "JustNumber".to_string(), just_number.to_string(), ].join(",") @@ -4141,7 +4141,7 @@ impl std::string::ToString for Order { let params: Vec> = vec![ self.id.as_ref().map(|id| { - vec![ + [ "id".to_string(), id.to_string(), ].join(",") @@ -4149,7 +4149,7 @@ impl std::string::ToString for Order { self.pet_id.as_ref().map(|pet_id| { - vec![ + [ "petId".to_string(), pet_id.to_string(), ].join(",") @@ -4157,7 +4157,7 @@ impl std::string::ToString for Order { self.quantity.as_ref().map(|quantity| { - vec![ + [ "quantity".to_string(), quantity.to_string(), ].join(",") @@ -4167,7 +4167,7 @@ impl std::string::ToString for Order { self.status.as_ref().map(|status| { - vec![ + [ "status".to_string(), status.to_string(), ].join(",") @@ -4175,7 +4175,7 @@ impl std::string::ToString for Order { self.complete.as_ref().map(|complete| { - vec![ + [ "complete".to_string(), complete.to_string(), ].join(",") @@ -4377,7 +4377,7 @@ impl std::string::ToString for OuterComposite { let params: Vec> = vec![ self.my_number.as_ref().map(|my_number| { - vec![ + [ "my_number".to_string(), my_number.to_string(), ].join(",") @@ -4385,7 +4385,7 @@ impl std::string::ToString for OuterComposite { self.my_string.as_ref().map(|my_string| { - vec![ + [ "my_string".to_string(), my_string.to_string(), ].join(",") @@ -4393,7 +4393,7 @@ impl std::string::ToString for OuterComposite { self.my_boolean.as_ref().map(|my_boolean| { - vec![ + [ "my_boolean".to_string(), my_boolean.to_string(), ].join(",") @@ -4699,7 +4699,7 @@ impl std::string::ToString for Pet { let params: Vec> = vec![ self.id.as_ref().map(|id| { - vec![ + [ "id".to_string(), id.to_string(), ].join(",") @@ -4719,7 +4719,7 @@ impl std::string::ToString for Pet { self.status.as_ref().map(|status| { - vec![ + [ "status".to_string(), status.to_string(), ].join(",") @@ -4875,7 +4875,7 @@ impl std::string::ToString for ReadOnlyFirst { let params: Vec> = vec![ self.bar.as_ref().map(|bar| { - vec![ + [ "bar".to_string(), bar.to_string(), ].join(",") @@ -4883,7 +4883,7 @@ impl std::string::ToString for ReadOnlyFirst { self.baz.as_ref().map(|baz| { - vec![ + [ "baz".to_string(), baz.to_string(), ].join(",") @@ -5022,7 +5022,7 @@ impl std::string::ToString for Return { let params: Vec> = vec![ self.r#return.as_ref().map(|r#return| { - vec![ + [ "return".to_string(), r#return.to_string(), ].join(",") @@ -5161,7 +5161,7 @@ impl std::string::ToString for Tag { let params: Vec> = vec![ self.id.as_ref().map(|id| { - vec![ + [ "id".to_string(), id.to_string(), ].join(",") @@ -5169,7 +5169,7 @@ impl std::string::ToString for Tag { self.name.as_ref().map(|name| { - vec![ + [ "name".to_string(), name.to_string(), ].join(",") @@ -5343,7 +5343,7 @@ impl std::string::ToString for User { let params: Vec> = vec![ self.id.as_ref().map(|id| { - vec![ + [ "id".to_string(), id.to_string(), ].join(",") @@ -5351,7 +5351,7 @@ impl std::string::ToString for User { self.username.as_ref().map(|username| { - vec![ + [ "username".to_string(), username.to_string(), ].join(",") @@ -5359,7 +5359,7 @@ impl std::string::ToString for User { self.first_name.as_ref().map(|first_name| { - vec![ + [ "firstName".to_string(), first_name.to_string(), ].join(",") @@ -5367,7 +5367,7 @@ impl std::string::ToString for User { self.last_name.as_ref().map(|last_name| { - vec![ + [ "lastName".to_string(), last_name.to_string(), ].join(",") @@ -5375,7 +5375,7 @@ impl std::string::ToString for User { self.email.as_ref().map(|email| { - vec![ + [ "email".to_string(), email.to_string(), ].join(",") @@ -5383,7 +5383,7 @@ impl std::string::ToString for User { self.password.as_ref().map(|password| { - vec![ + [ "password".to_string(), password.to_string(), ].join(",") @@ -5391,7 +5391,7 @@ impl std::string::ToString for User { self.phone.as_ref().map(|phone| { - vec![ + [ "phone".to_string(), phone.to_string(), ].join(",") @@ -5399,7 +5399,7 @@ impl std::string::ToString for User { self.user_status.as_ref().map(|user_status| { - vec![ + [ "userStatus".to_string(), user_status.to_string(), ].join(",") diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs index 72dea2e7e685..ea3e74c470f2 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs @@ -316,8 +316,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for TEST_SPECIAL_TAGS_SUCCESSFUL_OPERATION")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -415,8 +415,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("*/*") .expect("Unable to create Content-Type header for FAKE_OUTER_BOOLEAN_SERIALIZE_OUTPUT_BOOLEAN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -485,8 +485,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("*/*") .expect("Unable to create Content-Type header for FAKE_OUTER_COMPOSITE_SERIALIZE_OUTPUT_COMPOSITE")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -555,8 +555,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("*/*") .expect("Unable to create Content-Type header for FAKE_OUTER_NUMBER_SERIALIZE_OUTPUT_NUMBER")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -625,8 +625,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("*/*") .expect("Unable to create Content-Type header for FAKE_OUTER_STRING_SERIALIZE_OUTPUT_STRING")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -888,8 +888,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for TEST_CLIENT_MODEL_SUCCESSFUL_OPERATION")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -1302,8 +1302,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for TEST_CLASSNAME_SUCCESSFUL_OPERATION")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -1588,8 +1588,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/xml") .expect("Unable to create Content-Type header for FIND_PETS_BY_STATUS_SUCCESSFUL_OPERATION")); - let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, FindPetsByStatusResponse::InvalidStatusValue => { @@ -1665,8 +1665,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/xml") .expect("Unable to create Content-Type header for FIND_PETS_BY_TAGS_SUCCESSFUL_OPERATION")); - let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, FindPetsByTagsResponse::InvalidTagValue => { @@ -1739,8 +1739,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/xml") .expect("Unable to create Content-Type header for GET_PET_BY_ID_SUCCESSFUL_OPERATION")); - let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, GetPetByIdResponse::InvalidIDSupplied => { @@ -2115,8 +2115,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for UPLOAD_FILE_SUCCESSFUL_OPERATION")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -2224,8 +2224,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_INVENTORY_SUCCESSFUL_OPERATION")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -2284,8 +2284,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/xml") .expect("Unable to create Content-Type header for GET_ORDER_BY_ID_SUCCESSFUL_OPERATION")); - let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, GetOrderByIdResponse::InvalidIDSupplied => { @@ -2366,8 +2366,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/xml") .expect("Unable to create Content-Type header for PLACE_ORDER_SUCCESSFUL_OPERATION")); - let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, PlaceOrderResponse::InvalidOrder => { @@ -2712,8 +2712,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/xml") .expect("Unable to create Content-Type header for GET_USER_BY_NAME_SUCCESSFUL_OPERATION")); - let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, GetUserByNameResponse::InvalidUsernameSupplied => { @@ -2845,8 +2845,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/xml") .expect("Unable to create Content-Type header for LOGIN_USER_SUCCESSFUL_OPERATION")); - let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, LoginUserResponse::InvalidUsername => { diff --git a/samples/server/petstore/rust-server/output/ping-bearer-auth/src/client/mod.rs b/samples/server/petstore/rust-server/output/ping-bearer-auth/src/client/mod.rs index 9ce229a207f5..22eb1b5814c8 100644 --- a/samples/server/petstore/rust-server/output/ping-bearer-auth/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/ping-bearer-auth/src/client/mod.rs @@ -424,7 +424,7 @@ impl Api for Client where // Currently only authentication with Basic and Bearer are supported #[allow(clippy::single_match, clippy::match_single_binding)] match auth_data { - &AuthData::Bearer(ref bearer_header) => { + AuthData::Bearer(bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs index 96b49d463b93..0915bf515e28 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/models.rs @@ -39,7 +39,7 @@ impl std::string::ToString for ANullableContainer { let params: Vec> = vec![ self.nullable_thing.as_ref().map(|nullable_thing| { - vec![ + [ "NullableThing".to_string(), nullable_thing.as_ref().map_or("null".to_string(), |x| x.to_string()), ].join(",") @@ -225,7 +225,7 @@ impl std::string::ToString for AllOfObject { let params: Vec> = vec![ self.sample_property.as_ref().map(|sample_property| { - vec![ + [ "sampleProperty".to_string(), sample_property.to_string(), ].join(",") @@ -233,7 +233,7 @@ impl std::string::ToString for AllOfObject { self.sample_base_property.as_ref().map(|sample_base_property| { - vec![ + [ "sampleBaseProperty".to_string(), sample_base_property.to_string(), ].join(",") @@ -361,7 +361,7 @@ impl std::string::ToString for BaseAllOf { let params: Vec> = vec![ self.sample_base_property.as_ref().map(|sample_base_property| { - vec![ + [ "sampleBaseProperty".to_string(), sample_base_property.to_string(), ].join(",") @@ -493,7 +493,7 @@ impl std::string::ToString for DummyPutRequest { self.password.as_ref().map(|password| { - vec![ + [ "password".to_string(), password.to_string(), ].join(",") @@ -623,7 +623,7 @@ impl std::string::ToString for GetYamlResponse { let params: Vec> = vec![ self.value.as_ref().map(|value| { - vec![ + [ "value".to_string(), value.to_string(), ].join(",") @@ -874,7 +874,7 @@ impl std::string::ToString for ObjectOfObjectsInner { self.optional_thing.as_ref().map(|optional_thing| { - vec![ + [ "optional_thing".to_string(), optional_thing.to_string(), ].join(",") diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs index 4789b886ecde..3152eb63a364 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs @@ -182,8 +182,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("*/*") .expect("Unable to create Content-Type header for ALL_OF_GET_OK")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -320,8 +320,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for FILE_RESPONSE_GET_SUCCESS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -356,8 +356,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("application/yaml") .expect("Unable to create Content-Type header for GET_STRUCTURED_YAML_OK")); - let body = body; - *response.body_mut() = Body::from(body); + let body_content = body; + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -418,8 +418,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("text/html") .expect("Unable to create Content-Type header for HTML_POST_SUCCESS")); - let body = body; - *response.body_mut() = Body::from(body); + let body_content = body; + *response.body_mut() = Body::from(body_content); }, }, Err(_) => { @@ -521,8 +521,8 @@ impl hyper::service::Service<(Request, C)> for Service where CONTENT_TYPE, HeaderValue::from_str("*/*") .expect("Unable to create Content-Type header for RAW_JSON_GET_SUCCESS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); + let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body_content); }, }, Err(_) => {