use of io.swagger.v3.oas.annotations.extensions.Extension in project carbon-apimgt by wso2.
the class OAS3Parser method updateOperations.
/**
* Update OAS operations for Store
*
* @param openAPI OpenAPI to be updated
*/
private void updateOperations(OpenAPI openAPI) {
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();
Map<String, Object> extensions = operation.getExtensions();
if (extensions != null) {
// remove mediation extension
if (extensions.containsKey(APIConstants.SWAGGER_X_MEDIATION_SCRIPT)) {
extensions.remove(APIConstants.SWAGGER_X_MEDIATION_SCRIPT);
}
// set x-scope value to security definition if it not there.
if (extensions.containsKey(APIConstants.SWAGGER_X_WSO2_SCOPES)) {
String scope = (String) extensions.get(APIConstants.SWAGGER_X_WSO2_SCOPES);
List<SecurityRequirement> security = operation.getSecurity();
if (security == null) {
security = new ArrayList<>();
operation.setSecurity(security);
}
for (Map<String, List<String>> requirement : security) {
if (requirement.get(OPENAPI_SECURITY_SCHEMA_KEY) == null || !requirement.get(OPENAPI_SECURITY_SCHEMA_KEY).contains(scope)) {
requirement.put(OPENAPI_SECURITY_SCHEMA_KEY, Collections.singletonList(scope));
}
}
}
}
}
}
}
use of io.swagger.v3.oas.annotations.extensions.Extension in project swagger-parser by swagger-api.
the class OpenAPIV3Parser method read.
public OpenAPI read(String location, List<AuthorizationValue> auths, ParseOptions resolve) {
if (location == null) {
return null;
}
final List<SwaggerParserExtension> parserExtensions = getExtensions();
SwaggerParseResult parsed;
for (SwaggerParserExtension extension : parserExtensions) {
parsed = extension.readLocation(location, auths, resolve);
for (String message : parsed.getMessages()) {
LOGGER.info("{}: {}", extension, message);
}
final OpenAPI result = parsed.getOpenAPI();
if (result != null) {
return result;
}
}
return null;
}
use of io.swagger.v3.oas.annotations.extensions.Extension in project swagger-parser by swagger-api.
the class OpenAPIV3Parser method getExtensions.
protected static List<SwaggerParserExtension> getExtensions(ClassLoader cl) {
final List<SwaggerParserExtension> extensions = new ArrayList<>();
final ServiceLoader<SwaggerParserExtension> loader = ServiceLoader.load(SwaggerParserExtension.class, cl);
for (SwaggerParserExtension extension : loader) {
extensions.add(extension);
}
return extensions;
}
use of io.swagger.v3.oas.annotations.extensions.Extension in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readServerObject.
@Test(dataProvider = "data")
public void readServerObject(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 List<Server> server = openAPI.getServers();
Assert.assertNotNull(server);
Assert.assertNotNull(server.get(0));
Assert.assertNotNull(server.get(0).getUrl());
Assert.assertEquals(server.get(0).getUrl(), "http://petstore.swagger.io/v2");
Assert.assertNotNull(server.get(1));
Assert.assertNotNull(server.get(1).getUrl());
Assert.assertNotNull(server.get(1).getDescription());
Assert.assertEquals(server.get(1).getUrl(), "https://development.gigantic-server.com/v1");
Assert.assertEquals(server.get(1).getDescription(), "Development server");
Assert.assertNotNull(server.get(2));
Assert.assertNotNull(server.get(2).getVariables());
Assert.assertNotNull(server.get(2).getVariables().values());
Assert.assertNotNull(server.get(2).getVariables().get("username"));
Assert.assertEquals(server.get(2).getVariables().get("username").getDefault(), "demo");
Assert.assertEquals(server.get(2).getVariables().get("username").getDescription(), "this value is assigned by the service provider, in this example `gigantic-server.com`");
Assert.assertNotNull(server.get(2).getVariables().get("port").getEnum());
Assert.assertEquals(server.get(2).getVariables().get("port").getEnum().get(0), "8443");
Assert.assertEquals(server.get(2).getVariables().get("port").getEnum().get(1), "443");
Assert.assertEquals(server.get(2).getVariables().get("port").getDefault(), "8443");
Assert.assertNotNull(server.get(2).getVariables().get("port"));
Assert.assertNotNull(server.get(2).getVariables().get("basePath"));
Assert.assertNotNull(server.get(2).getExtensions().get("x-server"));
Assert.assertEquals(server.get(2).getExtensions().get("x-server").toString(), "server extension");
Assert.assertEquals(server.get(2).getVariables().get("basePath").getDescription(), "testing overwriting");
Assert.assertEquals(server.get(2).getVariables().get("basePath").getDefault(), "v2");
}
use of io.swagger.v3.oas.annotations.extensions.Extension in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testToplevelExtension.
@Test(description = "it should read a top-level extension per https://github.com/openAPI-api/validator-badge/issues/59")
public void testToplevelExtension() throws Exception {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "x-foo: woof\n" + "info:\n" + " version: 0.0.0\n" + " title: Simple API\n" + "paths:\n" + " /:\n" + " get:\n" + " responses:\n" + " '200':\n" + " description: OK";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
assertNotNull(result.getOpenAPI().getExtensions());
}
Aggregations