use of io.swagger.v3.oas.models.PathItem in project carbon-apimgt by wso2.
the class OAS3Parser method removePublisherSpecificInfo.
/**
* Remove MG related information
*
* @param openAPI OpenAPI
*/
private void removePublisherSpecificInfo(OpenAPI openAPI) {
Map<String, Object> extensions = openAPI.getExtensions();
OASParserUtil.removePublisherSpecificInfo(extensions);
for (String pathKey : openAPI.getPaths().keySet()) {
PathItem pathItem = openAPI.getPaths().get(pathKey);
for (Map.Entry<PathItem.HttpMethod, Operation> entry : pathItem.readOperationsMap().entrySet()) {
Operation operation = entry.getValue();
OASParserUtil.removePublisherSpecificInfofromOperation(operation.getExtensions());
}
}
}
use of io.swagger.v3.oas.models.PathItem in project cxf by apache.
the class OpenApiCustomizer method customize.
public void customize(final OpenAPI oas) {
if (replaceTags || javadocProvider != null) {
Map<String, ClassResourceInfo> operations = new HashMap<>();
Map<Pair<String, String>, OperationResourceInfo> methods = new HashMap<>();
cris.forEach(cri -> {
cri.getMethodDispatcher().getOperationResourceInfos().forEach(ori -> {
String normalizedPath = getNormalizedPath(cri.getURITemplate().getValue(), ori.getURITemplate().getValue());
operations.put(normalizedPath, cri);
methods.put(Pair.of(ori.getHttpMethod(), normalizedPath), ori);
});
});
List<Tag> tags = new ArrayList<>();
oas.getPaths().forEach((pathKey, pathItem) -> {
Optional<Tag> tag;
if (replaceTags && operations.containsKey(pathKey)) {
ClassResourceInfo cri = operations.get(pathKey);
tag = Optional.of(new Tag());
tag.get().setName(cri.getURITemplate().getValue().replaceAll("/", "_"));
if (javadocProvider != null) {
tag.get().setDescription(javadocProvider.getClassDoc(cri));
}
if (!tags.contains(tag.get())) {
tags.add(tag.get());
}
} else {
tag = Optional.empty();
}
pathItem.readOperationsMap().forEach((method, operation) -> {
if (replaceTags && tag.isPresent()) {
operation.setTags(Collections.singletonList(tag.get().getName()));
}
Pair<String, String> key = Pair.of(method.name(), pathKey);
if (methods.containsKey(key) && javadocProvider != null) {
OperationResourceInfo ori = methods.get(key);
if (StringUtils.isBlank(operation.getSummary())) {
operation.setSummary(javadocProvider.getMethodDoc(ori));
}
if (operation.getParameters() == null) {
List<Parameter> parameters = new ArrayList<>();
addParameters(parameters);
operation.setParameters(parameters);
}
for (int i = 0; i < operation.getParameters().size(); i++) {
if (StringUtils.isBlank(operation.getParameters().get(i).getDescription())) {
operation.getParameters().get(i).setDescription(extractJavadoc(operation, ori, i));
}
}
addParameters(operation.getParameters());
customizeResponses(operation, ori);
}
});
});
if (replaceTags && oas.getTags() != null) {
oas.setTags(tags);
}
}
}
use of io.swagger.v3.oas.models.PathItem in project snow-owl by b2ihealthcare.
the class FhirMetadataController method collectOperationDefinitions.
private Collection<OperationDefinition> collectOperationDefinitions(final OpenAPI openAPI) {
final Paths paths = openAPI.getPaths();
// Collect GET requests within the FHIR services hierarchy where the request path contains a '$' character
return paths.entrySet().stream().filter(e -> {
final String key = e.getKey();
final PathItem value = e.getValue();
return key.startsWith(config.getApiBaseUrl()) && key.contains("$") && (value.getGet() != null);
}).map(e -> buildOperationDefinition(e.getKey(), e.getValue())).collect(Collectors.toList());
}
use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readPathsObject.
@Test(dataProvider = "data")
public void readPathsObject(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);
final Paths paths = openAPI.getPaths();
Assert.assertNotNull(paths);
Assert.assertEquals(paths.size(), 19);
PathItem petRef = paths.get("/pathItemRef");
PathItem petEndpoint = paths.get("/pet");
Assert.assertNotNull(petEndpoint);
Assert.assertEquals(petEndpoint.getSummary(), "summary");
Assert.assertEquals(petEndpoint.getDescription(), "description");
Assert.assertNotNull(petEndpoint.getPost().getExternalDocs());
Assert.assertEquals(petEndpoint.getPost().getExternalDocs().getUrl(), "http://swagger.io");
Assert.assertEquals(petEndpoint.getPost().getExternalDocs().getDescription(), "Find out more");
// Operation trace
Assert.assertNotNull(petEndpoint.getTrace());
Assert.assertNotNull(petEndpoint.getDescription());
// Operation post
Assert.assertNotNull(petEndpoint.getPost());
Assert.assertNotNull(petEndpoint.getPost().getTags());
Assert.assertEquals(petEndpoint.getPost().getTags().size(), 1);
Assert.assertEquals(petEndpoint.getPost().getSummary(), "Add a new pet to the store");
Assert.assertEquals(petEndpoint.getPost().getDescription(), "");
Assert.assertEquals(petEndpoint.getPost().getOperationId(), "addPet");
Assert.assertNotNull(petEndpoint.getServers());
Assert.assertEquals(petEndpoint.getServers().size(), 1);
Assert.assertNotNull(petEndpoint.getParameters());
Assert.assertEquals(petEndpoint.getParameters().size(), 2);
Assert.assertNotNull(petEndpoint.getPost().getParameters());
Assert.assertEquals(petEndpoint.getPost().getSecurity().get(0).get("petstore_auth").get(0), "write:pets");
Assert.assertEquals(petEndpoint.getPost().getSecurity().get(0).get("petstore_auth").get(1), "read:pets");
ApiResponses responses = petEndpoint.getPost().getResponses();
Assert.assertNotNull(responses);
assertTrue(responses.containsKey("405"));
ApiResponse response = responses.get("405");
Assert.assertEquals(response.getDescription(), "Invalid input");
Assert.assertEquals(response.getHeaders().get("X-Rate-Limit").getDescription(), "calls per hour allowed by the user");
// parameters operation get
PathItem petByStatusEndpoint = paths.get("/pet/findByStatus");
Assert.assertNotNull(petByStatusEndpoint.getGet());
Assert.assertNotNull(petByStatusEndpoint.getGet().getTags());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().size(), 1);
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getIn(), "query");
Assert.assertEquals(petByStatusEndpoint.getGet().getCallbacks().get("mainHook").get("$request.body#/url").getPost().getResponses().get("200").getDescription(), "webhook successfully processed operation");
}
use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readProducesTestEndpoint.
@Test(dataProvider = "data")
public void readProducesTestEndpoint(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);
final Paths paths = openAPI.getPaths();
Assert.assertNotNull(paths);
Assert.assertEquals(paths.size(), 19);
// parameters operation get
PathItem producesTestEndpoint = paths.get("/producesTest");
Assert.assertNotNull(producesTestEndpoint.getGet());
Assert.assertNotNull(producesTestEndpoint.getGet().getParameters());
Assert.assertTrue(producesTestEndpoint.getGet().getParameters().isEmpty());
Operation operation = producesTestEndpoint.getGet();
ApiResponses responses = operation.getResponses();
Assert.assertNotNull(responses);
Assert.assertFalse(responses.isEmpty());
ApiResponse response = responses.get("200");
Assert.assertNotNull(response);
Assert.assertEquals("it works", response.getDescription());
Content content = response.getContent();
Assert.assertNotNull(content);
MediaType mediaType = content.get("application/json");
Assert.assertNotNull(mediaType);
Schema schema = mediaType.getSchema();
Assert.assertNotNull(schema);
Assert.assertTrue(schema instanceof ObjectSchema);
ObjectSchema objectSchema = (ObjectSchema) schema;
schema = objectSchema.getProperties().get("name");
Assert.assertNotNull(schema);
Assert.assertTrue(schema instanceof StringSchema);
}
Aggregations