springdoc-openapi icon indicating copy to clipboard operation
springdoc-openapi copied to clipboard

Parameter annotation doesn't take defaultValue attribute

Open satyavemuri opened this issue 6 years ago • 5 comments

Describe the bug

  • io.swagger.v3.oas.annotations.Parameter doesn't have defaultValue attribute which is required in our case because we have default value available for one of our query parameters and also we were migrating from io.springfox for swagger2.0 and which was supporting it.
  • May I know, is there any reason for not having it?

Version: 'org.springdoc:springdoc-openapi-ui:1.4.6'

image

satyavemuri avatar Sep 16 '20 05:09 satyavemuri

I believe the defaultValue is part of the @Schema and not the @Parameter.

See the example below (from this sample project):

    @Schema(description = "Test enum object", defaultValue = "TestEnum.C")
    @NotNull
    @JsonProperty("testEnum")
    private TestEnum testEnum = TestEnum.C;

morgado-ricardo avatar Sep 16 '20 09:09 morgado-ricardo

@satyavemuri,

The class io.swagger.v3.oas.annotations.Parameter is not a springdoc-openapi class. Please raison your question on the swagger github instead.

bnasslahsen avatar Sep 17 '20 10:09 bnasslahsen

Hi @bnasslahsen,

Thanks for the response, I will raise the issue in Swagger Github.

satyavemuri avatar Sep 17 '20 21:09 satyavemuri

for convenience: https://github.com/swagger-api/swagger-core/issues/4174

tgolob avatar Oct 11 '22 20:10 tgolob

We also ran into this issue and were able to make the following workaround in cases where there was a @Parameter annotated parameter that also had a @org.springframework.web.bind.annotation.RequestParam annotation.

    @Component
    public class DefaultValueParameterCustomizer implements ParameterCustomizer {
        @Override
        public Parameter customize(Parameter parameterModel, MethodParameter methodParameter) {
            RequestParam requestParamAnnotation = methodParameter.getParameterAnnotation(RequestParam.class);
            if (requestParamAnnotation != null &&
                 !ValueConstants.DEFAULT_NONE.equals(requestParamAnnotation.defaultValue())) {
                String defaultValue = requestParamAnnotation.defaultValue();
                parameterModel.setExtensions(new HashMap<>());
                parameterModel.getExtensions().put("default", defaultValue);
            }
            return parameterModel;
        }
    }

cliffcotino avatar Jun 23 '23 12:06 cliffcotino