Swagger、OpenAPI和springdoc-openapi-ui入门
import org.springdoc.core.SwaggerUiConfigProperties;
import org.springdoc.core.SwaggerUiOAuthProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfig {
@Bean
public SwaggerUiConfigProperties customSwaggerUiConfig() {
SwaggerUiConfigProperties properties = new SwaggerUiConfigProperties();
properties.setUrl("/swagger-ui-custom.html"); // 自定义swagger-ui路径
return properties;
}
@Bean
public SwaggerUiOAuthProperties swaggerUiOAuthProperties() {
SwaggerUiOAuthProperties properties = new SwaggerUiOAuthProperties();
properties.setAppName("My API");
properties.setClientId("client-id");
properties.setClientSecret("client-secret");
properties.setRealm("my-realm");
properties.setScopes("scope-a,scope-b");
properties.setBaseUrl(null);
return properties;
}
}
这段代码演示了如何在Spring Boot应用程序中配置自定义的Swagger UI路径和OAuth设置。通过定义SwaggerUiConfigProperties
和SwaggerUiOAuthProperties
的Bean,开发者可以根据自己的需求调整Swagger UI的行为。
评论已关闭