@ -24,6 +24,7 @@ import java.util.Map;
import com.tencent.cloud.common.util.JacksonUtils ;
import com.tencent.cloud.polaris.PolarisDiscoveryProperties ;
import com.tencent.cloud.polaris.contract.config.PolarisContractProperties ;
import com.tencent.polaris.api.core.ProviderAPI ;
import com.tencent.polaris.api.plugin.server.InterfaceDescriptor ;
import com.tencent.polaris.api.plugin.server.ReportServiceContractRequest ;
@ -55,7 +56,7 @@ public class PolarisContractReporter implements ApplicationListener<ApplicationR
private final org . springdoc . webmvc . api . MultipleOpenApiResource multipleOpenApiWebMvcResource ;
private final org . springdoc . webflux . api . MultipleOpenApiResource multipleOpenApiWebFluxResource ;
private final String groupName ;
private final PolarisContractProperties polarisContractProperties ;
private final ProviderAPI providerAPI ;
@ -63,24 +64,25 @@ public class PolarisContractReporter implements ApplicationListener<ApplicationR
public PolarisContractReporter ( org . springdoc . webmvc . api . MultipleOpenApiResource multipleOpenApiWebMvcResource ,
org . springdoc . webflux . api . MultipleOpenApiResource multipleOpenApiWebFluxResource ,
String groupName , ProviderAPI providerAPI ,
PolarisContractProperties polarisContractProperties , ProviderAPI providerAPI ,
PolarisDiscoveryProperties polarisDiscoveryProperties ) {
this . multipleOpenApiWebMvcResource = multipleOpenApiWebMvcResource ;
this . multipleOpenApiWebFluxResource = multipleOpenApiWebFluxResource ;
this . groupName = groupName ;
this . polarisContractProperties = polarisContractProperties ;
this . providerAPI = providerAPI ;
this . polarisDiscoveryProperties = polarisDiscoveryProperties ;
}
@Override
public void onApplicationEvent ( @NonNull ApplicationReadyEvent applicationReadyEvent ) {
if ( polarisContractProperties . isReportEnabled ( ) ) {
try {
AbstractOpenApiResource openApiResource = null ;
if ( multipleOpenApiWebMvcResource ! = null ) {
openApiResource = OpenApiWebMvcUtil . getOpenApiResourceOrThrow ( multipleOpenApiWebMvcResource , groupName ) ;
openApiResource = OpenApiWebMvcUtil . getOpenApiResourceOrThrow ( multipleOpenApiWebMvcResource , polarisContractProperties. getGroup ( ) ) ;
}
else if ( multipleOpenApiWebFluxResource ! = null ) {
openApiResource = OpenApiWebFluxUtil . getOpenApiResourceOrThrow ( multipleOpenApiWebFluxResource , groupName ) ;
openApiResource = OpenApiWebFluxUtil . getOpenApiResourceOrThrow ( multipleOpenApiWebFluxResource , polarisContractProperties. getGroup ( ) ) ;
}
OpenAPI openAPI = null ;
if ( openApiResource ! = null ) {
@ -105,13 +107,14 @@ public class PolarisContractReporter implements ApplicationListener<ApplicationR
}
}
else {
LOG . warn ( "OpenAPI or json is null, group:{}" , groupName ) ;
LOG . warn ( "OpenAPI or json is null, group:{}" , polarisContractProperties. getGroup ( ) ) ;
}
}
catch ( Throwable t ) {
LOG . error ( "Report contract failed." , t ) ;
}
}
}
private List < InterfaceDescriptor > getInterfaceDescriptorFromSwagger ( OpenAPI openAPI ) {
List < InterfaceDescriptor > interfaceDescriptorList = new ArrayList < > ( ) ;