pwall567 / json-kotlin-schema

Kotlin implementation of JSON Schema (Draft 07)
MIT License
90 stars 13 forks source link

Any plans to add "unevaluatedProperties"? #15

Open awallat opened 11 months ago

awallat commented 11 months ago

For my project I need to extend an already defined schema by a few other properties. My current solution is to include the schema as a $ref and by using additionalProperties: false. However in my extended schema I need to redefine all properties from the reference, like

"prop1": true,
"prop2": true,
...

As I understand this can be prevented by using unevaluatedProperties. Is there a plan to support this anytime soon?

Thanks for this great library!

pwall567 commented 11 months ago

Hi @awallat , to answer your last question first – yes, I do plan to add unevaluatedProperties, but not in this version. I have had a new version under development for some time now, and this will include the full 2020-12 spec, but I'm afraid I can't yet say when that will be available.

But to go back to your problem – the preferred method for extending a schema is:

    "allOf": [
      {
        "$ref": "original.schema.json"
      },
      {
        "properties": {
          "newProp": {
            "description": "New property, or additional validations on an existing property"
          }
        }
      }
    ]

Would some variation on this technique meet your needs?

awallat commented 11 months ago

Thank you for the info!

The "preferred method" unfortunately doesn't meet my needs. I do not want to allow additional properties and throw an error if there's a property in the JSON document which is not expected. When I add "additionalProperties": false it seems always to be releated to one of the items defined in the allOf-array and not for the union or the extended definition, when setting like this:

"additionalProperties": false,
"allOf": [ ... ]