2024-01-03 17:59:04 +00:00
|
|
|
package stirling.software.SPDF.config;
|
|
|
|
|
|
|
|
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;
|
2025-05-14 00:06:14 +02:00
|
|
|
import io.swagger.v3.oas.models.info.Contact;
|
2024-01-03 17:59:04 +00:00
|
|
|
import io.swagger.v3.oas.models.info.Info;
|
2025-05-14 00:06:14 +02:00
|
|
|
import io.swagger.v3.oas.models.info.License;
|
2024-01-03 17:59:04 +00:00
|
|
|
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
|
|
|
import io.swagger.v3.oas.models.security.SecurityScheme;
|
|
|
|
|
2025-04-25 15:35:12 +02:00
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
2024-01-03 17:59:04 +00:00
|
|
|
import stirling.software.SPDF.model.ApplicationProperties;
|
|
|
|
|
|
|
|
@Configuration
|
2025-04-25 15:35:12 +02:00
|
|
|
@RequiredArgsConstructor
|
2024-01-03 17:59:04 +00:00
|
|
|
public class OpenApiConfig {
|
|
|
|
|
2024-12-24 09:52:53 +00:00
|
|
|
private final ApplicationProperties applicationProperties;
|
|
|
|
|
2025-04-25 15:35:12 +02:00
|
|
|
private static final String DEFAULT_TITLE = "Stirling PDF API";
|
|
|
|
private static final String DEFAULT_DESCRIPTION =
|
|
|
|
"API documentation for all Server-Side processing.\n"
|
|
|
|
+ "Please note some functionality might be UI only and missing from here.";
|
2024-01-03 17:59:04 +00:00
|
|
|
|
|
|
|
@Bean
|
|
|
|
public OpenAPI customOpenAPI() {
|
|
|
|
String version = getClass().getPackage().getImplementationVersion();
|
|
|
|
if (version == null) {
|
2024-12-24 09:52:53 +00:00
|
|
|
// default version if all else fails
|
|
|
|
version = "1.0.0";
|
2024-01-03 17:59:04 +00:00
|
|
|
}
|
2025-05-14 00:06:14 +02:00
|
|
|
Info info =
|
|
|
|
new Info()
|
|
|
|
.title(DEFAULT_TITLE)
|
|
|
|
.version(version)
|
|
|
|
.license(
|
|
|
|
new License()
|
|
|
|
.name("MIT")
|
|
|
|
.url(
|
|
|
|
"https://raw.githubusercontent.com/Stirling-Tools/Stirling-PDF/refs/heads/main/LICENSE")
|
|
|
|
.identifier("MIT"))
|
|
|
|
.termsOfService("https://www.stirlingpdf.com/terms")
|
|
|
|
.contact(
|
|
|
|
new Contact()
|
|
|
|
.name("Stirling Software")
|
|
|
|
.url("https://www.stirlingpdf.com")
|
|
|
|
.email("contact@stirlingpdf.com"))
|
|
|
|
.description(DEFAULT_DESCRIPTION);
|
2024-01-03 17:59:04 +00:00
|
|
|
if (!applicationProperties.getSecurity().getEnableLogin()) {
|
2025-05-14 00:06:14 +02:00
|
|
|
return new OpenAPI().components(new Components()).info(info);
|
2024-01-03 17:59:04 +00:00
|
|
|
} else {
|
2025-04-25 15:35:12 +02:00
|
|
|
SecurityScheme apiKeyScheme =
|
|
|
|
new SecurityScheme()
|
|
|
|
.type(SecurityScheme.Type.APIKEY)
|
|
|
|
.in(SecurityScheme.In.HEADER)
|
|
|
|
.name("X-API-KEY");
|
2024-01-03 17:59:04 +00:00
|
|
|
return new OpenAPI()
|
|
|
|
.components(new Components().addSecuritySchemes("apiKey", apiKeyScheme))
|
2025-05-14 00:06:14 +02:00
|
|
|
.info(info)
|
2024-01-03 17:59:04 +00:00
|
|
|
.addSecurityItem(new SecurityRequirement().addList("apiKey"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|