2023-08-13 02:15:26 +02:00
|
|
|
package stirling.software.SPDF.config;
|
|
|
|
|
2023-12-29 22:05:32 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2023-08-13 02:15:26 +02:00
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
|
|
import io.swagger.v3.oas.models.Components;
|
|
|
|
import io.swagger.v3.oas.models.OpenAPI;
|
|
|
|
import io.swagger.v3.oas.models.info.Info;
|
2023-12-29 22:05:32 +01:00
|
|
|
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
|
|
|
import io.swagger.v3.oas.models.security.SecurityScheme;
|
|
|
|
import stirling.software.SPDF.model.ApplicationProperties;
|
2023-08-13 02:15:26 +02:00
|
|
|
|
|
|
|
@Configuration
|
|
|
|
public class OpenApiConfig {
|
|
|
|
|
2023-12-29 22:05:32 +01:00
|
|
|
@Autowired
|
|
|
|
ApplicationProperties applicationProperties;
|
|
|
|
|
2023-08-13 02:15:26 +02:00
|
|
|
@Bean
|
|
|
|
public OpenAPI customOpenAPI() {
|
2023-12-29 22:05:32 +01:00
|
|
|
String version = getClass().getPackage().getImplementationVersion();
|
|
|
|
if (version == null) {
|
|
|
|
version = "1.0.0"; // default version if all else fails
|
|
|
|
}
|
2023-08-13 02:15:26 +02:00
|
|
|
|
2023-12-29 22:05:32 +01:00
|
|
|
SecurityScheme apiKeyScheme = new SecurityScheme().type(SecurityScheme.Type.APIKEY).in(SecurityScheme.In.HEADER)
|
|
|
|
.name("X-API-KEY");
|
|
|
|
if (!applicationProperties.getSecurity().getEnableLogin()) {
|
|
|
|
return new OpenAPI().components(new Components())
|
|
|
|
.info(new Info().title("Stirling PDF API").version(version).description(
|
|
|
|
"API documentation for all Server-Side processing.\nPlease note some functionality might be UI only and missing from here."));
|
|
|
|
} else {
|
|
|
|
return new OpenAPI().components(new Components().addSecuritySchemes("apiKey", apiKeyScheme))
|
|
|
|
.info(new Info().title("Stirling PDF API").version(version).description(
|
|
|
|
"API documentation for all Server-Side processing.\nPlease note some functionality might be UI only and missing from here."))
|
|
|
|
.addSecurityItem(new SecurityRequirement().addList("apiKey"));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-08-13 02:15:26 +02:00
|
|
|
|
2023-12-29 22:05:32 +01:00
|
|
|
}
|