use of io.swagger.v3.oas.models.Paths in project carbon-apimgt by wso2.
the class OAS3Parser method injectMgwThrottlingExtensionsToDefault.
/**
* This method returns openAPI definition which replaced X-WSO2-throttling-tier extension comes from
* mgw with X-throttling-tier extensions in openAPI file(openAPI version 3)
*
* @param swaggerContent String
* @return String
* @throws APIManagementException
*/
@Override
public String injectMgwThrottlingExtensionsToDefault(String swaggerContent) throws APIManagementException {
OpenAPI openAPI = getOpenAPI(swaggerContent);
Paths paths = openAPI.getPaths();
for (String pathKey : paths.keySet()) {
Map<PathItem.HttpMethod, Operation> operationsMap = paths.get(pathKey).readOperationsMap();
for (Map.Entry<PathItem.HttpMethod, Operation> entry : operationsMap.entrySet()) {
Operation operation = entry.getValue();
Map<String, Object> extensions = operation.getExtensions();
if (extensions != null && extensions.containsKey(APIConstants.X_WSO2_THROTTLING_TIER)) {
Object tier = extensions.get(APIConstants.X_WSO2_THROTTLING_TIER);
extensions.remove(APIConstants.X_WSO2_THROTTLING_TIER);
extensions.put(APIConstants.SWAGGER_X_THROTTLING_TIER, tier);
}
}
}
return Json.pretty(openAPI);
}
use of io.swagger.v3.oas.models.Paths in project flow by vaadin.
the class AbstractEndpointGenerationTest method assertClassPathsRecursive.
private int assertClassPathsRecursive(Paths actualPaths, Class<?> testEndpointClass, Class<?> testMethodsClass, HashMap<String, Class<?>> typeArguments) {
if (!testMethodsClass.equals(testEndpointClass) && !testMethodsClass.isAnnotationPresent(EndpointExposed.class)) {
return 0;
}
int pathCount = 0;
for (Method expectedEndpointMethod : testMethodsClass.getDeclaredMethods()) {
if (!Modifier.isPublic(expectedEndpointMethod.getModifiers()) || accessChecker.getAccessAnnotationChecker().getSecurityTarget(expectedEndpointMethod).isAnnotationPresent(DenyAll.class)) {
continue;
}
pathCount++;
String expectedEndpointUrl = String.format("/%s/%s", getEndpointName(testEndpointClass), expectedEndpointMethod.getName());
PathItem actualPath = actualPaths.get(expectedEndpointUrl);
assertNotNull(String.format("Expected to find a path '%s' for the endpoint method '%s' in the class '%s'", expectedEndpointUrl, expectedEndpointMethod, testEndpointClass), actualPath);
assertPath(testEndpointClass, expectedEndpointMethod, actualPath, typeArguments);
}
Type genericSuperClass = testMethodsClass.getGenericSuperclass();
pathCount += assertClassPathsRecursive(actualPaths, testEndpointClass, applyTypeArguments(genericSuperClass, typeArguments), extractTypeArguments(genericSuperClass, typeArguments));
for (Type genericInterface : testMethodsClass.getGenericInterfaces()) {
pathCount += assertClassPathsRecursive(actualPaths, testEndpointClass, applyTypeArguments(genericInterface, typeArguments), extractTypeArguments(genericInterface, typeArguments));
}
return pathCount;
}
use of io.swagger.v3.oas.models.Paths 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());
}
use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class SwaggerConverter method convert.
public SwaggerParseResult convert(SwaggerDeserializationResult parse) {
if (parse == null) {
return null;
}
SwaggerParseResult output = new SwaggerParseResult().messages(parse.getMessages());
if (parse.getSwagger() == null) {
return output;
}
OpenAPI openAPI = new OpenAPI();
SwaggerInventory inventory = new SwaggerInventory().process(parse.getSwagger());
Swagger swagger = parse.getSwagger();
if (swagger.getVendorExtensions() != null) {
openAPI.setExtensions(convert(swagger.getVendorExtensions()));
}
// Set extension to retain original version of OAS document.
openAPI.addExtension("x-original-swagger-version", swagger.getSwagger());
if (swagger.getExternalDocs() != null) {
openAPI.setExternalDocs(convert(swagger.getExternalDocs()));
}
if (swagger.getInfo() != null) {
openAPI.setInfo(convert(swagger.getInfo()));
}
openAPI.setServers(convert(swagger.getSchemes(), swagger.getHost(), swagger.getBasePath()));
if (swagger.getTags() != null) {
openAPI.setTags(convertTags(swagger.getTags()));
}
if (swagger.getConsumes() != null) {
this.globalConsumes.addAll(swagger.getConsumes());
}
if (swagger.getProduces() != null) {
this.globalProduces.addAll(swagger.getProduces());
}
if (swagger.getSecurity() != null && swagger.getSecurity().size() > 0) {
openAPI.setSecurity(convertSecurityRequirements(swagger.getSecurity()));
}
List<Model> models = inventory.getModels();
// TODO until we have the example object working correctly in v3 pojos...
for (Model model : models) {
if (model instanceof RefModel) {
RefModel ref = (RefModel) model;
if (ref.get$ref().indexOf("#/definitions") == 0) {
String updatedRef = "#/components/schemas" + ref.get$ref().substring("#/definitions".length());
ref.set$ref(updatedRef);
}
}
}
for (Property property : inventory.getProperties()) {
if (property instanceof RefProperty) {
RefProperty ref = (RefProperty) property;
if (ref.get$ref().indexOf("#/definitions") == 0) {
String updatedRef = "#/components/schemas" + ref.get$ref().substring("#/definitions".length());
ref.set$ref(updatedRef);
}
}
if (property instanceof ComposedProperty) {
ComposedProperty comprop = (ComposedProperty) property;
if (comprop.getAllOf() != null) {
for (Property item : comprop.getAllOf()) {
if (item instanceof RefProperty) {
RefProperty ref = (RefProperty) item;
if (ref.get$ref().indexOf("#/definitions") == 0) {
String updatedRef = "#/components/schemas" + ref.get$ref().substring("#/definitions".length());
ref.set$ref(updatedRef);
}
}
}
}
}
}
if (swagger.getParameters() != null) {
globalV2Parameters.putAll(swagger.getParameters());
swagger.getParameters().forEach((k, v) -> {
if ("body".equals(v.getIn())) {
components.addRequestBodies(k, convertParameterToRequestBody(v));
} else if ("formData".equals(v.getIn())) {
// formData_ is added not to overwrite existing schemas
components.addSchemas("formData_" + k, convertFormDataToSchema(v));
} else {
components.addParameters(k, convert(v));
}
});
}
Paths v3Paths = new Paths();
Map<String, Path> pathMap = Optional.ofNullable(swagger.getPaths()).orElse(new HashMap<>());
for (String pathname : pathMap.keySet()) {
io.swagger.models.Path v2Path = swagger.getPath(pathname);
PathItem v3Path = convert(v2Path);
v3Paths.put(pathname, v3Path);
}
openAPI.setPaths(v3Paths);
if (swagger.getResponses() != null) {
swagger.getResponses().forEach((k, v) -> components.addResponses(k, convert(v)));
}
if (swagger.getDefinitions() != null) {
for (String key : swagger.getDefinitions().keySet()) {
Model model = swagger.getDefinitions().get(key);
Schema schema = convert(model);
components.addSchemas(key, schema);
}
}
if (swagger.getSecurityDefinitions() != null) {
swagger.getSecurityDefinitions().forEach((k, v) -> components.addSecuritySchemes(k, convert(v)));
}
openAPI.setComponents(components);
output.setOpenAPI(openAPI);
return output;
}
use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class V2ConverterTest method testIssue25.
@Test(description = "Covert path item $refs")
public void testIssue25() throws Exception {
OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_25_JSON);
assertNotNull(oas);
assertEquals(oas.getPaths().get("/foo2").get$ref(), "#/paths/~1foo");
}
Aggregations