@Override
protected Swagger loadSwagger(ConsumerSchemaContext context) {
Swagger swagger = super.loadSwagger(context);
if (swagger != null) {
return swagger;
}
ServiceRegistryClient client = RegistryUtils.getServiceRegistryClient();
String schemaContent = client.getSchema(context.getMicroservice().getServiceId(), context.getSchemaId());
LOGGER.info("load schema from service center, microservice={}:{}:{}, schemaId={}, result={}",
context.getMicroservice().getAppId(),
context.getMicroservice().getServiceName(),
context.getMicroservice().getVersion(),
context.getSchemaId(),
!StringUtils.isEmpty(schemaContent));
if (schemaContent != null) {
return SchemaUtils.parseSwagger(schemaContent);
}
throw new Error(
String.format("no schema in local, and can not get schema from service center, %s:%s",
context.getMicroserviceName(),
context.getSchemaId()));
}
}