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)));
}
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)));
}
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());
}
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);
}
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;
}
Aggregations