Search in sources :

Example 6 with AuthorizationValue

use of io.swagger.models.auth.AuthorizationValue in project swagger-parser by swagger-api.

the class RemoteUrlTest method testHostQueryParam.

@Test
public void testHostQueryParam() throws Exception {
    final String queryParamName = "Authorization";
    final String queryParamValue = "foobar";
    final String expectedBody = "a really good body";
    stubFor(get(urlPathEqualTo("/v2/pet/1")).withQueryParam(queryParamName, equalTo(queryParamValue)).willReturn(aResponse().withBody(expectedBody).withHeader("Content-Type", "application/json")));
    final AuthorizationValue authorizationValue = new HostAuthorizationValue(LOCALHOST, queryParamName, queryParamValue, "query");
    final String actualBody = RemoteUrl.urlToString(getUrl(), Arrays.asList(authorizationValue));
    assertEquals(actualBody, expectedBody);
    verify(getRequestedFor(urlPathEqualTo("/v2/pet/1")).withHeader("Accept", equalTo(EXPECTED_ACCEPTS_HEADER)).withQueryParam(queryParamName, equalTo(queryParamValue)));
}
Also used : AuthorizationValue(io.swagger.models.auth.AuthorizationValue) Test(org.testng.annotations.Test)

Example 7 with AuthorizationValue

use of io.swagger.models.auth.AuthorizationValue in project swagger-parser by swagger-api.

the class RemoteUrlTest method testAuthorizationQueryParam.

@Test
public void testAuthorizationQueryParam() throws Exception {
    final String queryParamName = "Authorization";
    final String queryParamValue = "foobar";
    final String expectedBody = "a really good body";
    stubFor(get(urlPathEqualTo("/v2/pet/1")).withQueryParam(queryParamName, equalTo(queryParamValue)).willReturn(aResponse().withBody(expectedBody).withHeader("Content-Type", "application/json")));
    final AuthorizationValue authorizationValue = new AuthorizationValue(queryParamName, queryParamValue, "query");
    final String actualBody = RemoteUrl.urlToString(getUrl(), Arrays.asList(authorizationValue));
    assertEquals(actualBody, expectedBody);
    verify(getRequestedFor(urlPathEqualTo("/v2/pet/1")).withHeader("Accept", equalTo(EXPECTED_ACCEPTS_HEADER)).withQueryParam(queryParamName, equalTo(queryParamValue)));
}
Also used : AuthorizationValue(io.swagger.models.auth.AuthorizationValue) Test(org.testng.annotations.Test)

Example 8 with AuthorizationValue

use of io.swagger.models.auth.AuthorizationValue 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 9 with AuthorizationValue

use of io.swagger.models.auth.AuthorizationValue 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 10 with AuthorizationValue

use of io.swagger.models.auth.AuthorizationValue in project swagger-parser by swagger-api.

the class SwaggerParser method readWithInfo.

public SwaggerDeserializationResult readWithInfo(String location, List<AuthorizationValue> auths, boolean resolve) {
    if (location == null) {
        return null;
    }
    location = location.replaceAll("\\\\", "/");
    List<SwaggerParserExtension> parserExtensions = getExtensions();
    SwaggerDeserializationResult output;
    if (auths == null) {
        auths = new ArrayList<AuthorizationValue>();
    }
    output = new Swagger20Parser().readWithInfo(location, auths);
    if (output != null) {
        if (output.getSwagger() != null && "2.0".equals(output.getSwagger().getSwagger())) {
            if (resolve) {
                output.setSwagger(new SwaggerResolver(output.getSwagger(), auths, location).resolve());
            }
            return output;
        }
    }
    for (SwaggerParserExtension extension : parserExtensions) {
        output = extension.readWithInfo(location, auths);
        if (output != null && output.getSwagger() != null && "2.0".equals(output.getSwagger().getSwagger())) {
            return output;
        }
    }
    if (output == null) {
        output = new SwaggerDeserializationResult().message("The swagger definition could not be read");
    }
    return output;
}
Also used : AuthorizationValue(io.swagger.models.auth.AuthorizationValue) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult)

Aggregations

AuthorizationValue (io.swagger.models.auth.AuthorizationValue)18 Test (org.testng.annotations.Test)15 SwaggerDeserializationResult (io.swagger.parser.util.SwaggerDeserializationResult)10 Expectations (mockit.Expectations)8 Swagger (io.swagger.models.Swagger)6 SwaggerParser (io.swagger.parser.SwaggerParser)2 ArrayList (java.util.ArrayList)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ModelImpl (io.swagger.models.ModelImpl)1 Path (io.swagger.models.Path)1 Response (io.swagger.models.Response)1 Parameter (io.swagger.models.parameters.Parameter)1 Property (io.swagger.models.properties.Property)1 RefProperty (io.swagger.models.properties.RefProperty)1 StringProperty (io.swagger.models.properties.StringProperty)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1