Skip to content

additionalProperties==false produces unexpected behavior when used with definitions #507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dreftymac opened this issue Dec 16, 2018 · 4 comments
Labels
Invalid Not a bug, PEBKAC, or an unsupported setup

Comments

@dreftymac
Copy link

Problem

  • Using additionalProperties seems to omit acceptance of declared properties when those properties are declared in a definitions section

Expected behavior

  • The additionalProperties setting should not behave differently depending on whether properties are declared in a definitions section

Actual behavior

  • The additionalProperties setting behaves differently depending on whether properties are declared in a definitions section
  • In the example below, the schema that avoids the use of definitions behaves as expected when additionalProperties == false
  • In the example below, the schema that uses definitions behaves unexpectedly additionalProperties == false ... the error message is Additional properties are not allowed

Example

Sample schema (avoiding use of definitions and YAML-formatted)

  additionalProperties:   false
  type:             object
  required:         ["fname", "lname", "age"]
  properties:
    fname:          { type: string  }
    lname:          { type: string  }
    age:            { type: integer }

Sample schema (using definitions and YAML-formatted)

  additionalProperties:   false
  allOf:
    - {"$ref": "#/definitions/contactinfo_001"}
  definitions:
    contactinfo_001:
      type:             object
      required:         ["fname", "lname", "age"]
      properties:
        fname:          { type: string  }
        lname:          { type: string  }
        age:            { type: integer }

Sample documents

  # ## ********************
  ## NO__WORKY -- age must be integer
  -
    fname:            homer
    lname:            himpson
    age:              '33'

  ## ********************
  ## NO__WORKY -- age is required
  -
    fname:            homer
    lname:            himpson

  ## ********************
  ## YES_WORKY -- all expected properties
  -
    fname:            homer
    lname:            himpson
    age:              33

  ## ********************
  ## additional property 'motto' (affected by additionalProperties)
  -
    fname:            homer
    lname:            himpson
    age:              33
    motto:            i love science
@Julian
Copy link
Member

Julian commented Dec 16, 2018

Hi, thanks.

This is the behavior specified by the spec for better or worse.

Many run into this same issue, which I believe is being addressed in part in draft 8, but yeah, nothing really here for this library to do at the minute.

@dreftymac
Copy link
Author

Got it. Thanks for the heads-up. Any references or links to the specification greatly appreciated, by anyone who may come across this issue, before it is closed.

Thanks again.

@handrews
Copy link

@dreftymac you are looking for draft-08's unevaluatedProperties: json-schema-org/json-schema-spec#656 (although note that there were several other changes laying the groundwork for how that keywords functions, as it's much more complicated than you'd think to make this work).

@Julian Julian closed this as completed Dec 16, 2018
@Julian
Copy link
Member

Julian commented Dec 16, 2018

(thanks for the ref @handrews)

@Julian Julian added the Invalid Not a bug, PEBKAC, or an unsupported setup label Apr 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Invalid Not a bug, PEBKAC, or an unsupported setup
Projects
None yet
Development

No branches or pull requests

3 participants