@Override public Schema createProperty() { return new StringSchema().format("uri"); } },
@Override public Schema createProperty() { return new StringSchema().format("url"); } },
@Override public Schema createProperty() { return new StringSchema().format("partial-time"); } },
@Override public Schema createProperty() { return new StringSchema().format("email"); } },
@Test(description = "it should serialize a string property with readOnly unset") public void deserializeNotReadOnlyStringProperty() throws IOException { final StringSchema p = new StringSchema(); p.setReadOnly(false); final String json = "{\"type\":\"string\",\"readOnly\":false}"; assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should serialize a string property with readOnly set") public void serializeReadOnlyStringProperty() throws IOException { final Schema p = new StringSchema().readOnly(true); final String json = "{\"type\":\"string\",\"readOnly\":true}"; assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should serialize a StringProperty") public void serializeStringProperty() throws IOException { final StringSchema p = new StringSchema() ._default("Bob"); final String json = "{\"type\":\"string\",\"default\":\"Bob\"}"; assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should serialize a string array property") public void serializeArrayStringProperty() throws IOException { final Schema p = new ArraySchema().items(new StringSchema()); final String json = "{\"type\":\"array\",\"items\":{\"type\":\"string\"}}"; assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should serialize a string MapProperty") public void serializeStringMapProperty() throws IOException { final Schema p = new MapSchema().additionalProperties(new StringSchema()); final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"string\"}}"; assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should deserialize an object property with required set") public void deserializeObjectPropertyWithRequiredProperties() throws IOException { final Schema p = new ObjectSchema() .addProperties("stringProperty", new StringSchema()); p.required(Arrays.asList("stringProperty")); final String json = "{\"type\":\"object\",\"properties\":{\"stringProperty\":{\"type\":\"string\"}},\"required\":[\"stringProperty\"]}"; assertEquals(p, m.readValue(json, Schema.class)); } }
@Test(description = "it should serialize an object property with required set") public void serializeObjectPropertyWithRequiredProperties() throws IOException { final Schema p = new ObjectSchema() .addProperties("stringProperty", new StringSchema()); p.required(Arrays.asList("stringProperty")); final String json = "{\"required\":[\"stringProperty\"],\"type\":\"object\",\"properties\":{\"stringProperty\":{\"type\":\"string\"}}}"; assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should serialize a StringProperty with enums") public void serializeEnumStringProperty() throws IOException { final StringSchema p = new StringSchema(); p._enum(new ArrayList<String>() {{ this.add("a"); this.add("b"); }}); final String json = "{\"type\":\"string\",\"enum\":[\"a\",\"b\"]}"; assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should serialize a PathParameter") public void serializePathParameter() { final Parameter p = new PathParameter().schema(new StringSchema()); final String json = "{\"in\":\"path\",\"required\":true,\"schema\":{\"type\":\"string\"}}"; SerializationMatchers.assertEqualsToJson(p, json); }
@Test(description = "it should serialize a QueryParameter") public void serializeQueryParameter() { final Parameter p = new QueryParameter() .schema(new StringSchema()); final String json = "{\"in\":\"query\",\"schema\":{\"type\":\"string\"}}"; SerializationMatchers.assertEqualsToJson(p, json); }
@Test(description = "it should it should serialize a HeaderParameter") public void serializeHeaderParameter() { final Parameter p = new HeaderParameter() .schema(new StringSchema()); final String json = "{\"in\":\"header\",\"schema\":{\"type\":\"string\"}}"; SerializationMatchers.assertEqualsToJson(p, json); final String yaml = "---\n" + "in: \"header\"\n" + "schema:\n" + " type: \"string\""; SerializationMatchers.assertEqualsToYaml(p, yaml); }
@Test(description = "should mark a parameter as readOnly") public void testReadOnlyParameter() throws Exception { final QueryParameter qp = new QueryParameter(); qp.setSchema(new StringSchema().readOnly(true)); final String json = "{" + " \"in\":\"query\"," + " \"schema\":{" + " \"type\":\"string\"," + " \"readOnly\":true" + " }" + "}"; SerializationMatchers.assertEqualsToJson(qp, json); }
@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); }
@Test(description = "it should serialize a string array HeaderParameter") public void serializeStringArrayHeaderParameter() { final Parameter p = new HeaderParameter() .schema(new ArraySchema() .items(new StringSchema())); final String json = "{\"in\":\"header\",\"schema\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}}"; SerializationMatchers.assertEqualsToJson(p, json); }
@Test(description = "it should create a model with example") public void createModelWithExample() { ObjectSchema model = new ObjectSchema(); model.addProperties("name", new StringSchema().example("Tony")); model.addProperties("id", new IntegerSchema().example(123)); model.example("{\"name\":\"Fred\",\"id\":123456\"}"); assertEquals(model.getExample(), "{\"name\":\"Fred\",\"id\":123456\"}"); } }
@Test(description = "it should serialize a BodyParameter") public void serializeBodyParameter() { final Schema model = new Schema() .title("Cat") .addProperties("name", new StringSchema()); final RequestBody p = new RequestBody() .content(new Content().addMediaType("*/*", new MediaType().schema(model))); final String json = "{\"content\":{\"*/*\":{\"schema\":{\"title\":\"Cat\",\"properties\":{\"name\":{\"type\":\"string\"}}}}}}"; SerializationMatchers.assertEqualsToJson(p, json); }