swagger-editor
swagger-editor copied to clipboard
Validator not recognizing missing property definition in object schemas
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.
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.
Okay, thanks!