use of io.swagger.v3.oas.models.media.ObjectSchema in project swagger-core by swagger-api.
the class ObjectPropertyTest method readModelWithObjectProperty.
@Test(description = "convert a model with object properties")
public void readModelWithObjectProperty() throws IOException {
String json = "{" + " \"properties\":{" + " \"id\":{" + " \"type\":\"string\"" + " }," + " \"someObject\":{" + " \"type\":\"object\"," + " \"x-foo\": \"vendor x\"," + " \"properties\":{" + " \"innerId\":{" + " \"type\":\"string\"" + " }" + " }" + " }" + " }" + "}";
Schema model = Json.mapper().readValue(json, Schema.class);
Schema p = (Schema) model.getProperties().get("someObject");
assertTrue(p instanceof ObjectSchema);
ObjectSchema op = (ObjectSchema) p;
Schema sp = op.getProperties().get("innerId");
assertTrue(sp instanceof StringSchema);
assertTrue(op.getExtensions() != null);
assertNotNull(op.getExtensions().get("x-foo"));
assertEquals(op.getExtensions().get("x-foo"), "vendor x");
}
use of io.swagger.v3.oas.models.media.ObjectSchema in project swagger-core by swagger-api.
the class MapPropertyDeserializerTest method testBooleanAdditionalPropertiesDeserialization.
@Test(description = "it should deserialize a boolean additionalProperties")
public void testBooleanAdditionalPropertiesDeserialization() throws Exception {
Operation operation = Json.mapper().readValue(jsonAdditionalPropertiesBoolean, Operation.class);
ApiResponse response = operation.getResponses().get("200");
assertNotNull(response);
Schema responseSchema = response.getContent().get("*/*").getSchema();
assertNotNull(responseSchema);
assertTrue(responseSchema instanceof ObjectSchema);
assertTrue(responseSchema.getAdditionalProperties() instanceof Boolean);
Assert.assertFalse((Boolean) responseSchema.getAdditionalProperties());
operation = Json.mapper().readValue(jsonAdditionalPropertiesBooleanTrue, Operation.class);
response = operation.getResponses().get("200");
assertNotNull(response);
responseSchema = response.getContent().get("*/*").getSchema();
assertNotNull(responseSchema);
assertTrue(responseSchema instanceof MapSchema);
assertTrue(responseSchema.getAdditionalProperties() instanceof Boolean);
Assert.assertTrue((Boolean) responseSchema.getAdditionalProperties());
}
use of io.swagger.v3.oas.models.media.ObjectSchema in project swagger-core by swagger-api.
the class MapPropertyDeserializerTest method testBooleanAdditionalPropertiesSerialization.
@Test(description = "it should serialize a boolean additionalProperties")
public void testBooleanAdditionalPropertiesSerialization() throws Exception {
Operation operation = Json.mapper().readValue(json, Operation.class);
ApiResponse response = operation.getResponses().get("200");
assertNotNull(response);
Schema responseSchema = response.getContent().get("*/*").getSchema();
Schema schema = new ObjectSchema().additionalProperties(true);
assertEquals(normalizeLineEnds(Json.pretty(schema)), "{\n" + " \"type\" : \"object\",\n" + " \"additionalProperties\" : true\n" + "}");
schema = new ObjectSchema().additionalProperties(responseSchema);
assertEquals(normalizeLineEnds(Json.pretty(schema)), "{\n" + " \"type\" : \"object\",\n" + " \"additionalProperties\" : {\n" + " \"type\" : \"object\",\n" + " \"additionalProperties\" : {\n" + " \"type\" : \"integer\",\n" + " \"format\" : \"int32\"\n" + " },\n" + " \"x-foo\" : \"vendor x\"\n" + " }\n" + "}");
}
use of io.swagger.v3.oas.models.media.ObjectSchema in project swagger-core by swagger-api.
the class ModelExampleTest method createModel.
@Test(description = "it should create a model")
public void createModel() {
ObjectSchema model = new ObjectSchema();
model.addProperties("name", new StringSchema().example("Tony"));
model.addProperties("id", new IntegerSchema().example(123));
assertNotNull(model);
}
use of io.swagger.v3.oas.models.media.ObjectSchema in project swagger-core by swagger-api.
the class OpenAPI3_1SerializationTest method testRequestBodyRefSerialization.
@Test
public void testRequestBodyRefSerialization() {
OpenAPI openAPI = new OpenAPI().openapi("3.1.0").path("/test", new PathItem().description("test path item").post(new Operation().operationId("testPathItem").requestBody(new RequestBody().$ref("#/components/requestBodies/body").description("ref request body")))).components(new Components().addRequestBodies("body", new RequestBody().content(new Content().addMediaType("application/json", new MediaType().schema(new ObjectSchema())))));
SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.1.0\n" + "paths:\n" + " /test:\n" + " description: test path item\n" + " post:\n" + " operationId: testPathItem\n" + " requestBody:\n" + " description: ref request body\n" + " $ref: '#/components/requestBodies/body'\n" + "components:\n" + " requestBodies:\n" + " body:\n" + " content:\n" + " application/json:\n" + " schema: {}");
SerializationMatchers.assertEqualsToJson31(openAPI, "{\n" + " \"openapi\" : \"3.1.0\",\n" + " \"paths\" : {\n" + " \"/test\" : {\n" + " \"description\" : \"test path item\",\n" + " \"post\" : {\n" + " \"operationId\" : \"testPathItem\",\n" + " \"requestBody\" : {\n" + " \"description\" : \"ref request body\",\n" + " \"$ref\" : \"#/components/requestBodies/body\"\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"components\" : {\n" + " \"requestBodies\" : {\n" + " \"body\" : {\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : { }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}");
}
Aggregations