@Test(description = "it should generate a JSON with read-only from pojo, #1161") public void readOnlyJsonGeneration() throws IOException { Map<String, Schema> models = ModelConverters.getInstance().read(ReadOnlyModel.class); Schema model = models.get("ReadOnlyModel"); Schema id = (Schema) model.getProperties().get("id"); assertTrue(id.getReadOnly()); Schema readWriteId = (Schema) model.getProperties().get("readWriteId"); assertNull(readWriteId.getReadOnly()); }
@Test(description = "it should set readOnly per #854") public void setReadOnly() { final Map<String, Schema> schemas = readAll(JacksonReadonlyModel.class); final Schema model = (Schema) schemas.get("JacksonReadonlyModel"); final Schema prop = (Schema) model.getProperties().get("count"); assertTrue(prop.getReadOnly()); }
@Test(description = "it should deserialize a model with read-only property") public void deserializeModelWithReadOnlyProperty() throws IOException { final String json = "{\n" + " \"properties\":{\n" + " \"id\":{\n" + " \"type\":\"integer\",\n" + " \"format\":\"int32\",\n" + " \"readOnly\":true\n" + " }\n" + " }\n" + "}"; final Schema model = Json.mapper().readValue(json, Schema.class); Schema property = (Schema) model.getProperties().get("id"); assertTrue(property.getReadOnly()); }
@Test public void testReadOnlyProperty() { final Map<String, Schema> models = ModelConverters.getInstance().readAll(ReadOnlyFields.class); Schema model = models.get("ReadOnlyFields"); assertTrue(((Schema) model.getProperties().get("id")).getReadOnly()); }
@Test(description = "it should deserialize a read only parameter") public void deserializeReadOnlyParameter() throws IOException { final String json = "{\"in\":\"path\"," + "\"content\":{" + " \"*/*\":{" + " \"schema\":{" + " \"type\":\"string\"," + " \"readOnly\":true}}}}"; final Parameter p = m.readValue(json, Parameter.class); assertTrue(p.getContent().get("*/*").getSchema().getReadOnly()); }
.pattern(subtypeModel.getPattern()) .properties(subtypeModel.getProperties()) .readOnly(subtypeModel.getReadOnly()) .required(subtypeModel.getRequired()) .type(subtypeModel.getType())
/** * Checks if a property is read-only. * * @return true if the property is read-only */ public boolean getReadOnly() { return BooleanUtils.isTrue(property.getReadOnly()); } }
private boolean isSchemaWithAdditionalValues(Schema schema) { return nonNull(schema.getDescription()) || nonNull(schema.getExample()) || nonNull(schema.getXml()) || nonNull(schema.getReadOnly()) || (nonNull(schema.getExtensions()) && !schema.getExtensions().isEmpty()); }
private boolean isPropertyApplicable(Schema schema, DiffContext context) { return !(context.isResponse() && Boolean.TRUE.equals(schema.getWriteOnly())) && !(context.isRequest() && Boolean.TRUE.equals(schema.getReadOnly())); }
cp.hasMore = true; if (!Boolean.TRUE.equals(propertyList.get(i + 1).getValue().getReadOnly())) { cp.hasMoreNonReadOnly = true; // next entry is not ready only
cp.getVendorExtensions().put(CodegenConstants.HAS_MORE_EXT_NAME, Boolean.TRUE); if (!Boolean.TRUE.equals(propertyList.get(i+1).getValue().getReadOnly())) { cp.getVendorExtensions().put(CodegenConstants.HAS_MORE_NON_READ_ONLY_EXT_NAME, Boolean.TRUE);
cp.getVendorExtensions().put(CodegenConstants.HAS_MORE_EXT_NAME, Boolean.TRUE); if (!Boolean.TRUE.equals(propertyList.get(i+1).getValue().getReadOnly())) { cp.getVendorExtensions().put(CodegenConstants.HAS_MORE_NON_READ_ONLY_EXT_NAME, Boolean.TRUE);
codegenProperty.defaultValueWithParam = toDefaultValueWithParam(name, propertySchema); codegenProperty.jsonSchema = Json.pretty(propertySchema); if (propertySchema.getReadOnly() != null) { codegenProperty.getVendorExtensions().put(CodegenConstants.IS_READ_ONLY_EXT_NAME, propertySchema.getReadOnly());
codegenProperty.nullable = propertySchema.getNullable(); if (propertySchema.getReadOnly() != null) { codegenProperty.getVendorExtensions().put(CodegenConstants.IS_READ_ONLY_EXT_NAME, propertySchema.getReadOnly());
.setEnumeration(changedEnum) .setChangeFormat(!Objects.equals(left.getFormat(), right.getFormat())) .setReadOnly(new ChangedReadOnly(left.getReadOnly(), right.getReadOnly(), context)) .setWriteOnly(new ChangedWriteOnly(left.getWriteOnly(), right.getWriteOnly(), context)) .setMaxLength(new ChangedMaxLength(left.getMaxLength(), right.getMaxLength(), context));
property.defaultValueWithParam = toDefaultValueWithParam(name, p); property.jsonSchema = Json.pretty(p); if (p.getReadOnly() != null) { property.isReadOnly = p.getReadOnly();
public AnyProperty(Schema prop) { if (prop != null) { setName(prop.getName()); setDescription(prop.getDescription()); setExample(prop.getExample()); setFormat(prop.getFormat()); setReadOnly(prop.getReadOnly()); setRequired(prop.getRequired()); setTitle(prop.getTitle()); setExtensions(prop.getExtensions()); setXml(prop.getXml()); setExternalDocs(prop.getExternalDocs()); setProperties(prop.getProperties()); set$ref(prop.get$ref()); } } }
.pattern(subtypeModel.getPattern()) .properties(subtypeModel.getProperties()) .readOnly(subtypeModel.getReadOnly()) .required(subtypeModel.getRequired()) .type(subtypeModel.getType())
composedSchema.setPattern(schema.getPattern()); composedSchema.setProperties(schema.getProperties()); composedSchema.setReadOnly(schema.getReadOnly()); composedSchema.setRequired(schema.getRequired()); composedSchema.setTitle(schema.getTitle());