Order rest APIs in openapi doc (#2438)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -9,11 +9,17 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.rest.resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import io.swagger.v3.oas.models.servers.ServerVariable;
|
||||
import io.swagger.v3.oas.models.servers.ServerVariables;
|
||||
import org.eclipse.hawkbit.rest.OpenApiConfiguration;
|
||||
import org.springdoc.core.models.GroupedOpenApi;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -30,11 +36,11 @@ public class MgmtOpenApiConfiguration {
|
||||
value = "hawkbit.server.openapi.mgmt.enabled",
|
||||
havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
public GroupedOpenApi mgmtApi() {
|
||||
public GroupedOpenApi mgmtApi(@Value("${hawkbit.server.openapi.mgmt.tenant-endpoint.enabled:false}") final boolean tenantEndpointEnabled) {
|
||||
return GroupedOpenApi
|
||||
.builder()
|
||||
.group("Management API")
|
||||
.pathsToMatch("/rest/v*/**", "/{tenant}/rest/v*/**")
|
||||
.pathsToMatch(tenantEndpointEnabled ? new String[] { "/rest/v*/**", "/{tenant}/rest/v*/**" } : new String[] { "/rest/v*/**" })
|
||||
.addOpenApiCustomizer(openApi ->
|
||||
openApi
|
||||
.info(new Info()
|
||||
@@ -43,6 +49,13 @@ public class MgmtOpenApiConfiguration {
|
||||
The Management API provides access to the management features of the hawkBit.
|
||||
It allows for managing devices, deployments, and other.
|
||||
"""))
|
||||
.servers(tenantEndpointEnabled
|
||||
? List.of(
|
||||
new Server()
|
||||
.url("/{tenant}/")
|
||||
.variables(new ServerVariables().addServerVariable("tenant", tenantSeverVariable())),
|
||||
new Server().url("/"))
|
||||
: List.of(new Server().url("/")))
|
||||
.addSecurityItem(new SecurityRequirement()
|
||||
.addList(BASIC_AUTH_SEC_SCHEME_NAME)
|
||||
.addList(BEARER_AUTH_SEC_SCHEME_NAME))
|
||||
@@ -52,14 +65,16 @@ public class MgmtOpenApiConfiguration {
|
||||
.addSecuritySchemes(BASIC_AUTH_SEC_SCHEME_NAME,
|
||||
new SecurityScheme()
|
||||
.name(BASIC_AUTH_SEC_SCHEME_NAME)
|
||||
.description(BASIC_AUTH_SEC_SCHEME_NAME + " Authentication")
|
||||
.description(
|
||||
BASIC_AUTH_SEC_SCHEME_NAME + " Authentication")
|
||||
.type(SecurityScheme.Type.HTTP)
|
||||
.in(SecurityScheme.In.HEADER)
|
||||
.scheme("basic"))
|
||||
.addSecuritySchemes(BEARER_AUTH_SEC_SCHEME_NAME,
|
||||
new SecurityScheme()
|
||||
.name(BEARER_AUTH_SEC_SCHEME_NAME)
|
||||
.description(BEARER_AUTH_SEC_SCHEME_NAME + " Authentication")
|
||||
.description(
|
||||
BEARER_AUTH_SEC_SCHEME_NAME + " Authentication")
|
||||
.type(SecurityScheme.Type.HTTP)
|
||||
.in(SecurityScheme.In.HEADER)
|
||||
.bearerFormat("JWT")
|
||||
@@ -67,4 +82,11 @@ public class MgmtOpenApiConfiguration {
|
||||
.tags(OpenApiConfiguration.sort(openApi.getTags())))
|
||||
.build();
|
||||
}
|
||||
|
||||
private static ServerVariable tenantSeverVariable() {
|
||||
final ServerVariable tenantServerVariable = new ServerVariable();
|
||||
tenantServerVariable.setDescription("Tenant identifier");
|
||||
tenantServerVariable.setDefault("DEFAULT");
|
||||
return tenantServerVariable;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user