use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method propertyTest.
@Test
public void propertyTest(@Injectable List<AuthorizationValue> auths) {
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " /primitiveBody/inline:\n" + " post:\n" + " x-swagger-router-controller: TestController\n" + " operationId: inlineRequiredBody\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: object\n" + " properties:\n" + " name:\n" + " type: string\n" + " required: true\n" + " responses:\n" + " '200':\n" + " description: ok!";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = parser.readContents(yaml, auths, options);
OpenAPI openAPI = result.getOpenAPI();
Map<String, Schema> properties = openAPI.getPaths().get("/primitiveBody/inline").getPost().getRequestBody().getContent().get("application/json").getSchema().getProperties();
assertTrue(properties.get("name") instanceof StringSchema);
}
use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testEmpty.
@Test
public void testEmpty(@Injectable List<AuthorizationValue> auths) {
String json = "{}";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = parser.readContents(json, auths, options);
List<String> messageList = result.getMessages();
Set<String> messages = new HashSet<>(messageList);
assertTrue(messages.contains("attribute openapi is missing"));
}
use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testOptionalParameter.
@Test
public void testOptionalParameter(@Injectable List<AuthorizationValue> auths) {
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " \"/pet\":\n" + " summary: summary\n" + " description: description\n" + " post:\n" + " summary: Add a new pet to the store\n" + " description: ''\n" + " operationId: addPet\n" + " parameters:\n" + " - name: status\n" + " in: query\n" + " description: Status values that need to be considered for filter\n" + " schema:\n" + " type: array\n" + " items:\n" + " type: string\n" + " enum:\n" + " - available\n" + " - pending\n" + " - sold\n" + " default: available";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = parser.readContents(yaml, auths, options);
OpenAPI openAPI = result.getOpenAPI();
Parameter parameter = openAPI.getPaths().get("/pet").getPost().getParameters().get(0);
Assert.assertFalse(parameter.getRequired());
}
use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.
the class RemoteUrlTest method testAuthorizationHeaderWithMatchingUrl.
@Test
public void testAuthorizationHeaderWithMatchingUrl() throws Exception {
final String expectedBody = setupStub();
final String headerName = "Authorization";
final String headerValue = "foobar";
final AuthorizationValue authorizationValue = new AuthorizationValue(headerName, headerValue, "header", url -> url.toString().startsWith("http://localhost"));
final String actualBody = RemoteUrl.urlToString(getUrl(), Arrays.asList(authorizationValue));
assertEquals(actualBody, expectedBody);
verify(getRequestedFor(urlEqualTo("/v2/pet/1")).withHeader("Accept", equalTo(EXPECTED_ACCEPTS_HEADER)).withHeader(headerName, equalTo(headerValue)));
}
use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.
the class ExternalRefProcessorTest method testRelativeRefIncludingUrlRef.
@Test
public void testRelativeRefIncludingUrlRef(@Injectable final Schema mockedModel) throws Exception {
final RefFormat refFormat = RefFormat.RELATIVE;
final String url = "https://my.example.remote.url.com/globals.yaml";
final String expectedResult = "components:\n" + " schemas:\n" + " link-object:\n" + " type: object\n" + " additionalProperties:\n" + " \"$ref\": \"#/components/schemas/rel-data\"\n" + " rel-data:\n" + " type: object\n" + " required:\n" + " - href\n" + " properties:\n" + " href:\n" + " type: string\n" + " note:\n" + " type: string\n" + " result:\n" + " type: object\n" + " properties:\n" + " name:\n" + " type: string\n" + " _links:\n" + " \"$ref\": \"#/components/schemas/link-object\"\n" + "";
List<AuthorizationValue> auths = null;
new Expectations() {
{
RemoteUrl.urlToString(url, auths);
times = 1;
result = expectedResult;
}
};
OpenAPI mockedOpenAPI = new OpenAPI();
mockedOpenAPI.setComponents(new Components());
mockedOpenAPI.getComponents().setSchemas(new HashMap<>());
ResolverCache mockedResolverCache = new ResolverCache(mockedOpenAPI, null, null);
ExternalRefProcessor processor = new ExternalRefProcessor(mockedResolverCache, mockedOpenAPI);
processor.processRefToExternalSchema("./relative-with-url/relative-with-url.yaml#/relative-with-url", refFormat);
assertThat(((Schema) mockedOpenAPI.getComponents().getSchemas().get("relative-with-url").getProperties().get("Foo")).get$ref(), is("https://my.example.remote.url.com/globals.yaml#/components/schemas/link-object"));
assertThat(mockedOpenAPI.getComponents().getSchemas().keySet().contains("link-object"), is(true));
assertThat(mockedOpenAPI.getComponents().getSchemas().keySet().contains("rel-data"), is(true));
// assert that ref is relative ref is resolved. and the file path is from root yaml file.
assertThat(((Schema) mockedOpenAPI.getComponents().getSchemas().get("relative-with-url").getProperties().get("Bar")).get$ref(), is("./relative-with-url/relative-with-local.yaml#/relative-same-file"));
}
Aggregations