santhosh-tekuri/jsonschema

ReadOnly and WriteOnly are getting ignored

Closed this issue · 7 comments

Hi I have written a json schema which uses readonly and writeonly but the attribute are getting ignored by the schema. I noticed it while reading the properties filed of the schema and then the readonly field. Is it a error on my side? Could you present an exmaple with read only?

Cheers.

Compiler.ExtractAnnotations must be set to true to read those

Thank you! I dont know if it is documented anywhere but I think it should be for clarification. Is it wanted that a readOnly attribute can still be provided via json which means the validation is still true?

Annotation keywords has no impact on validation

Alright. Thank you. Currently I'm implementing an API and would like to validate the given input JSON data. For exmaple that an application is not allowed to overwrite the id or set the id. Any idea how to implement it using readOnly?

you can think of readOnly as javadoc in java program. the compiler ignores the java doc. whereas java doc tool used them to generate html documentation. similarly jsonschema validator ignores those keywords, where as some editors might use those as hints while editing json.

what you are trying to achieve is not possible using readOnly. But you can try the following:

following schema does not allow to set id:

{
    "properties": {
        "id": false
    }
}

following schema allows either id is not set or id has a specific value say 1234:

{
    "properties": {
        "id": {
            "constant": 1234
        }
    }
}

Thank you! Solved the issue for me.