use of com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_X_INTERACTION in project snow-owl by b2ihealthcare.
the class FhirMetadataController method collectResources.
private Collection<Resource> collectResources(final OpenAPI openAPI) {
final Paths paths = openAPI.getPaths();
final List<io.swagger.v3.oas.models.tags.Tag> tags = openAPI.getTags();
return tags.stream().filter(t -> t.getExtensions() != null && t.getExtensions().containsKey(B2I_OPENAPI_X_NAME)).map(t -> {
final Map<?, ?> nameExtensionMap = (Map<?, ?>) t.getExtensions().get(B2I_OPENAPI_X_NAME);
final String profile = (String) nameExtensionMap.get(B2I_OPENAPI_PROFILE);
final Resource.Builder resourceBuilder = Resource.builder().type(t.getName()).profile(profile);
// Collect the operations that belong to the same tagged class resource
paths.values().stream().flatMap(pi -> pi.readOperations().stream()).filter(o -> o.getTags().contains(t.getName()) && o.getExtensions() != null && o.getExtensions().containsKey(B2I_OPENAPI_X_INTERACTION)).forEachOrdered(op -> {
final Map<String, Object> operationExtensionMap = op.getExtensions();
final Map<?, ?> interactionMap = (Map<?, ?>) operationExtensionMap.get(B2I_OPENAPI_X_INTERACTION);
interactionMap.entrySet().forEach(e -> {
final Interaction.Builder interactionBuilder = Interaction.builder().code((String) e.getKey());
final String value = (String) e.getValue();
if (!StringUtils.isEmpty(value)) {
interactionBuilder.documentation((String) value);
}
resourceBuilder.addInteraction(interactionBuilder.build());
});
});
return resourceBuilder.build();
}).sorted(Comparator.comparing(r -> r.getType().getCodeValue())).collect(Collectors.toList());
}
Aggregations