SpringBoot3 Swagger笔记整理

@Configuration public class SwaggerConfig { @Bean public OpenAPI springShopOpenAPI() { return new OpenAPI() .info(new Info().title("SpringShop API") .description("Spring shop sample application") .version("v0.0.1") .license(new License().name("Apache 2.0").url("https://springdoc.org"))) .addSecurityItem(buildSecurityRequirement()) .components(new Components().securitySchemes(buildSecuritySchemes())) .externalDocs(new ExternalDocumentation() .description("SpringShop Wiki Documentation") .url("https://springshop.wiki.github.org/docs")); } private SecurityRequirement buildSecurityRequirement() { SecurityRequirement securityRequirement = new SecurityRequirement(); securityRequirement.addList("token"); securityRequirement.addList("basic"); return securityRequirement; } private Map<String, SecurityScheme> buildSecuritySchemes() { Map<String, SecurityScheme> securitySchemes = new HashMap<>(); // token SecurityScheme token = new SecurityScheme() .type(SecurityScheme.Type.APIKEY) // 类型 .name("token") // 请求头的 name .in(SecurityScheme.In.HEADER); securitySchemes.put("token", token); // basic SecurityScheme basic = new SecurityScheme() .type(SecurityScheme.Type.APIKEY) // 类型 .name("Authorization") .in(SecurityScheme.In.HEADER) ; securitySchemes.put("basic", basic); return securitySchemes; } }
上一篇:从耐用到防水:全面综合评估SD卡的性能指标


下一篇:CRM如何助力企业内部高效管理?