diff --git a/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/GenericParameterService.java b/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/GenericParameterService.java index 0b8b15181..5162cc5ee 100644 --- a/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/GenericParameterService.java +++ b/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/GenericParameterService.java @@ -303,7 +303,7 @@ public Parameter buildParameterFromDoc(io.swagger.v3.oas.annotations.Parameter p optionalContent.ifPresent(parameter::setContent); } else - setSchema(parameterDoc, components, jsonView, parameter); + setSchema(parameterDoc, components, jsonView, parameter, locale); setExamples(parameterDoc, parameter); setExtensions(parameterDoc, parameter, locale); @@ -320,8 +320,9 @@ public Parameter buildParameterFromDoc(io.swagger.v3.oas.annotations.Parameter p * @param components the components * @param jsonView the json view * @param parameter the parameter + * @param locale the locale */ - private void setSchema(io.swagger.v3.oas.annotations.Parameter parameterDoc, Components components, JsonView jsonView, Parameter parameter) { + private void setSchema(io.swagger.v3.oas.annotations.Parameter parameterDoc, Components components, JsonView jsonView, Parameter parameter, Locale locale) { if (StringUtils.isNotBlank(parameterDoc.ref())) parameter.$ref(parameterDoc.ref()); else { @@ -335,7 +336,11 @@ private void setSchema(io.swagger.v3.oas.annotations.Parameter parameterDoc, Com PrimitiveType primitiveType = PrimitiveType.fromTypeAndFormat(schema.getType(), schema.getFormat()); if (primitiveType != null) { Schema primitiveSchema = primitiveType.createProperty(); - primitiveSchema.setDefault(schema.getDefault()); + if (schema.getDefault() instanceof String stringValue) { + primitiveSchema.setDefault(propertyResolverUtils.resolve(stringValue, locale)); + } else { + primitiveSchema.setDefault(schema.getDefault()); + } schema.setDefault(primitiveSchema.getDefault()); } } diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app139/HelloController.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app139/HelloController.java index 3d0867692..a900f8262 100644 --- a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app139/HelloController.java +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app139/HelloController.java @@ -24,6 +24,9 @@ package test.org.springdoc.api.v30.app139; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Schema; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -33,6 +36,10 @@ public class HelloController { @GetMapping(produces = MediaType.TEXT_PLAIN_VALUE, path = "/test1") + @Parameter(name = "parameter", in = ParameterIn.QUERY, + schema = @Schema(type = "string", defaultValue = "${test.parameter-default-value}")) + @Parameter(name = "parameter-boolean", in = ParameterIn.QUERY, + schema = @Schema(type = "boolean", defaultValue = "${test.parameter-boolean-default-value}")) public String echo1(@RequestParam(name = "${test.name}", defaultValue = "${test.default-value}") String text) { return text; } diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app139/SpringDocApp139Test.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app139/SpringDocApp139Test.java index 1c3105e69..6d107e44d 100644 --- a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app139/SpringDocApp139Test.java +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app139/SpringDocApp139Test.java @@ -23,16 +23,21 @@ */ package test.org.springdoc.api.v30.app139; -import test.org.springdoc.api.v30.AbstractSpringDocV30Test; - import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.test.context.TestPropertySource; +import test.org.springdoc.api.v30.AbstractSpringDocV30Test; /** * Tests Spring meta-annotations as method parameters */ -@TestPropertySource(properties = { "test.name=text", "test.value=text", "test.default-value=default-text" }) +@TestPropertySource(properties = { + "test.name=text", + "test.value=text", + "test.default-value=default-text", + "test.parameter-default-value=parameter-text", + "test.parameter-boolean-default-value=true" +}) public class SpringDocApp139Test extends AbstractSpringDocV30Test { @SpringBootApplication diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app139/HelloController.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app139/HelloController.java index e078830da..40537687d 100644 --- a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app139/HelloController.java +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app139/HelloController.java @@ -24,6 +24,9 @@ package test.org.springdoc.api.v31.app139; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Schema; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -33,6 +36,10 @@ public class HelloController { @GetMapping(produces = MediaType.TEXT_PLAIN_VALUE, path = "/test1") + @Parameter(name = "parameter", in = ParameterIn.QUERY, + schema = @Schema(type = "string", defaultValue = "${test.parameter-default-value}")) + @Parameter(name = "parameter-boolean", in = ParameterIn.QUERY, + schema = @Schema(type = "boolean", defaultValue = "${test.parameter-boolean-default-value}")) public String echo1(@RequestParam(name = "${test.name}", defaultValue = "${test.default-value}") String text) { return text; } diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app139/SpringDocApp139Test.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app139/SpringDocApp139Test.java index d2c46fef9..1b0266007 100644 --- a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app139/SpringDocApp139Test.java +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app139/SpringDocApp139Test.java @@ -32,7 +32,13 @@ /** * Tests Spring meta-annotations as method parameters */ -@TestPropertySource(properties = { "test.name=text", "test.value=text", "test.default-value=default-text" }) +@TestPropertySource(properties = { + "test.name=text", + "test.value=text", + "test.default-value=default-text", + "test.parameter-default-value=parameter-text", + "test.parameter-boolean-default-value=true" +}) public class SpringDocApp139Test extends AbstractSpringDocTest { @SpringBootApplication diff --git a/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app139.json b/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app139.json index eb7e86680..64c04b550 100644 --- a/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app139.json +++ b/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app139.json @@ -57,6 +57,22 @@ "type": "string", "default": "default-text" } + }, + { + "name" : "parameter", + "in" : "query", + "schema" : { + "type" : "string", + "default": "parameter-text" + } + }, + { + "name" : "parameter-boolean", + "in" : "query", + "schema" : { + "type" : "boolean", + "default": true + } } ], "responses": { diff --git a/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app139.json b/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app139.json index 72b1c7d6e..b597f5b81 100644 --- a/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app139.json +++ b/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app139.json @@ -57,6 +57,22 @@ "type": "string", "default": "default-text" } + }, + { + "name" : "parameter", + "in" : "query", + "schema" : { + "type" : "string", + "default": "parameter-text" + } + }, + { + "name" : "parameter-boolean", + "in" : "query", + "schema" : { + "type" : "boolean", + "default": true + } } ], "responses": {