From ec98693da51e1fe578ade00fb821efa60b6b1319 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 19 Oct 2024 15:56:07 +0800 Subject: [PATCH] fix accepts, contentType with unescaped values (#19915) --- .../main/resources/Java/libraries/rest-assured/api.mustache | 4 ++-- .../src/main/resources/JavaSpring/api.mustache | 2 +- .../JavaSpring/libraries/spring-http-interface/api.mustache | 2 +- .../server/test/controller_test.groovy.mustache | 4 ++-- .../java-micronaut/server/test/controller_test.mustache | 4 ++-- .../src/main/resources/java-pkmst/api.mustache | 2 +- .../src/main/resources/kotlin-spring/api.mustache | 2 +- .../src/main/resources/kotlin-spring/apiInterface.mustache | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/api.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/api.mustache index 8ccff676f1ae..f865f0956400 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/api.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/api.mustache @@ -155,9 +155,9 @@ public class {{classname}} { this.reqSpec = reqSpec; {{#vendorExtensions}} {{#x-content-type}} - reqSpec.setContentType("{{x-content-type}}"); + reqSpec.setContentType("{{{x-content-type}}}"); {{/x-content-type}} - reqSpec.setAccept("{{#x-accepts}}{{.}}{{^-last}},{{/-last}}{{/x-accepts}}"); + reqSpec.setAccept("{{#x-accepts}}{{{.}}}{{^-last}},{{/-last}}{{/x-accepts}}"); {{/vendorExtensions}} this.respSpec = new ResponseSpecBuilder(); } diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache index d6609ff960c0..ca566b626bd5 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache @@ -233,7 +233,7 @@ public interface {{classname}} { @RequestMapping( method = RequestMethod.{{httpMethod}}, value = "{{{path}}}"{{#singleContentTypes}}{{#hasProduces}}, - produces = { {{#vendorExtensions.x-accepts}}"{{.}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}} }{{/hasProduces}}{{#hasConsumes}}, + produces = { {{#vendorExtensions.x-accepts}}"{{{.}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}} }{{/hasProduces}}{{#hasConsumes}}, consumes = "{{{vendorExtensions.x-content-type}}}"{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}, produces = { {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }{{/hasProduces}}{{#hasConsumes}}, consumes = { {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }{{/hasConsumes}}{{/singleContentTypes}}{{#hasVersionHeaders}}, diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/api.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/api.mustache index a0808e35bf15..da85695b0288 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/api.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/api.mustache @@ -54,7 +54,7 @@ public interface {{classname}} { @HttpExchange( method = "{{{httpMethod}}}", value = "{{{path}}}", - accept = { {{#vendorExtensions.x-accepts}}"{{.}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}} }{{#vendorExtensions.x-content-type}}, + accept = { {{#vendorExtensions.x-accepts}}"{{{.}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}} }{{#vendorExtensions.x-content-type}}, contentType = "{{{vendorExtensions.x-content-type}}}"{{/vendorExtensions.x-content-type}} ) {{>responseType}} {{operationId}}( diff --git a/modules/openapi-generator/src/main/resources/java-micronaut/server/test/controller_test.groovy.mustache b/modules/openapi-generator/src/main/resources/java-micronaut/server/test/controller_test.groovy.mustache index de981e9639d8..04da306a8cf1 100644 --- a/modules/openapi-generator/src/main/resources/java-micronaut/server/test/controller_test.groovy.mustache +++ b/modules/openapi-generator/src/main/resources/java-micronaut/server/test/controller_test.groovy.mustache @@ -139,10 +139,10 @@ class {{classname}}Spec extends Specification { MutableHttpRequest request = HttpRequest.{{httpMethod}}{{#vendorExtensions.methodAllowsBody}}{{#bodyParam}}(uri, body){{/bodyParam}}{{#isMultipart}}{{^formParams}}(uri, body){{/formParams}}{{/isMultipart}}{{#formParams.0}}(uri, form){{/formParams.0}}{{^bodyParam}}{{^isMultipart}}{{^formParams}}(uri, null){{/formParams}}{{/isMultipart}}{{/bodyParam}}{{/vendorExtensions.methodAllowsBody}}{{^vendorExtensions.methodAllowsBody}}(uri){{/vendorExtensions.methodAllowsBody}} {{!Fill in all the request parameters}} {{#vendorExtensions.x-content-type}} - .contentType('{{vendorExtensions.x-content-type}}') + .contentType('{{{vendorExtensions.x-content-type}}}') {{/vendorExtensions.x-content-type}} {{#vendorExtensions.x-accepts}} - .accept('{{vendorExtensions.x-accepts}}') + .accept('{{{vendorExtensions.x-accepts}}}') {{/vendorExtensions.x-accepts}} {{#headerParams}} .header('{{{baseName}}}', {{{vendorExtensions.groovyExample}}}{{^isString}}.toString(){{/isString}}) diff --git a/modules/openapi-generator/src/main/resources/java-micronaut/server/test/controller_test.mustache b/modules/openapi-generator/src/main/resources/java-micronaut/server/test/controller_test.mustache index 75cb7bd30b8b..6e7fe03a61ca 100644 --- a/modules/openapi-generator/src/main/resources/java-micronaut/server/test/controller_test.mustache +++ b/modules/openapi-generator/src/main/resources/java-micronaut/server/test/controller_test.mustache @@ -146,8 +146,8 @@ public class {{classname}}Test { {{closebrace}}{{closebrace}}{{/pathParams.0}}); {{!Create the request with body and uri}} MutableHttpRequest request = HttpRequest.{{httpMethod}}{{#vendorExtensions.methodAllowsBody}}{{#bodyParam}}(uri, body){{/bodyParam}}{{#isMultipart}}{{^formParams}}(uri, body){{/formParams}}{{/isMultipart}}{{#formParams.0}}(uri, form){{/formParams.0}}{{^bodyParam}}{{^isMultipart}}{{^formParams}}(uri, null){{/formParams}}{{/isMultipart}}{{/bodyParam}}{{/vendorExtensions.methodAllowsBody}}{{^vendorExtensions.methodAllowsBody}}(uri){{/vendorExtensions.methodAllowsBody}}{{!Fill in all the request parameters}}{{#vendorExtensions.x-contentType}} - .contentType("{{vendorExtensions.x-contentType}}"){{/vendorExtensions.x-contentType}}{{#vendorExtensions.x-accepts}} - .accept("{{vendorExtensions.x-accepts}}"){{/vendorExtensions.x-accepts}}{{#headerParams}} + .contentType("{{{vendorExtensions.x-contentType}}}"){{/vendorExtensions.x-contentType}}{{#vendorExtensions.x-accepts}} + .accept("{{{vendorExtensions.x-accepts}}}"){{/vendorExtensions.x-accepts}}{{#headerParams}} .header("{{{baseName}}}", {{^isString}}String.valueOf({{/isString}}{{{example}}}{{^isString}}){{/isString}}){{/headerParams}}{{#cookieParams}} .cookie(Cookie.of("{{{baseName}}}", {{{example}}})){{/cookieParams}}; {{!Fill in the query parameters}} diff --git a/modules/openapi-generator/src/main/resources/java-pkmst/api.mustache b/modules/openapi-generator/src/main/resources/java-pkmst/api.mustache index 8da721448f56..f24464e8b3d0 100644 --- a/modules/openapi-generator/src/main/resources/java-pkmst/api.mustache +++ b/modules/openapi-generator/src/main/resources/java-pkmst/api.mustache @@ -58,7 +58,7 @@ public interface {{classname}} { @RequestMapping( method = RequestMethod.{{httpMethod}}, value = "{{{path}}}"{{#singleContentTypes}}, - produces = { {{#vendorExtensions.x-accepts}}"{{.}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}} }, + produces = { {{#vendorExtensions.x-accepts}}"{{{.}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}} }, consumes = "{{{vendorExtensions.x-content-type}}}"{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}, produces = { {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }{{/hasProduces}}{{#hasConsumes}}, consumes = { {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }{{/hasConsumes}}{{/singleContentTypes}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/api.mustache index 6220601fe64a..9257b1b52f7a 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/api.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/api.mustache @@ -84,7 +84,7 @@ class {{classname}}Controller({{#serviceInterface}}@Autowired(required = true) v @RequestMapping( method = [RequestMethod.{{httpMethod}}], value = ["{{#lambdaEscapeInNormalString}}{{path}}{{/lambdaEscapeInNormalString}}"]{{#singleContentTypes}}{{#hasProduces}}, - produces = [{{#vendorExtensions.x-accepts}}"{{.}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}}]{{/hasProduces}}{{#hasConsumes}}, + produces = [{{#vendorExtensions.x-accepts}}"{{{.}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}}]{{/hasProduces}}{{#hasConsumes}}, consumes = "{{{vendorExtensions.x-content-type}}}"{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}, produces = [{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}]{{/hasProduces}}{{#hasConsumes}}, consumes = [{{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}]{{/hasConsumes}}{{/singleContentTypes}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache index 8c436c764dbb..fd6d88119c98 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache @@ -97,7 +97,7 @@ interface {{classname}} { @RequestMapping( method = [RequestMethod.{{httpMethod}}], value = ["{{#lambdaEscapeInNormalString}}{{path}}{{/lambdaEscapeInNormalString}}"]{{#singleContentTypes}}{{#hasProduces}}, - produces = [{{#vendorExtensions.x-accepts}}"{{.}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}}]{{/hasProduces}}{{#hasConsumes}}, + produces = [{{#vendorExtensions.x-accepts}}"{{{.}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}}]{{/hasProduces}}{{#hasConsumes}}, consumes = "{{{vendorExtensions.x-content-type}}}"{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}, produces = [{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}]{{/hasProduces}}{{#hasConsumes}}, consumes = [{{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}]{{/hasConsumes}}{{/singleContentTypes}}