3333import es .bsc .inb .ga4gh .beacon .framework .model .v200 .responses .AbstractBeaconResponse ;
3434import es .bsc .inb .ga4gh .beacon .framework .model .v200 .responses .BeaconCollections ;
3535import es .bsc .inb .ga4gh .beacon .framework .model .v200 .responses .BeaconCollectionsResponse ;
36+ import es .bsc .inb .ga4gh .beacon .framework .model .v200 .responses .BeaconInformationalResponse ;
3637import es .bsc .inb .ga4gh .beacon .framework .model .v200 .responses .BeaconInformationalResponseMeta ;
38+ import es .bsc .inb .ga4gh .beacon .framework .model .v200 .responses .BeaconResponseMeta ;
3739import es .bsc .inb .ga4gh .beacon .framework .model .v200 .responses .BeaconResultset ;
3840import es .bsc .inb .ga4gh .beacon .framework .model .v200 .responses .BeaconResultsets ;
3941import es .bsc .inb .ga4gh .beacon .framework .model .v200 .responses .BeaconResultsetsResponse ;
@@ -211,18 +213,34 @@ private String resolveTemplateParameters(String template, JsonObject entry) {
211213 return single_entry_endpoint .toString ();
212214 }
213215
214- private String getSchemaURL (String entityType ) {
215- if (model .info != null ) {
216- final BeaconInformationalResponseMeta meta = model .info .getMeta ();
217- final List <SchemaPerEntity > returnedSchemas = meta .getReturnedSchemas ();
218- if (returnedSchemas != null ) {
219- for (SchemaPerEntity returnedSchema : returnedSchemas ) {
220- if (entityType .equals (returnedSchema .getEntityType ())) {
221- return returnedSchema .getSchema ();
222- }
216+ private String getSchemaURL (AbstractBeaconResponse response , String entityType ) {
217+ final BeaconResponseMeta meta = response .getMeta ();
218+ if (meta != null ) {
219+ final String schemaURL = getSchemaURL (meta .getReturnedSchemas (), entityType );
220+ if (schemaURL != null ) {
221+ return schemaURL ;
222+ }
223+ }
224+
225+ return getSchemaURL (model .info , entityType );
226+ }
227+
228+ private String getSchemaURL (List <SchemaPerEntity > schemas , String entityType ) {
229+ if (schemas != null ) {
230+ for (SchemaPerEntity schema : schemas ) {
231+ if (entityType .equals (schema .getEntityType ())) {
232+ return schema .getSchema ();
223233 }
224234 }
225235 }
236+ return null ;
237+ }
238+
239+ private String getSchemaURL (BeaconInformationalResponse response , String entityType ) {
240+ final BeaconInformationalResponseMeta meta = response .getMeta ();
241+ if (meta != null ) {
242+ return getSchemaURL (meta .getReturnedSchemas (), entityType );
243+ }
226244
227245 if (model .configuration != null ) {
228246 final BeaconConfiguration configuration = model .configuration .getResponse ();
@@ -239,7 +257,7 @@ private String getSchemaURL(String entityType) {
239257
240258 return null ;
241259 }
242-
260+
243261 private AbstractBeaconResponse validateEntryEndpoint (String endpoint ,
244262 ValidationObserver reporter ) {
245263
@@ -285,10 +303,14 @@ private AbstractBeaconResponse validateEntryEndpoint(String endpoint,
285303 private JsonObject validateResponse (AbstractBeaconResponse response ,
286304 String entryType , ValidationObserver reporter ) {
287305
288- JsonObject entry = null ;
289-
290- final String entryTypeSchema = (entryType == null ) ? null : getSchemaURL (entryType );
291- final JsonSchema schema = model .loadSchema (entryTypeSchema , entryType , reporter );
306+ final JsonSchema schema ;
307+ if (entryType == null ) {
308+ schema = null ;
309+ } else {
310+ final String entryTypeSchema = getSchemaURL (response , entryType );
311+ schema = entryTypeSchema == null ? null :
312+ model .loadSchema (entryTypeSchema , entryType , reporter );
313+ }
292314
293315 final List <JsonObject > entries = new ArrayList ();
294316 if (response instanceof BeaconCollectionsResponse res ) {
@@ -308,6 +330,7 @@ private JsonObject validateResponse(AbstractBeaconResponse response,
308330 }
309331 }
310332
333+ JsonObject entry = null ;
311334 if (schema != null ) {
312335 final List <ValidationError > errors = new ArrayList ();
313336 for (JsonObject obj : entries ) {
0 commit comments