use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testExampleFlag.
@Test
public void testExampleFlag() {
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveCombinators(true);
options.setResolveFully(true);
options.setFlatten(true);
SwaggerParseResult parseResult = openApiParser.readLocation("media-type-null-example.yaml", null, options);
OpenAPI openAPI = parseResult.getOpenAPI();
assertNull(openAPI.getPaths().get("/pets/{petId}").getGet().getResponses().get("200").getContent().get("application/json").getExample());
assertTrue(openAPI.getPaths().get("/pets/{petId}").getGet().getResponses().get("200").getContent().get("application/json").getExampleSetFlag());
assertNull(openAPI.getPaths().get("/pet").getPost().getResponses().get("200").getContent().get("application/json").getExample());
assertFalse(openAPI.getPaths().get("/pet").getPost().getResponses().get("200").getContent().get("application/json").getExampleSetFlag());
assertNotNull(openAPI.getPaths().get("/pet").getPost().getRequestBody().getContent().get("application/json").getExample());
assertNotNull(openAPI.getPaths().get("/pet").getPost().getRequestBody().getContent().get("application/json").getExample());
assertTrue(openAPI.getPaths().get("/pet").getPost().getRequestBody().getContent().get("application/json").getExampleSetFlag());
assertNotNull(openAPI.getPaths().get("/object-with-null-example").getGet().getResponses().get("200").getContent().get("application/json").getExamples().get("foo").getValue());
assertTrue(openAPI.getPaths().get("/object-with-null-example").getGet().getResponses().get("200").getContent().get("application/json").getExamples().get("foo").getValueSetFlag());
assertNull(openAPI.getPaths().get("/object-with-null-example").getGet().getResponses().get("200").getContent().get("application/json").getExamples().get("bar").getValue());
assertTrue(openAPI.getPaths().get("/object-with-null-example").getGet().getResponses().get("200").getContent().get("application/json").getExamples().get("bar").getValueSetFlag());
assertNotNull(openAPI.getPaths().get("/object-with-null-in-schema-example").getGet().getResponses().get("200").getContent().get("application/json").getExamples().get("a").getValue());
assertTrue(openAPI.getPaths().get("/object-with-null-in-schema-example").getGet().getResponses().get("200").getContent().get("application/json").getExamples().get("a").getValueSetFlag());
assertNotNull(openAPI.getPaths().get("/object-with-null-in-schema-example").getGet().getResponses().get("200").getContent().get("application/json").getExamples().get("b").getValue());
assertTrue(openAPI.getPaths().get("/object-with-null-in-schema-example").getGet().getResponses().get("200").getContent().get("application/json").getExamples().get("b").getValueSetFlag());
assertNotNull(openAPI.getPaths().get("/object-with-null-in-schema-example").getGet().getResponses().get("200").getContent().get("application/json").getExamples().get("c").getValue());
assertTrue(openAPI.getPaths().get("/object-with-null-in-schema-example").getGet().getResponses().get("200").getContent().get("application/json").getExamples().get("c").getValueSetFlag());
assertNull(openAPI.getPaths().get("/object-with-null-in-schema-example").getGet().getResponses().get("200").getContent().get("application/json").getExamples().get("d").getValue());
assertTrue(openAPI.getPaths().get("/object-with-null-in-schema-example").getGet().getResponses().get("200").getContent().get("application/json").getExamples().get("d").getValueSetFlag());
assertNull(openAPI.getComponents().getSchemas().get("ObjectWithNullExample").getExample());
assertTrue(openAPI.getComponents().getSchemas().get("ObjectWithNullExample").getExampleSetFlag());
assertNotNull(openAPI.getComponents().getSchemas().get("ObjectWithNullInSchemaExample").getExample());
assertTrue(openAPI.getComponents().getSchemas().get("ObjectWithNullInSchemaExample").getExampleSetFlag());
assertNotNull(((Schema) openAPI.getComponents().getSchemas().get("ObjectWithNullPropertyExample").getProperties().get("a")).getExample());
assertTrue(((Schema) openAPI.getComponents().getSchemas().get("ObjectWithNullPropertyExample").getProperties().get("a")).getExampleSetFlag());
assertNull(((Schema) openAPI.getComponents().getSchemas().get("ObjectWithNullPropertyExample").getProperties().get("b")).getExample());
assertTrue(((Schema) openAPI.getComponents().getSchemas().get("ObjectWithNullPropertyExample").getProperties().get("b")).getExampleSetFlag());
assertNull(openAPI.getComponents().getSchemas().get("StringWithNullExample").getExample());
assertTrue(openAPI.getComponents().getSchemas().get("StringWithNullExample").getExampleSetFlag());
assertNull(openAPI.getComponents().getSchemas().get("ArrayWithNullArrayExample").getExample());
assertTrue(openAPI.getComponents().getSchemas().get("ArrayWithNullArrayExample").getExampleSetFlag());
assertNull(((ArraySchema) openAPI.getComponents().getSchemas().get("ArrayWithNullItemExample")).getItems().getExample());
assertTrue(((ArraySchema) openAPI.getComponents().getSchemas().get("ArrayWithNullItemExample")).getItems().getExampleSetFlag());
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testAdditionalPropertiesJson.
@Test
public void testAdditionalPropertiesJson() throws Exception {
Operation op = testSpec.getPaths().get("/additionalProperties").getPost();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
loadHandlers("/additionalProperties", HttpMethod.POST, true, validationHandler, (routingContext) -> {
RequestParameters params = routingContext.get("parsedParameters");
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("Content-Type", "application/json").end(params.body().getJsonObject().encode());
});
JsonObject pet = new JsonObject();
pet.put("id", 14612);
pet.put("name", "Willy");
pet.put("lazyness", "Highest");
testRequestWithJSON(HttpMethod.POST, "/additionalProperties", pet, 400, errorMessage(ValidationException.ErrorType.JSON_INVALID));
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testComplexMultipart.
@Test
public void testComplexMultipart() throws Exception {
Operation op = testSpec.getPaths().get("/multipart/complex").getPost();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
loadHandlers("/multipart/complex", HttpMethod.POST, false, validationHandler, (routingContext) -> {
RequestParameters params = routingContext.get("parsedParameters");
assertEquals(params.formParameter("param1").getString(), "sampleString");
assertNotNull(params.formParameter("param2").getJsonObject());
assertEquals(params.formParameter("param2").getJsonObject().getString("name"), "Willy");
assertEquals(params.formParameter("param4").getArray().size(), 4);
routingContext.response().setStatusMessage("ok").end();
});
MultiMap form = MultiMap.caseInsensitiveMultiMap();
form.add("param1", "sampleString");
JsonObject pet = new JsonObject();
pet.put("id", 14612);
pet.put("name", "Willy");
form.add("param2", pet.encode());
form.add("param3", "SELECT * FROM table;");
List<String> valuesArray = new ArrayList<>();
for (int i = 0; i < 4; i++) valuesArray.add(getSuccessSample(ParameterType.FLOAT).getFloat().toString());
form.add("param4", serializeInCSVStringArray(valuesArray));
testRequestWithForm(HttpMethod.POST, "/multipart/complex", FormType.MULTIPART, form, 200, "ok");
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.
the class JsonDeserializationTest method testCompositionTest.
@Test(description = "it should deserialize the composition test")
public void testCompositionTest() throws IOException {
final String json = ResourceUtils.loadClassResource(getClass(), "specFiles/compositionTest-3.0.json");
final Object deserialized = m.readValue(json, OpenAPI.class);
assertTrue(deserialized instanceof OpenAPI);
OpenAPI openAPI = (OpenAPI) deserialized;
Schema lizardSchema = openAPI.getComponents().getSchemas().get("Lizard");
assertTrue(lizardSchema instanceof ComposedSchema);
assertEquals(((ComposedSchema) lizardSchema).getAllOf().size(), 2);
Schema petSchema = openAPI.getComponents().getSchemas().get("Pet");
assertEquals(petSchema.getDiscriminator().getPropertyName(), "pet_type");
assertEquals(petSchema.getDiscriminator().getMapping().get("cachorro"), "#/components/schemas/Dog");
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.
the class JsonDeserializationTest method testDeserializeAPathRef.
@Test
public void testDeserializeAPathRef() throws Exception {
final OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/pathRef.json", OpenAPI.class);
final PathItem petPath = oas.getPaths().get("/pet");
assertNotNull(petPath.get$ref());
assertEquals(petPath.get$ref(), "http://my.company.com/paths/health.json");
assertTrue(oas.getPaths().get("/user") instanceof PathItem);
}
Aggregations