use of io.swagger.v3.jaxrs2.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.jaxrs2.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.jaxrs2.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.jaxrs2.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");
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-parser by swagger-api.
the class OpenAPIParserTest method testIssue1608.
@Test
public void testIssue1608() {
ParseOptions options = new ParseOptions();
options.setResolveFully(true);
OpenAPIParser openAPIParser = new OpenAPIParser();
SwaggerParseResult swaggerParseResult = openAPIParser.readLocation("issue1608.json", null, options);
Schema schema = swaggerParseResult.getOpenAPI().getPaths().get("/pet").getPut().getRequestBody().getContent().get("application/json").getSchema();
assertEquals(schema.getRequired().size(), 1);
}
Aggregations