swagger-editor icon indicating copy to clipboard operation
swagger-editor copied to clipboard

Validator not recognizing missing property definition in object schemas

Open RitterHannah opened this issue 4 years ago • 2 comments

The following invalid schema is not being recognized by the validator:

InfoRecord:
  type: object
  required:
    - userId
    - name
  properties:
    userId:
      type: string
      description: The user id.

The connexxion validator that runs when I generate a flask app from the spec correctly identifies this issue. The generated documentation also just skips the "name" property.

RitterHannah avatar Jul 22 '21 09:07 RitterHannah

This is not an error. Without additionalProperties: false present, schemas allow arbitrary extra properties besides those explicitly defined in properties. In your example, having name in the required list but not in properties means that the name property must be present regardless of what value it has, i.e. the name value can be a string, number, object, null, etc. - anything. This is equivalent to:

InfoRecord:
  type: object
  required:
    - userId
    - name
  properties:
    userId:
      type: string
      description: The user id.
    name: {}    # <-----

Some OpenAPI linters may have an option to flag such schemas, but technically this is a valid OpenAPI schema.

hkosova avatar Jul 22 '21 13:07 hkosova

Okay, thanks!

RitterHannah avatar Jul 22 '21 14:07 RitterHannah