use of io.swagger.parser.SwaggerParser in project carbon-apimgt by wso2.
the class OAS2ParserTest method testUpdateAPIDefinition.
@Test
public void testUpdateAPIDefinition() throws Exception {
String relativePath = "definitions" + File.separator + "oas2" + File.separator + "oas2Resources.json";
String oas2Resources = IOUtils.toString(getClass().getClassLoader().getResourceAsStream(relativePath), "UTF-8");
OASParserEvaluator evaluator = (definition -> {
SwaggerParser swaggerParser = new SwaggerParser();
Swagger swagger = swaggerParser.parse(definition);
Assert.assertNotNull(swagger);
Assert.assertEquals(1, swagger.getPaths().size());
Assert.assertFalse(swagger.getPaths().containsKey("/noresource/{resid}"));
});
testGenerateAPIDefinition2(oas2Parser, oas2Resources, evaluator);
}
use of io.swagger.parser.SwaggerParser in project carbon-apimgt by wso2.
the class SOAPOperationBindingTestCase method testGetSwaggerFromWSDLWithExternalXSDs.
@Test
public void testGetSwaggerFromWSDLWithExternalXSDs() throws Exception {
String externalXSDElementName = "InvokeClaimGeniousDataIntoCordysElement";
String externalXSDElementInputOperation = "invokeClaimGeniousDataIntoCordysBindingOperationInput";
String externalXSDElementOutputOperation = "invokeClaimGeniousDataIntoCordysBindingOperationOutput";
String externalXSDElementPropertyName = "LocalizableMessage";
String swaggerStr = SOAPOperationBindingUtils.getSoapOperationMappingForUrl(Thread.currentThread().getContextClassLoader().getResource("wsdls/wsdl-with-external-xsds/sampleWSDLWithExternalXSDFiles.wsdl").toExternalForm());
Swagger swagger = new SwaggerParser().parse(swaggerStr);
Assert.assertTrue("Unable to parse the swagger from the given string", swagger != null);
Assert.assertNotNull(swagger.getPaths());
// Assert WSDL elements
Assert.assertEquals(1, swagger.getPaths().size());
Assert.assertEquals(5, swagger.getDefinitions().size());
Assert.assertNotNull(swagger.getDefinitions().get(externalXSDElementOutputOperation));
Assert.assertNotNull(swagger.getDefinitions().get(externalXSDElementInputOperation));
Assert.assertNotNull(swagger.getDefinitions().get(externalXSDElementName));
// Assert WSDL external XSD element
Assert.assertTrue(swagger.getDefinitions().get(externalXSDElementName).getProperties().size() == 1);
Assert.assertNotNull(swagger.getDefinitions().get(externalXSDElementName).getProperties().get(externalXSDElementPropertyName));
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerConverter method readContents.
@Override
public SwaggerParseResult readContents(String swaggerAsString, List<AuthorizationValue> auth, ParseOptions options) {
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(swaggerAsString, options == null ? true : options.isResolve());
if (options != null) {
if (options.isResolve()) {
Swagger resolved = new SwaggerResolver(result.getSwagger(), convert(auth)).resolve();
result.setSwagger(resolved);
}
}
return readResult(result, auth, options);
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerConverter method readLocation.
@Override
public SwaggerParseResult readLocation(String url, List<AuthorizationValue> auths, ParseOptions options) {
boolean resolve = false;
if (options != null) {
resolve = options.isResolve();
}
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(url, convert(auths), resolve);
return readResult(result, auths, options);
}
use of io.swagger.parser.SwaggerParser in project gravitee-management-rest-api by gravitee-io.
the class SwaggerServiceImpl method prepare.
public NewApiEntity prepare(ImportSwaggerDescriptorEntity swaggerDescriptor) {
Swagger swagger = null;
switch(swaggerDescriptor.getVersion()) {
case VERSION_1_0:
try {
logger.info("Loading an old Swagger descriptor from {}", swaggerDescriptor.getPayload());
// For spec < 2.0, only read by url is possible
swagger = new SwaggerCompatConverter().read(swaggerDescriptor.getPayload());
} catch (IOException ioe) {
logger.error("Can not read old Swagger specification", ioe);
throw new SwaggerDescriptorException();
}
case VERSION_2_0:
if (swaggerDescriptor.getType() == ImportSwaggerDescriptorEntity.Type.INLINE) {
logger.info("Loading an inline Swagger descriptor");
swagger = new SwaggerParser().parse(swaggerDescriptor.getPayload());
} else if (swaggerDescriptor.getType() == ImportSwaggerDescriptorEntity.Type.URL) {
logger.info("Loading a Swagger descriptor from URL: ", swaggerDescriptor.getPayload());
swagger = new SwaggerParser().read(swaggerDescriptor.getPayload());
}
}
if (swagger == null) {
throw new SwaggerDescriptorException();
}
NewApiEntity apiEntity = new NewApiEntity();
apiEntity.setName(swagger.getInfo().getTitle());
apiEntity.setDescription(swagger.getInfo().getDescription());
apiEntity.setVersion(swagger.getInfo().getVersion());
String scheme = (swagger.getSchemes() == null || swagger.getSchemes().isEmpty()) ? defaultScheme : swagger.getSchemes().iterator().next().toValue();
apiEntity.setEndpoint(scheme + "://" + swagger.getHost() + swagger.getBasePath());
apiEntity.setPaths(new ArrayList<>(swagger.getPaths().keySet().stream().map(path -> path.replaceAll("\\{(.[^/]*)\\}", ":$1")).collect(Collectors.toList())));
return apiEntity;
}
Aggregations