use of io.swagger.parser.SwaggerParser in project service-proxy by membrane.
the class SwaggerProxy method init.
@Override
public void init() throws Exception {
super.init();
// download swaggerUrl
HttpClient hc = new HttpClient(router.getHttpClientConfig());
Exchange ex = hc.call(new Request.Builder().get(swaggerUrl).buildExchange());
if (ex.getResponse().getStatusCode() != 200) {
log.error("Couldn't fetch Swagger URL!");
throw new Exception("Couldn't fetch Swagger URL!");
}
// parse swaggerUrl
swagger = new SwaggerParser().parse(ex.getResponse().getBodyAsStringDecoded());
// pass swagger specification to Swagger Key
((SwaggerProxyKey) key).setSwagger(swagger);
((SwaggerProxyKey) key).setAllowUI(allowUI);
// add interceptor to position 0.
SwaggerRewriterInterceptor sri = new SwaggerRewriterInterceptor(swagger, swaggerUrl);
interceptors.add(0, sri);
}
use of io.swagger.parser.SwaggerParser in project teiid by teiid.
the class SwaggerMetadataProcessor method getSchema.
protected Swagger getSchema(WSConnection conn) throws TranslatorException {
Swagger swagger = null;
try {
String swaggerFile = getSwaggerFilePath();
if (swaggerFile != null && !swaggerFile.isEmpty()) {
File f = new File(swaggerFile);
if (!f.exists() || !f.isFile()) {
throw new TranslatorException(SwaggerPlugin.Event.TEIID28019, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28019, swaggerFile));
}
SwaggerParser parser = new SwaggerParser();
swagger = parser.read(f.getAbsolutePath(), null, true);
} else {
BaseQueryExecution execution = new BaseQueryExecution(this.ef, null, null, conn);
Map<String, List<String>> headers = new HashMap<String, List<String>>();
// $NON-NLS-1$ //$NON-NLS-2$
BinaryWSProcedureExecution call = execution.buildInvokeHTTP("GET", "swagger.json", null, headers);
call.execute();
if (call.getResponseCode() != 200) {
throw new TranslatorException(SwaggerPlugin.Event.TEIID28015, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28015, call.getResponseCode()));
}
Blob out = (Blob) call.getOutputParameterValues().get(0);
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = objectMapper.readTree(out.getBinaryStream());
swagger = new SwaggerParser().read(rootNode, true);
}
} catch (Exception e) {
throw new TranslatorException(SwaggerPlugin.Event.TEIID28016, e, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28016, e));
}
return swagger;
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class LegacyConverterTest method testIssue43.
@Test
public void testIssue43() throws Exception {
new Expectations() {
{
remoteUrl.urlToString("http://gateway.marvel.com/docs", new ArrayList<AuthorizationValue>());
result = marvel_json;
remoteUrl.urlToString("http://gateway.marvel.com/docs/public", new ArrayList<AuthorizationValue>());
result = public_json;
}
};
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo("http://gateway.marvel.com/docs", null, true);
Assert.assertNotNull(result.getSwagger());
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class LegacyConverterTest method testIssueFun.
@Test
public void testIssueFun() throws Exception {
new Expectations() {
{
remoteUrl.urlToString("http://localhost:8080/api-docs", new ArrayList<AuthorizationValue>());
result = resources_json;
remoteUrl.urlToString("http://localhost:8080/api-docs/pet", new ArrayList<AuthorizationValue>());
result = pet_json;
remoteUrl.urlToString("http://localhost:8080/api-docs/store", new ArrayList<AuthorizationValue>());
result = store_json;
remoteUrl.urlToString("http://localhost:8080/api-docs/user", new ArrayList<AuthorizationValue>());
result = user_json;
remoteUrl.urlToString("http://localhost:8080/api-docs", null);
result = resources_json;
remoteUrl.urlToString("http://localhost:8080/api-docs/pet", null);
result = pet_json;
remoteUrl.urlToString("http://localhost:8080/api-docs/store", null);
result = store_json;
remoteUrl.urlToString("http://localhost:8080/api-docs/user", null);
result = user_json;
}
};
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo("http://localhost:8080/api-docs", null, true);
Swagger swagger = parser.read("http://localhost:8080/api-docs");
Assert.assertNotNull(swagger);
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class ParserExtensionsTest method readAllExtensions.
@Test
public void readAllExtensions() throws Exception {
SwaggerParser parser = new SwaggerParser();
List<SwaggerParserExtension> extensions = parser.getExtensions();
assertTrue(extensions.size() == 2, "Didn't find 2 extensions as expected");
}
Aggregations