Skip to content

absolute_schema_path is incorrect for if/then constructs #696

Closed
@jason-s

Description

@jason-s

I'm using jsonschema 3.2.0 for Python 2.7.14 and am seeing an error in the absolute_schema_path when an if/then construct is involved.

See sample code https://gist.github.com/jason-s/188c226e51f0982ab05538c2d6581c21

which outputs (on my machine) the following, including absolute_schema_path that starts with ['allOf', 0, 'if', 'then' --- the problem is that the if and then keys are at the same level; if we are trying to indicate the then branch, then if should not be in the absolute_schema_path

jsonschema version: 3.2.0
item1: success
item2: success
=====
item3: failure
message: 0 is not of type 'string'
path: ['color']
absolute_schema_path: ['allOf', 0, 'if', 'then', 'properties', 'color', 'type']
0 is not of type 'string'

Failed validating 'type' in schema['allOf'][0]['if']['then']['properties']['color']:
    {'type': 'string'}

On instance['color']:
    0
=====
item4: failure
message: Additional properties are not allowed ('zipcode' was unexpected)
path: []
absolute_schema_path: ['allOf', 0, 'if', 'then', 'additionalProperties']
Additional properties are not allowed ('zipcode' was unexpected)

Failed validating 'additionalProperties' in schema['allOf'][0]['if']['then']:
    {'additionalProperties': False,
     'properties': {'color': {'type': 'string'}, 'type': {'const': 'foo'}},
     'required': ['color'],
     'type': 'object'}

On instance:
    {'color': 'red', 'type': 'foo', 'zipcode': 12345}

my sample schema (in YAML form)

title: SCHEMA 1 (foo_node or bar_node)
$ref: '#/definitions/root_node'
$schema: http://json-schema.org/draft-07/schema#
definitions:
  bar_node:
    additionalProperties: false
    properties:
      type: {const: bar}
      flavor: {type: string}
    required: [flavor]
    type: object
  foo_node:
    additionalProperties: false
    properties:
      type: {const: foo}
      color: {type: string}
    required: [color]
    type: object
  root_node:
    allOf:
    - if:
        properties:
          type: {const: foo}
      then: {$ref: '#/definitions/foo_node'}
    - if:
        properties:
          type: {const: bar}
      then: {$ref: '#/definitions/bar_node'}
    properties:
      type:
        enum: [foo, bar]
    required: [type]

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething doesn't work the way it should.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions