Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Springfox class Parameter is deprecated

In Springfox 3.0, springfox.documentation.service.Parameter is deprecated.

Is there a newer way of providing the parameter and its builder?

And how to provide its default value?

like image 571
Muhammad Siddique Avatar asked Sep 20 '20 07:09

Muhammad Siddique


2 Answers

Firstly, use the RequestParameter for specify the Parameter in your Docket bean.

for its builder use RequestParameterBuilder class

RequestParameter can be look like this.

private RequestParameter authorizationParameter() {
    RequestParameterBuilder tokenBuilder = new RequestParameterBuilder();
    tokenBuilder
            .name("Authorization")
            .description("access_token")
            .required(false)
            .in("header")
            .accepts(Collections.singleton(MediaType.APPLICATION_JSON))
            .build();
    return tokenBuilder.build();
like image 59
Asad Kareem Avatar answered Sep 24 '22 21:09

Asad Kareem


@Bean
public Docket api() {
// Adding Header
RequestParameterBuilder aParameterBuilder = new RequestParameterBuilder();
aParameterBuilder.name("Cache-Control")
    .query(q -> q.defaultValue("no-cache, no-store")
        .model(modelSpecificationBuilder -> modelSpecificationBuilder.scalarModel(ScalarType.STRING)))
    .in(ParameterType.HEADER).required(true).build();

List<RequestParameter> aParameters = new ArrayList<>();
aParameters.add(aParameterBuilder.build());

return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
    .paths(PathSelectors.regex("(?!/error.*).*")).build().apiInfo(metadata())
    .globalRequestParameters(aParameters);
}
like image 21
Dumindu Avatar answered Sep 25 '22 21:09

Dumindu