use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.
the class ParameterSerializationTest method testReadOnlyParameter.
@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);
}
use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.
the class PropertySerializationTest method deserializeEnumStringProperty.
@Test(description = "it should deserialize a StringProperty with enums")
public void deserializeEnumStringProperty() throws IOException {
final String json = "{\"type\":\"string\",\"enum\":[\"a\",\"b\"]}";
final Schema p = m.readValue(json, Schema.class);
assertEquals(p.getType(), "string");
List<String> _enum = ((StringSchema) p).getEnum();
assertNotNull(_enum);
assertEquals(_enum, Arrays.asList("a", "b"));
assertEquals(p.getClass(), StringSchema.class);
assertEquals(m.writeValueAsString(p), json);
}
use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.
the class PropertySerializationTest method deserializeObjectPropertyWithRequiredProperties.
@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));
}
use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.
the class PropertySerializationTest method deserializeNotReadOnlyStringProperty.
@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);
}
use of io.swagger.v3.oas.models.media.StringSchema in project cruise-control by linkedin.
the class ResponseTest method checkSchema.
/**
* Check OpenApi's JSON schema definition against with Java response class.
* The check focus on two things.
* <ul>
* <li>The response hierarchy are the same. In Json response, if a field's value is an array or map, a new layer is
* introduced. The check ensures the layout of layer are the same.</li>
* <li>Within each layer, the field key set are the same.</li>
* </ul>
*
* @param schema The OpenApi schema
* @param className The name of corresponding Java response class.
* @param isOutermost Whether the schema is the outermost layer of the response.
*/
private void checkSchema(Schema schema, String className, boolean isOutermost) {
// Get the complete field key set from Java class.
Map<String, Boolean> fields = extractFieldKeys(_schemaToClass.get(className));
Map<String, Schema> properties = schema.getProperties();
// otherwise it may contain version field because the it can be reused as the outermost layer in another response.
if (isOutermost) {
assertEquals(properties.size(), fields.size() + 1);
assertTrue(properties.get(VERSION) instanceof IntegerSchema);
} else {
if (properties.size() - fields.size() == 1) {
assertTrue(properties.get(VERSION) instanceof IntegerSchema);
} else {
assertEquals(className, properties.size(), fields.size());
}
}
// Check other fields
properties.forEach((k, v) -> {
// Skip version field here.
if (!k.equals(VERSION)) {
// Check key exists.
assertTrue(k + " does not exist in corresponding Java class.", fields.containsKey(k));
// Check key's necessity.
assertEquals(className + ":" + k, fields.get(k), schema.getRequired() != null && schema.getRequired().contains(k));
// Check value
Schema schemaToCheck = v;
while (schemaToCheck instanceof ArraySchema || schemaToCheck instanceof MapSchema) {
if (schemaToCheck instanceof ArraySchema) {
schemaToCheck = ((ArraySchema) schemaToCheck).getItems();
} else {
schemaToCheck = (Schema) schemaToCheck.getAdditionalProperties();
}
}
if (schemaToCheck instanceof StringSchema || schemaToCheck instanceof IntegerSchema || schemaToCheck instanceof NumberSchema || schemaToCheck instanceof ComposedSchema || schemaToCheck instanceof BooleanSchema) {
return;
}
assertNotEquals(schemaToCheck.get$ref(), null);
String refName = schemaToCheck.get$ref();
String schemaName = refName.substring(refName.lastIndexOf('/') + 1);
checkSchema(_openAPI.getComponents().getSchemas().get(schemaName), schemaName, false);
}
});
}
Aggregations