use of io.swagger.parser.SwaggerParser in project gravitee-management-rest-api by gravitee-io.
the class SwaggerServiceImpl method transformV2.
private Swagger transformV2(String content, PageConfigurationEntity config) {
Swagger swagger = new SwaggerParser().parse(content);
if (swagger != null && config != null && config.getTryItURL() != null) {
URI newURI = URI.create(config.getTryItURL());
swagger.setSchemes(Collections.singletonList(Scheme.forValue(newURI.getScheme())));
swagger.setHost((newURI.getPort() != -1) ? newURI.getHost() + ':' + newURI.getPort() : newURI.getHost());
swagger.setBasePath((newURI.getRawPath().isEmpty()) ? "/" : newURI.getRawPath());
}
return swagger;
}
use of io.swagger.parser.SwaggerParser in project syndesis by syndesisio.
the class BaseSwaggerConnectorGeneratorTest method shouldCreatePropertyParametersFromPetstoreSwagger.
@Test
public void shouldCreatePropertyParametersFromPetstoreSwagger() throws IOException {
final String specification = resource("/swagger/petstore.swagger.json");
final Swagger swagger = new SwaggerParser().parse(specification);
final Parameter petIdPathParameter = swagger.getPath("/pet/{petId}").getGet().getParameters().get(0);
final Optional<ConfigurationProperty> maybeConfigurationProperty = BaseSwaggerConnectorGenerator.createPropertyFromParameter(petIdPathParameter);
final ConfigurationProperty expected = //
new ConfigurationProperty.Builder().componentProperty(//
false).deprecated(//
false).description(//
"ID of pet to return").displayName(//
"petId").group(//
"producer").javaType(//
Long.class.getName()).kind(//
"property").required(//
true).secret(//
false).type(//
"integer").build();
assertThat(maybeConfigurationProperty).hasValue(expected);
}
use of io.swagger.parser.SwaggerParser in project syndesis by syndesisio.
the class SwaggerHelper method parse.
public static SwaggerModelInfo parse(final String specification, final boolean validate) {
final SwaggerModelInfo.Builder resultBuilder = new SwaggerModelInfo.Builder();
final String resolvedSpecification;
try {
resolvedSpecification = resolve(specification);
resultBuilder.resolvedSpecification(resolvedSpecification);
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") final Exception e) {
LOG.debug("Unable to resolve Swagger specification\n{}\n", specification, e);
return resultBuilder.addError(new Violation.Builder().error("error").property("").message("Unable to resolve Swagger specification from: " + ofNullable(specification).map(s -> StringUtils.abbreviate(s, 100)).orElse("")).build()).build();
}
final SwaggerParser parser = new SwaggerParser();
final Swagger swagger = parser.parse(resolvedSpecification);
if (swagger == null) {
LOG.debug("Unable to read Swagger specification\n{}\n", specification);
return resultBuilder.addError(new Violation.Builder().error("error").property("").message("Unable to read Swagger specification from: " + ofNullable(specification).map(s -> StringUtils.abbreviate(s, 100)).orElse("")).build()).build();
}
if (validate) {
final SwaggerModelInfo swaggerModelInfo = validateJSonSchema(resolvedSpecification, swagger);
return SyndesisSwaggerValidationRules.getInstance().apply(swaggerModelInfo);
}
return resultBuilder.model(swagger).build();
}
use of io.swagger.parser.SwaggerParser in project teiid by teiid.
the class TestSwaggerMetadataProcessor method getMetadata.
private static MetadataFactory getMetadata(SwaggerExecutionFactory ef, final String file) throws TranslatorException {
SwaggerMetadataProcessor processor = new SwaggerMetadataProcessor(ef) {
protected Swagger getSchema(WSConnection conn) throws TranslatorException {
File f = new File(file);
ObjectMapper objectMapper = new ObjectMapper();
try (FileInputStream fis = new FileInputStream(f)) {
JsonNode rootNode = objectMapper.readTree(fis);
return new SwaggerParser().read(rootNode, true);
} catch (IOException e) {
throw new TranslatorException(e);
}
}
};
processor.setPreferredProduces("application/json");
processor.setPreferredConsumes("application/json");
processor.setPreferredScheme("http");
Properties props = new Properties();
MetadataFactory mf = new MetadataFactory("vdb", 1, "swagger", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
processor.process(mf, null);
return mf;
}
use of io.swagger.parser.SwaggerParser in project service-proxy by membrane.
the class SwaggerRewriterInterceptor method init.
@Override
public void init() throws Exception {
// inherit wsdl="..." from SoapProxy
if (this.swagger == null || this.swagger.isNull()) {
Rule parent = router.getParentProxy(this);
if (parent instanceof SwaggerProxy) {
setSwagger(((SwaggerProxy) parent).getSwagger());
}
}
// use default if no SwaggerProxy is found
if (this.swagger == null || this.swagger.isNull()) {
String swaggerSource = IOUtils.toString(this.getRouter().getResolverMap().resolve(this.swaggerJson));
this.swagger = new OpenAPIAdapter(new OpenAPIV3Parser().readContents(swaggerSource).getOpenAPI());
if (this.swagger == null || this.swagger.isNull()) {
this.swagger = new SwaggerAdapter(new SwaggerParser().parse(swaggerSource));
if (this.swagger == null || swagger.isNull())
throw new Exception("couldn't parse Swagger definition");
}
this.swaggerUrl = this.swaggerJson;
}
}
Aggregations