Search in sources :

Example 46 with SwaggerParser

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);
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) SwaggerParser(io.swagger.parser.SwaggerParser) HttpClient(com.predic8.membrane.core.transport.http.HttpClient) Request(com.predic8.membrane.core.http.Request) SwaggerRewriterInterceptor(com.predic8.membrane.core.interceptor.swagger.SwaggerRewriterInterceptor)

Example 47 with SwaggerParser

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;
}
Also used : Blob(java.sql.Blob) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) MetadataException(org.teiid.metadata.MetadataException) TranslatorException(org.teiid.translator.TranslatorException) SwaggerParser(io.swagger.parser.SwaggerParser) Swagger(io.swagger.models.Swagger) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) TranslatorException(org.teiid.translator.TranslatorException) List(java.util.List) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 48 with SwaggerParser

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());
}
Also used : Expectations(mockit.Expectations) SwaggerParser(io.swagger.parser.SwaggerParser) AuthorizationValue(io.swagger.models.auth.AuthorizationValue) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) Test(org.testng.annotations.Test)

Example 49 with SwaggerParser

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);
}
Also used : Expectations(mockit.Expectations) SwaggerParser(io.swagger.parser.SwaggerParser) AuthorizationValue(io.swagger.models.auth.AuthorizationValue) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) Swagger(io.swagger.models.Swagger) Test(org.testng.annotations.Test)

Example 50 with SwaggerParser

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");
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) SwaggerParserExtension(io.swagger.parser.SwaggerParserExtension) Test(org.testng.annotations.Test)

Aggregations

SwaggerParser (io.swagger.parser.SwaggerParser)65 Test (org.testng.annotations.Test)37 Swagger (io.swagger.models.Swagger)25 HashSet (java.util.HashSet)19 HashMap (java.util.HashMap)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 ArrayList (java.util.ArrayList)7 List (java.util.List)7 SecuritySchemeDefinition (io.swagger.models.auth.SecuritySchemeDefinition)6 IOException (java.io.IOException)6 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)6 Path (io.swagger.models.Path)5 OAuth2Definition (io.swagger.models.auth.OAuth2Definition)5 Map (java.util.Map)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 HttpMethod (io.swagger.models.HttpMethod)4 Operation (io.swagger.models.Operation)4 BodyParameter (io.swagger.models.parameters.BodyParameter)4 File (java.io.File)4