mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-13 13:07:32 +00:00
[fix][project]Use SpringDoc to support swagger in Spring 3.x
This commit is contained in:
@@ -71,13 +71,6 @@
|
|||||||
<artifactId>auth-api</artifactId>
|
<artifactId>auth-api</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-boot-starter</artifactId>
|
|
||||||
<version>3.0.0</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
|||||||
@@ -6,13 +6,11 @@ import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfigurat
|
|||||||
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
|
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
||||||
|
|
||||||
@SpringBootApplication(scanBasePackages = {"com.tencent.supersonic", "dev.langchain4j"},
|
@SpringBootApplication(scanBasePackages = {"com.tencent.supersonic", "dev.langchain4j"},
|
||||||
exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
|
exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
@EnableAsync
|
@EnableAsync
|
||||||
@EnableSwagger2
|
|
||||||
public class StandaloneLauncher {
|
public class StandaloneLauncher {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -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<SecurityReference> 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -27,14 +27,12 @@ logging:
|
|||||||
dev.langchain4j: DEBUG
|
dev.langchain4j: DEBUG
|
||||||
dev.ai4j.openai4j: DEBUG
|
dev.ai4j.openai4j: DEBUG
|
||||||
|
|
||||||
swagger:
|
springdoc:
|
||||||
title: 'SuperSonic API Documentation'
|
swagger-ui:
|
||||||
base:
|
path: /swagger-ui.html
|
||||||
package: com.tencent.supersonic
|
enabled: true
|
||||||
description: 'SuperSonic API Documentation'
|
api-docs:
|
||||||
url: ''
|
path: /v3/api-docs
|
||||||
contact:
|
enabled: true
|
||||||
name:
|
packages-to-scan: com.tencent.supersonic
|
||||||
email:
|
paths-to-match: /api/chat/**,/api/semantic/**
|
||||||
url: ''
|
|
||||||
version: 3.0
|
|
||||||
6
pom.xml
6
pom.xml
@@ -78,6 +78,7 @@
|
|||||||
<spotless.version>2.27.1</spotless.version>
|
<spotless.version>2.27.1</spotless.version>
|
||||||
<spotless.skip>false</spotless.skip>
|
<spotless.skip>false</spotless.skip>
|
||||||
<stax2.version>4.2.1</stax2.version>
|
<stax2.version>4.2.1</stax2.version>
|
||||||
|
<io.springfox.version>3.0.0</io.springfox.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@@ -207,6 +208,11 @@
|
|||||||
<artifactId>mockito-inline</artifactId>
|
<artifactId>mockito-inline</artifactId>
|
||||||
<version>${mockito-inline.version}</version>
|
<version>${mockito-inline.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springdoc</groupId>
|
||||||
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
<version>2.1.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user