RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.38k stars 532 forks source link

ReadOnlyAttribute creates property readonly instead of readOnly #1152

Open B1nke opened 4 years ago

B1nke commented 4 years ago

Hi, I'm pretty new to using json shema, but from what I can see in the json hyperschema spec is that the property should be named readOnly and not readonly. From what I can tell from CreateJsonSerializerContractResolver(SchemaType schemaType), I can probably use the SchemaType.Swagger2 to achieve the expected result, but that will also change the behavior of RequiredAttribute, which is not desired. Might just be a typo or does the spec perhaps say that it should be all lower letters in some case?

RicoSuter commented 4 years ago

I think the default for JSON Schema is x-readOnly, no? And only for Swagger/OpenAPI where it is defined we rename it.

https://github.com/RicoSuter/NJsonSchema/blob/master/src/NJsonSchema/JsonSchemaProperty.cs#L78

Is it now also in the standard for JSON Schema?

B1nke commented 4 years ago

Well I'm very new to this but with some googling I ended up on a thread that said that it was in spec 3 but removed in spec 4, but it was actually not removed, just moved to jsonschema-hyperschema. Just went to the github for hyperschema and found some references for it here: https://github.com/json-schema-org/json-schema-spec/blob/master/jsonschema-hyperschema.xml

I'm using react-jsonschema-form to render data based on the schema, and it does not work for readonly but it does for readOnly.

kvanska commented 4 years ago

Based on this: https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.9.4

it should be readOnly, not readonly.

I'm also having problems generating UI forms from the schema because of casing.

Also, for some reason ReadOnly attribute is ignored on class level?

RicoSuter commented 4 years ago

Readonly handling on class level is currently missing. The casing needs to be checked in the static serializer class where the casing is configured per schema type.