| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * Swagger 文档配置 |
| | |
| | | openApi.tags(swaggerProperties.getTags()); |
| | | openApi.paths(swaggerProperties.getPaths()); |
| | | openApi.components(swaggerProperties.getComponents()); |
| | | Set<String> keySet = swaggerProperties.getComponents().getSecuritySchemes().keySet(); |
| | | List<SecurityRequirement> list = new ArrayList<>(); |
| | | list.add(new SecurityRequirement().addList("apikey")); |
| | | SecurityRequirement securityRequirement = new SecurityRequirement(); |
| | | keySet.forEach(securityRequirement::addList); |
| | | list.add(securityRequirement); |
| | | openApi.security(list); |
| | | |
| | | return openApi; |
| | |
| | | // 对所有路径增加前置上下文路径 |
| | | return openApi -> { |
| | | Paths oldPaths = openApi.getPaths(); |
| | | Paths newPaths = new Paths(); |
| | | if (oldPaths instanceof PlusPaths) { |
| | | return; |
| | | } |
| | | PlusPaths newPaths = new PlusPaths(); |
| | | oldPaths.forEach((k,v) -> newPaths.addPathItem(finalContextPath + k, v)); |
| | | openApi.setPaths(newPaths); |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * 单独使用一个类便于判断 解决springdoc路径拼接重复问题 |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | static class PlusPaths extends Paths { |
| | | |
| | | public PlusPaths() { |
| | | super(); |
| | | } |
| | | } |
| | | |
| | | } |