santhosh-tekuri / jsonschema

JSONSchema (draft 2020-12, draft 2019-09, draft-7, draft-6, draft-4) Validation using Go
Apache License 2.0
957 stars 98 forks source link

Look for deprecated and changed annotations #157

Closed afbjorklund closed 7 months ago

afbjorklund commented 7 months ago

These are used by the cloud-init schema for cloud-config

https://raw.githubusercontent.com/canonical/cloud-init/main/cloudinit/config/schemas/schema-cloud-config-v1.json

Example result, when validating with those annotations:

  [I#] [S#/allOf/8] allOf failed
    [I#] [S#/allOf/8/$ref] doesn't validate with '/$defs/cc_ca_certs'
      [I#/ca-certs] [S#/$defs/cc_ca_certs/properties/ca-certs/allOf/1] allOf failed
        [I#/ca-certs] [S#/$defs/cc_ca_certs/properties/ca-certs/allOf/1/deprecated] Use ``ca_certs`` instead. (since v22.3)
  [I#] [S#/allOf/49] allOf failed
    [I#] [S#/allOf/49/$ref] doesn't validate with '/$defs/cc_users_groups'
      [I#/users/0] [S#/$defs/cc_users_groups/properties/users/items/oneOf] oneOf failed
        [I#/users/0] [S#/$defs/cc_users_groups/properties/users/items/oneOf/0/type] expected string, but got object
        [I#/users/0] [S#/$defs/cc_users_groups/properties/users/items/oneOf/1/type] expected array, but got object
        [I#/users/0] [S#/$defs/cc_users_groups/properties/users/items/oneOf/2/$ref] doesn't validate with '/$defs/users_groups.user'
          [I#/users/0/uid] [S#/$defs/users_groups.user/properties/uid/oneOf] oneOf failed
            [I#/users/0/uid] [S#/$defs/users_groups.user/properties/uid/oneOf/0/type] expected integer, but got string
            [I#/users/0/uid] [S#/$defs/users_groups.user/properties/uid/oneOf/1/deprecated] The use of ``string`` type is deprecated. Use an ``integer`` instead. (since v22.3)
          [I#/users/0/ssh-authorized-keys] [S#/$defs/users_groups.user/properties/ssh-authorized-keys/allOf/1] allOf failed
            [I#/users/0/ssh-authorized-keys] [S#/$defs/users_groups.user/properties/ssh-authorized-keys/allOf/1/deprecated] Use ``ssh_authorized_keys`` instead. (since v18.3)
santhosh-tekuri commented 7 months ago

the keywords you added are not part of jsonschema specification. So adding It to default compiler and validation is not suggested. You can create custom Extension to handle these kind of behaviour.

you can follow the example: https://github.com/santhosh-tekuri/jsonschema/blob/master/example_extension_test.go