use of io.swagger.v3.plugin.maven.resources.model.Pet in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readContentObject.
@Test(dataProvider = "data")
public void readContentObject(JsonNode rootNode) throws Exception {
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
final Paths paths = openAPI.getPaths();
Assert.assertNotNull(paths);
PathItem petByStatusEndpoint = paths.get("/pet/findByStatusContent");
Assert.assertNotNull(petByStatusEndpoint.getGet());
Assert.assertNotNull(petByStatusEndpoint.getGet().getParameters());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().size(), 3);
Assert.assertNotNull(petByStatusEndpoint.getGet().getParameters().get(0).getContent());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getContent().size(), 1);
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getContent().get("application/json").getSchema().getType(), "array");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getContent().get("application/json").getExample(), null);
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getContent().get("application/json").getExamples().get("list").getSummary(), "List of Names");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getContent().get("application/json").getSchema().getType(), "array");
Assert.assertNotNull(petByStatusEndpoint.getGet().getParameters().get(1).getContent());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(1).getContent().size(), 1);
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(1).getContent().get("application/xml").getExamples().get("list").getSummary(), "List of names");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(1).getContent().get("application/xml").getExamples().get("list").getValue(), "<Users><User name='Bob'/><User name='Diane'/><User name='Mary'/><User name='Bill'/></Users>");
Assert.assertNotNull(petByStatusEndpoint.getGet().getParameters().get(1).getContent().get("application/xml").getExamples().get("empty").getSummary());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(1).getContent().get("application/xml").getExamples().get("empty").getSummary(), "Empty list");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(1).getContent().get("application/xml").getExamples().get("empty").getValue(), "<Users/>");
Assert.assertNotNull(petByStatusEndpoint.getGet().getParameters().get(2).getContent());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(2).getContent().size(), 1);
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(2).getContent().get("text/plain").getExamples().get("list").getSummary(), "List of names");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(2).getContent().get("text/plain").getExamples().get("list").getValue(), "Bob,Diane,Mary,Bill");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(2).getContent().get("text/plain").getExamples().get("empty").getSummary(), "Empty");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(2).getContent().get("text/plain").getExamples().get("empty").getValue(), "");
PathItem petEndpoint = paths.get("/pet");
Assert.assertNotNull(petEndpoint.getPut());
Assert.assertNotNull(petEndpoint.getPut().getResponses().get("400").getContent().get("application/json"));
Assert.assertEquals(petEndpoint.getPut().getResponses().get("400").getContent().size(), 1);
Assert.assertEquals(petEndpoint.getPut().getResponses().get("400").getContent().get("application/json").getSchema().getType(), "array");
}
use of io.swagger.v3.plugin.maven.resources.model.Pet 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.plugin.maven.resources.model.Pet 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.plugin.maven.resources.model.Pet in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readExamplesObject.
@Test(dataProvider = "data")
public void readExamplesObject(JsonNode rootNode) throws Exception {
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
final Paths paths = openAPI.getPaths();
Assert.assertNotNull(paths);
Assert.assertEquals(paths.size(), 19);
// parameters operation get
PathItem petByStatusEndpoint = paths.get("/pet/findByStatus");
Assert.assertNotNull(petByStatusEndpoint.getGet());
Assert.assertNotNull(petByStatusEndpoint.getGet().getParameters());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().size(), 1);
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getName(), "status");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getIn(), "query");
}
use of io.swagger.v3.plugin.maven.resources.model.Pet in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readSchemaObject.
@Test(dataProvider = "data")
public void readSchemaObject(JsonNode rootNode) throws Exception {
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
final Paths paths = openAPI.getPaths();
Assert.assertNotNull(paths);
Assert.assertEquals(paths.size(), 19);
// parameters operation get
PathItem petByStatusEndpoint = paths.get("/pet/findByStatus");
Assert.assertNotNull(petByStatusEndpoint.getGet());
Assert.assertNotNull(petByStatusEndpoint.getGet().getParameters());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().size(), 1);
Assert.assertNotNull(petByStatusEndpoint.getGet().getParameters().get(0).getSchema());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getSchema().getFormat(), "int64");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getSchema().getXml().getNamespace(), "http://example.com/schema/sample");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getSchema().getXml().getPrefix(), "sample");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getIn(), "query");
}
Aggregations