Skip to content

Incompatibility between JSON Schema validation & OpenAPI specification #19

Closed
@JoeAlamo

Description

@JoeAlamo

Hey there,

I have been testing this package and I think I have came across an issue which I believe is the result of an incompatibility between the JSON Schema validation being performed, and the OpenAPI specification.

If I have an OpenAPI response with some nullable attributes, I might have that defined like:

...
schema:
  properties:
    first_name:
      type: string
      example: 'Joe'
    last_name:
      type: string
      example: 'Bloggs'
    favourite_colour:
      type: string
      example: 'Red'
      nullable: true

using nullable: true, in accordance with OpenAPI 3.0 spec.

If in my tests, I have a response for that endpoint like the following:

{
  "first_name": "Jane",
  "last_name": "Doe",
  "favourite_colour": null
}

I will receive a Opis\JsonSchema\ValidationError with keyword = "favourite_colour" and keywordArgs = ["expected" => "string", "used" => "null"].

This error is a valid error, from a JsonSchema point of view. To mark something as nullable in JsonSchema, you provide type as an array, such as type: [string, null].

However, whilst that would satisfy JsonSchema, that is invalid according to OpenAPI 3.0 specification.

There may be more cases like that, but that is the only one I have came across.

This feels like quite a fundamental problem. The only solutions I can think of are:

I do hope there is something I've been doing wrong to get these errors but there more I've looked at it, the Json Schema / OpenAPI incompatibility has seemed like the cause!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions