123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- /*
- * ********************************************************************************************************************
- *
- * :*$@@%$*: ;: ;; ;;
- * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
- * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
- * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
- * =@* %! @ $= % %@= =%@! %=
- * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
- * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
- * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
- * $@* ;@@@%=!: *@*
- * =@$ ;;;!=%@@@@=! =@!
- * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司
- * ;%@@$=$@@%* *@@@$=%@@%;
- * ::;:: ::;:: All rights reserved.
- *
- * ********************************************************************************************************************
- */
- package com.persagy
- import io.swagger.v3.oas.annotations.enums.ParameterIn
- import io.swagger.v3.oas.models.Components
- import io.swagger.v3.oas.models.OpenAPI
- import io.swagger.v3.oas.models.Operation
- import io.swagger.v3.oas.models.info.Contact
- import io.swagger.v3.oas.models.info.Info
- import io.swagger.v3.oas.models.info.License
- import io.swagger.v3.oas.models.media.StringSchema
- import io.swagger.v3.oas.models.parameters.Parameter
- import io.swagger.v3.oas.models.security.SecurityScheme
- import org.springdoc.core.GroupedOpenApi
- import org.springdoc.core.customizers.OperationCustomizer
- import org.springframework.beans.factory.annotation.Autowired
- import org.springframework.context.ApplicationContext
- import org.springframework.context.annotation.Bean
- import org.springframework.context.annotation.Configuration
- import org.springframework.web.method.HandlerMethod
- /**
- * RESTful API文档生成器Swagger2配置
- *
- * @author PLX
- */
- @Configuration
- open class Swagger3Config {
- /** 注入的 ApplicationContext */
- @Autowired
- lateinit var applicationContext: ApplicationContext
- /** 标题 */
- private val title = "美库(图例库) API"
- /** API 版本号 */
- private val version = "1.0"
- val operationCustomizer = GlobalHeaderOperationCustomizer()
- /**
- * API 信息
- */
- @Bean
- open fun openApi(): OpenAPI {
- val contact = Contact().name("张维新").email("zhangweixin@sagacloud.cn")
- return OpenAPI()
- .components(
- Components()
- .addSecuritySchemes("basicScheme", SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
- .info(
- Info()
- .title(title)
- .version(version)
- .termsOfService("http://www.persagy.com")
- .contact(contact)
- .license(
- License()
- .name("Apache 2.0")
- .url("http://www.persagy.com")))
- }
- @Bean
- open fun publicApi(): GroupedOpenApi? {
- return GroupedOpenApi.builder()
- .group("默认")
- .pathsToMatch("/**")
- .addOperationCustomizer(operationCustomizer)
- .build()
- }
- @Bean
- open fun umlApi(): GroupedOpenApi? {
- return GroupedOpenApi.builder()
- .group("uml")
- .pathsToMatch("/uml/**")
- .build()
- }
- // /**
- // * 字典 API 组
- // */
- // @Bean
- // open fun dictApiGroup(): GroupedOpenApi {
- // return GroupedOpenApi.builder().group("asf").pathsToMatch("")
- // .build()
- //
- // }
- // /**
- // * 对象 API 组
- // */
- // @Bean
- // open fun objectApiGroup(): GroupedOpenApi {
- // return GroupedOpenApi.builder()
- // .group("对象")
- // .pathsToMatch("/object/**")
- // .addOperationCustomizer(operationCustomizer)
- // .build()
- // }
- } // Class Swagger2Config
- /**
- * 全局参数
- *
- * @author 庞利祥 <sybotan@126.com>
- */
- class GlobalHeaderOperationCustomizer : OperationCustomizer {
- /**
- * 接口定义器
- *
- * @param operation 接口
- * @param handlerMethod 原接口方法
- * @return 新定义的接口
- */
- override fun customize(operation: Operation, handlerMethod: HandlerMethod): Operation {
- val projectId = Parameter().`in`(ParameterIn.HEADER.toString())
- .name("projectId").description("项目 id")
- .schema(StringSchema()).required(false)
- operation.addParametersItem(projectId)
- return operation
- }
- }
|