3737import org .apache .servicecomb .swagger .generator .SwaggerGenerator ;
3838import org .slf4j .Logger ;
3939import org .slf4j .LoggerFactory ;
40+ import org .springframework .util .CollectionUtils ;
4041
4142import com .google .common .annotations .VisibleForTesting ;
4243import com .google .common .base .Charsets ;
@@ -181,7 +182,7 @@ private Swagger loadFromResource(String path) {
181182
182183 private Swagger loadFromRemote (Microservice microservice , Collection <MicroserviceInstance > instances ,
183184 String schemaId ) {
184- String key = microservice .getServiceName () + "." + schemaId ;
185+ String key = microservice .getServiceId () + "." + schemaId ;
185186 Swagger result = remoteSwagger .computeIfAbsent (key , k -> {
186187 String schemaContent = DiscoveryManager .INSTANCE .getSchema (microservice .getServiceId (), instances , schemaId );
187188 if (schemaContent != null ) {
@@ -197,7 +198,8 @@ private Swagger loadFromRemote(Microservice microservice, Collection<Microservic
197198 }
198199 return null ;
199200 });
200-
201+ LOGGER .info (
202+ "load [{}] schema from service center, map size [{}]" , microservice .getServiceId (), remoteSwagger .size ());
201203 if (result != null ) {
202204 return result ;
203205 }
@@ -212,4 +214,15 @@ private Swagger loadFromRemote(Microservice microservice, Collection<Microservic
212214
213215 return null ;
214216 }
217+
218+ public void removeRemoteSwagger (List <MicroserviceInstance > instances ) {
219+ if (CollectionUtils .isEmpty (instances )) {
220+ return ;
221+ }
222+ String serviceId = instances .get (0 ).getServiceId ();
223+ int originSize = remoteSwagger .size ();
224+ remoteSwagger .remove (serviceId );
225+ LOGGER .info (
226+ "remove [{}] swagger, origin size [{}], current size [{}]" , serviceId , originSize , remoteSwagger .size ());
227+ }
215228}
0 commit comments