springdoc / springdoc-openapi

Library for OpenAPI 3 with spring-boot
https://springdoc.org
Apache License 2.0
3.3k stars 501 forks source link

Parameter annotation doesn't take defaultValue attribute #868

Closed satyavemuri closed 4 years ago

satyavemuri commented 4 years ago

Describe the bug

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

image

morgado-ricardo commented 4 years ago

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;
bnasslahsen commented 4 years ago

@satyavemuri,

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

satyavemuri commented 4 years ago

Hi @bnasslahsen,

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

tgolob commented 2 years ago

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

cliffcotino commented 1 year ago

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;
        }
    }