Please make either SecurityConfiguration#DEFAULT public or the default constructor public
See original GitHub issueVersion: [2.6.1]
Issue
In 2.5.1, the springfox.documentation.swagger.web.SecurityConfiguration#DEFAULT
field is public, as is shown here: https://github.com/springfox/springfox/blob/2.5.0/springfox-swagger-common/src/main/java/springfox/documentation/swagger/web/SecurityConfiguration.java#L26. However this was changed in 2.6.x. I’d like to know the reason why it has been changed. And if possible, please make it public again to accommodate the following use case.
Use case
Programmatically configure Swagger’s API key, example code in 2.5.0:
@EnableSwagger2
@Configuration
class SwaggerConfiguration {
private ApiKey apiKey = null;
@PostConstruct
void init() {
// some logic to assign apiKey according to some configuration
}
@Bean
springfox.documentation.swagger.web.SecurityConfiguration security() {
if (this.apiKey == null) {
return springfox.documentation.swagger.web.SecurityConfiguration.DEFAULT;
} else {
return new springfox.documentation.swagger.web.SecurityConfiguration(null, null, null, null,
"Your access token", ApiKeyVehicle.HEADER, apiKey.getKeyname(), null);
}
}
Now 2.6.x in order to use the default security config, one needs to do the following, which is very cumbersome.
@EnableSwagger2
@Configuration
class SwaggerConfiguration {
// This line is really cumbersome, and will potentially cause issues if the default parameters don't match with Swagger's.
private static final springfox.documentation.swagger.web.SecurityConfiguration DEFAULT_SWAGGER_SECURITY_CONFIG =
new springfox.documentation.swagger.web.SecurityConfiguration(null, null, null, null, null, ApiKeyVehicle.HEADER, "api_key", ",");
private ApiKey apiKey = null;
@PostConstruct
void init() {
// some logic to assign apiKey according to some configuration
}
@Bean
springfox.documentation.swagger.web.SecurityConfiguration security() {
if (this.apiKey == null) {
return springfox.documentation.swagger.web.SecurityConfiguration.DEFAULT;
} else {
return new springfox.documentation.swagger.web.SecurityConfiguration(null, null, null, null,
"Your access token", ApiKeyVehicle.HEADER, apiKey.getKeyname(), null);
}
}
Ideal Solution
Please make either of the following public:
springfox.documentation.swagger.web.SecurityConfiguration#DEFAULT
SecurityConfiguration
’s default constructor
Or please advise other ways or workarounds.
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
java - No primary or default constructor found for interface org ...
The selected solution is a workaround. You can make Spring resolve the parameters automatically using this configuration :
Read more >Constructor in Java - DigitalOcean
Let's look at a simple program where default constructor is being used since we will not explicitly define a constructor. package com.journaldev ...
Read more >CA2132: Default constructors must be at least as critical as ...
The transparency attribute of the default constructor of a derived class is not as critical as the transparency of the base class.
Read more >Java Access Modifiers - Public, Private, Protected & Default
It means that a private constructor can be called from public constructors and even from static methods inside the same class. 1). Default ......
Read more >Why is there no default constructor generated if you define an ...
First of all, default constructor is not generated, its provided by compiler if no-argument constructor is not written explicitly. When you do not ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Closing this issue for now. We can reopen if you feel strongly after the 2.7.0 release
@dilipkrish We can use annotations like @NotNull with lombok. Or if more control is needed we can use factory method annotated with @Builder https://stackoverflow.com/questions/36909672/how-to-use-lombok-builder-annotation-on-methods