use of io.swagger.v3.oas.models.links.Link in project snow-owl by b2ihealthcare.
the class FhirMetadataController method operationDefinition.
/**
* Returns the {@link OperationDefinition} for a given operation.
* @param operation
* @return
*/
@Operation(summary = "Retrieve an operation definition by its name", description = "Retrieves an operation definition by its compound name (resource$operation).")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Operation definition not found") })
@GetMapping(value = "/OperationDefinition/{operation}")
public OperationDefinition operationDefinition(@PathVariable(value = "operation") final String operation) {
final Map<String, OperationDefinition> operationMap = capabilityStatementSupplier.get().operationMap;
final OperationDefinition operationDefinition = operationMap.get(operation);
if (operationDefinition == null) {
throw new NotFoundException("OperationDefinition", operation);
}
return operationDefinition;
}
use of io.swagger.v3.oas.models.links.Link in project snow-owl by b2ihealthcare.
the class FhirConceptMapTranslateOperationController method translate.
/**
* HTTP Get request to translate a code that could belongs to any {@link ConceptMap} in the system.
* @return translation of the code
*/
@Operation(summary = "Translate a code", description = "Translate a code from one value set to another, based on the existing value set and concept maps resources, and/or other additional knowledge available to the server.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "Bad request"), @ApiResponse(responseCode = "404", description = "Concept map not found") })
@GetMapping(value = "/$translate")
public Promise<Parameters.Fhir> translate(@Parameter(description = "The code to translate") @RequestParam(value = "code") final String code, @Parameter(description = "The code system's uri") @RequestParam(value = "system") final String system, @Parameter(description = "The code system's version, if null latest is used") @RequestParam(value = "version") final Optional<String> version, @Parameter(description = "The source value set") @RequestParam(value = "source") final Optional<String> source, @Parameter(description = "Value set in which a translation is sought") @RequestParam(value = "target") final Optional<String> target, @Parameter(description = "Target code system") @RequestParam(value = "targetsystem") final Optional<String> targetSystem, @Parameter(description = "If true, the mapping is reversed") @RequestParam(value = "reverse") final Optional<Boolean> isReverse) {
// validation is triggered by builder.build()
Builder builder = TranslateRequest.builder().code(code).system(system);
version.ifPresent(builder::version);
if (source.isPresent()) {
builder.source(source.get());
}
if (target.isPresent()) {
builder.target(target.get());
}
if (targetSystem.isPresent()) {
builder.targetSystem(targetSystem.get());
}
if (isReverse.isPresent()) {
builder.isReverse(isReverse.get());
}
return doTranslate(builder.build());
}
use of io.swagger.v3.oas.models.links.Link in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readComponentsObject.
@Test(dataProvider = "data")
public void readComponentsObject(JsonNode rootNode) throws Exception {
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
Assert.assertEquals(openAPI.getOpenapi(), "3.0.1");
final Components component = openAPI.getComponents();
Assert.assertNotNull(component);
Assert.assertNotNull(component.getCallbacks());
Assert.assertEquals(component.getCallbacks().get("heartbeat").get("$request.query.heartbeat-url").getPost().getResponses().get("200").getDescription(), "Consumer acknowledged the callback");
// System.out.println(component.getCallbacks().get("referenced"));
Assert.assertEquals(component.getCallbacks().get("failed").get("$response.body#/failedUrl").getPost().getResponses().get("200").getDescription(), "Consumer acknowledged the callback failed");
Assert.assertNotNull(component.getExamples());
Assert.assertEquals(component.getExamples().get("cat").getSummary(), "An example of a cat");
Assert.assertNotNull(component.getExamples().get("cat").getValue());
Assert.assertNotNull(component.getHeaders());
Assert.assertEquals(component.getHeaders().get("X-Rate-Limit-Limit").getDescription(), "The number of allowed requests in the current period");
Assert.assertEquals(component.getHeaders().get("X-Rate-Limit-Limit").getSchema().getType(), "integer");
Assert.assertNotNull(component.getLinks());
Assert.assertEquals(component.getLinks().get("unsubscribe").getOperationId(), "cancelHookCallback");
Assert.assertNotNull(component.getLinks().get("unsubscribe").getParameters());
Assert.assertEquals(component.getLinks().get("unsubscribe").getExtensions().get("x-link"), "link extension");
Assert.assertNotNull(component.getParameters());
Assert.assertEquals(component.getParameters().get("skipParam").getName(), "skip");
Assert.assertEquals(component.getParameters().get("skipParam").getIn(), "query");
Assert.assertEquals(component.getParameters().get("skipParam").getDescription(), "number of items to skip");
assertTrue(component.getParameters().get("skipParam").getRequired());
Assert.assertEquals(component.getParameters().get("skipParam").getSchema().getType(), "integer");
Assert.assertNotNull(component.getRequestBodies());
Assert.assertEquals(component.getRequestBodies().get("requestBody1").getDescription(), "request body in components");
Assert.assertEquals(component.getRequestBodies().get("requestBody1").getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/Pet");
Assert.assertEquals(component.getRequestBodies().get("requestBody1").getContent().get("application/xml").getSchema().get$ref(), "#/components/schemas/Pet");
Assert.assertEquals(component.getRequestBodies().get("requestBody2").getContent().get("application/json").getSchema().getType().toString(), "array");
Assert.assertNotNull(component.getRequestBodies().get("requestBody2").getContent().get("application/json").getSchema());
Assert.assertNotNull(component.getResponses());
Assert.assertEquals(component.getResponses().get("NotFound").getDescription(), "Entity not found.");
Assert.assertEquals(component.getResponses().get("IllegalInput").getDescription(), "Illegal input for operation.");
Assert.assertEquals(component.getResponses().get("GeneralError").getDescription(), "General Error");
Assert.assertEquals(component.getResponses().get("GeneralError").getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/ExtendedErrorModel");
Assert.assertNotNull(component.getSchemas());
Assert.assertEquals(component.getSchemas().get("Category").getType(), "object");
Assert.assertEquals(component.getSchemas().get("ApiResponse").getRequired().get(0), "name");
Assert.assertEquals(component.getSchemas().get("Order").getType(), "object");
Assert.assertEquals(component.getSchemas().get("Order").getNot().getType(), "integer");
assertTrue(component.getSchemas().get("Order").getAdditionalProperties() instanceof Schema);
Schema additionalProperties = (Schema) component.getSchemas().get("Order").getAdditionalProperties();
Assert.assertEquals(additionalProperties.getType(), "integer");
Schema schema = (Schema) component.getSchemas().get("Order").getProperties().get("status");
Map<String, Schema> properties = (Map<String, Schema>) component.getSchemas().get("Order").getProperties();
Assert.assertNotNull(properties);
Assert.assertEquals(properties.get("status").getType(), "string");
Assert.assertEquals(properties.get("status").getDescription(), "Order Status");
Assert.assertEquals(properties.get("status").getEnum().get(0), "placed");
Assert.assertNotNull(component.getSecuritySchemes());
Assert.assertEquals(component.getSecuritySchemes().get("petstore_auth").getType().toString(), "oauth2");
Assert.assertEquals(component.getSecuritySchemes().get("petstore_auth").getFlows().getImplicit().getAuthorizationUrl(), "http://petstore.swagger.io/oauth/dialog");
// TODO
Assert.assertNotNull(component.getSecuritySchemes().get("petstore_auth").getFlows().getImplicit().getScopes());
Assert.assertNotNull(component.getExtensions());
assertTrue(component.getExtensions().containsKey("x-component"));
Object object = component.getExtensions().get("x-component");
assertTrue(object instanceof List);
List elements = (List) object;
Assert.assertEquals(elements.size(), 1);
Map<String, Object> map = (Map) elements.get(0);
Assert.assertEquals(map.get("url"), "http://component.swagger.io/v2/swagger.json");
Assert.assertEquals(map.get("format"), "OAS");
Assert.assertEquals(map.get("version"), "3.0");
Map<String, Object> converter = (Map<String, Object>) map.get("converter");
Assert.assertNotNull(converter);
Assert.assertEquals(converter.get("url"), "https://github.com/mermade/oas3");
Assert.assertEquals(converter.get("version"), "1.2.3");
object = component.getExtensions().get("x-api-title");
assertTrue(object instanceof String);
Assert.assertEquals("pet store test api in components", object.toString());
}
use of io.swagger.v3.oas.models.links.Link in project swagger-parser by swagger-api.
the class ExternalRefProcessor method processRefToExternalLink.
public String processRefToExternalLink(String $ref, RefFormat refFormat) {
String renamedRef = cache.getRenamedRef($ref);
if (renamedRef != null) {
return renamedRef;
}
final Link link = cache.loadRef($ref, refFormat, Link.class);
if (link == null) {
// stop! There's a problem. retain the original ref
LOGGER.warn("unable to load model reference from `" + $ref + "`. It may not be available " + "or the reference isn't a valid model schema");
return $ref;
}
String newRef;
if (openAPI.getComponents() == null) {
openAPI.setComponents(new Components());
}
Map<String, Link> links = openAPI.getComponents().getLinks();
if (links == null) {
links = new LinkedHashMap<>();
}
final String possiblyConflictingDefinitionName = computeDefinitionName($ref);
Link existingLink = links.get(possiblyConflictingDefinitionName);
if (existingLink != null) {
LOGGER.debug("A model for " + existingLink + " already exists");
if (existingLink.get$ref() != null) {
// use the new model
existingLink = null;
}
}
newRef = possiblyConflictingDefinitionName;
cache.putRenamedRef($ref, newRef);
if (existingLink == null) {
// don't overwrite existing model reference
openAPI.getComponents().addLinks(newRef, link);
cache.addReferencedKey(newRef);
String file = $ref.split("#/")[0];
if (link.get$ref() != null) {
RefFormat format = computeRefFormat(link.get$ref());
if (isAnExternalRefFormat(format)) {
link.set$ref(processRefToExternalLink(link.get$ref(), format));
} else {
processRefToExternalLink(file + link.get$ref(), RefFormat.RELATIVE);
}
}
}
return newRef;
}
use of io.swagger.v3.oas.models.links.Link in project swagger-parser by swagger-api.
the class ExternalRefProcessorTest method testRelativeRefIncludingUrlRef.
@Test
public void testRelativeRefIncludingUrlRef(@Injectable final Schema mockedModel) throws Exception {
final RefFormat refFormat = RefFormat.RELATIVE;
final String url = "https://my.example.remote.url.com/globals.yaml";
final String expectedResult = "components:\n" + " schemas:\n" + " link-object:\n" + " type: object\n" + " additionalProperties:\n" + " \"$ref\": \"#/components/schemas/rel-data\"\n" + " rel-data:\n" + " type: object\n" + " required:\n" + " - href\n" + " properties:\n" + " href:\n" + " type: string\n" + " note:\n" + " type: string\n" + " result:\n" + " type: object\n" + " properties:\n" + " name:\n" + " type: string\n" + " _links:\n" + " \"$ref\": \"#/components/schemas/link-object\"\n" + "";
List<AuthorizationValue> auths = null;
new Expectations() {
{
RemoteUrl.urlToString(url, auths);
times = 1;
result = expectedResult;
}
};
OpenAPI mockedOpenAPI = new OpenAPI();
mockedOpenAPI.setComponents(new Components());
mockedOpenAPI.getComponents().setSchemas(new HashMap<>());
ResolverCache mockedResolverCache = new ResolverCache(mockedOpenAPI, null, null);
ExternalRefProcessor processor = new ExternalRefProcessor(mockedResolverCache, mockedOpenAPI);
processor.processRefToExternalSchema("./relative-with-url/relative-with-url.yaml#/relative-with-url", refFormat);
assertThat(((Schema) mockedOpenAPI.getComponents().getSchemas().get("relative-with-url").getProperties().get("Foo")).get$ref(), is("https://my.example.remote.url.com/globals.yaml#/components/schemas/link-object"));
assertThat(mockedOpenAPI.getComponents().getSchemas().keySet().contains("link-object"), is(true));
assertThat(mockedOpenAPI.getComponents().getSchemas().keySet().contains("rel-data"), is(true));
// assert that ref is relative ref is resolved. and the file path is from root yaml file.
assertThat(((Schema) mockedOpenAPI.getComponents().getSchemas().get("relative-with-url").getProperties().get("Bar")).get$ref(), is("./relative-with-url/relative-with-local.yaml#/relative-same-file"));
}
Aggregations