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?
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();
@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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With