diff --git a/launchers/standalone/pom.xml b/launchers/standalone/pom.xml index 7ca39e04a..472741e29 100644 --- a/launchers/standalone/pom.xml +++ b/launchers/standalone/pom.xml @@ -71,13 +71,6 @@ auth-api ${project.version} - - - io.springfox - springfox-boot-starter - 3.0.0 - - junit junit diff --git a/launchers/standalone/src/main/java/com/tencent/supersonic/StandaloneLauncher.java b/launchers/standalone/src/main/java/com/tencent/supersonic/StandaloneLauncher.java index a6de486bd..e00593228 100644 --- a/launchers/standalone/src/main/java/com/tencent/supersonic/StandaloneLauncher.java +++ b/launchers/standalone/src/main/java/com/tencent/supersonic/StandaloneLauncher.java @@ -6,13 +6,11 @@ import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfigurat import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; -import springfox.documentation.swagger2.annotations.EnableSwagger2; @SpringBootApplication(scanBasePackages = {"com.tencent.supersonic", "dev.langchain4j"}, exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class}) @EnableScheduling @EnableAsync -@EnableSwagger2 public class StandaloneLauncher { public static void main(String[] args) { diff --git a/launchers/standalone/src/main/java/com/tencent/supersonic/config/SwaggerConfiguration.java b/launchers/standalone/src/main/java/com/tencent/supersonic/config/SwaggerConfiguration.java deleted file mode 100644 index dfe751959..000000000 --- a/launchers/standalone/src/main/java/com/tencent/supersonic/config/SwaggerConfiguration.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.tencent.supersonic.config; - -import com.tencent.supersonic.auth.api.authentication.config.AuthenticationConfig; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.util.Collections; -import java.util.List; - -import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.oas.annotations.EnableOpenApi; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.service.ApiKey; -import springfox.documentation.service.Contact; -import springfox.documentation.service.SecurityReference; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spi.service.contexts.SecurityContext; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; - -@Configuration -@EnableSwagger2 -@EnableOpenApi -public class SwaggerConfiguration { - - /** - * 标题 - */ - @Value("${swagger.title}") - private String title; - - /** - * 基本包 - */ - @Value("${swagger.base.package}") - private String basePackage; - - /** - * 描述 - */ - @Value("${swagger.description}") - private String description; - - /** - * URL - */ - @Value("${swagger.url}") - private String url; - - /** - * 作者 - */ - @Value("${swagger.contact.name}") - private String contactName; - - /** - * 作者网址 - */ - @Value("${swagger.contact.url}") - private String contactUrl; - - /** - * 作者邮箱 - */ - @Value("${swagger.contact.email}") - private String contactEmail; - - /** - * 版本 - */ - @Value("${swagger.version}") - private String version; - - @Autowired - private AuthenticationConfig authenticationConfig; - - private ApiKey apiKey() { - return new ApiKey(authenticationConfig.getTokenHttpHeaderKey(), - authenticationConfig.getTokenHttpHeaderKey(), "header"); - } - - @Bean - public Docket createRestApi() { - return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo()).select() - .apis(RequestHandlerSelectors.basePackage(basePackage)).paths(PathSelectors.any()) - .build().securitySchemes(Collections.singletonList(apiKey())) - .securityContexts(Collections.singletonList(securityContext())); - } - - private SecurityContext securityContext() { - return SecurityContext.builder().securityReferences(defaultAuth()).build(); - } - - private List defaultAuth() { - SecurityReference securityReference = - new SecurityReference(authenticationConfig.getTokenHttpHeaderKey(), - new springfox.documentation.service.AuthorizationScope[0]); - return Collections.singletonList(securityReference); - } - - private ApiInfo apiInfo() { - return new ApiInfoBuilder().title(title).description(description).termsOfServiceUrl(url) - .contact(new Contact(contactName, contactUrl, contactEmail)).version(version) - .build(); - } -} diff --git a/launchers/standalone/src/main/resources/application.yaml b/launchers/standalone/src/main/resources/application.yaml index c94811431..0c86c10f8 100644 --- a/launchers/standalone/src/main/resources/application.yaml +++ b/launchers/standalone/src/main/resources/application.yaml @@ -27,14 +27,12 @@ logging: dev.langchain4j: DEBUG dev.ai4j.openai4j: DEBUG -swagger: - title: 'SuperSonic API Documentation' - base: - package: com.tencent.supersonic - description: 'SuperSonic API Documentation' - url: '' - contact: - name: - email: - url: '' - version: 3.0 \ No newline at end of file +springdoc: + swagger-ui: + path: /swagger-ui.html + enabled: true + api-docs: + path: /v3/api-docs + enabled: true + packages-to-scan: com.tencent.supersonic + paths-to-match: /api/chat/**,/api/semantic/** \ No newline at end of file diff --git a/pom.xml b/pom.xml index 57ffc7955..0f707286b 100644 --- a/pom.xml +++ b/pom.xml @@ -78,6 +78,7 @@ 2.27.1 false 4.2.1 + 3.0.0 @@ -207,6 +208,11 @@ mockito-inline ${mockito-inline.version} + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.1.0 +