Skip to content

Response schema validation message is not clear for arrays #128

Description

@ashpekvs

Use case description.
Inside my schema yaml file I've specified that response from some URL handler would be an array of objects, e.g.:

      responses:
        "200":
          description: An array of provisioned Resource Records
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ResourceRecord'

I've also described what is ResourceRecord inside the same yaml file

For some reason the code returns an object, not an array
in this case the exception message from OpenAPI framework is a bit strange:

SchemaValidationError: Mimetype invalid: Value id is not of type SchemaType.OBJECT

id from error is the 1st attribute of my object (specified in yaml spec)

What is expected.
The expected error message is to complain that no array specified, array is missed, etc

Activity

  1. michalmiesiak commented on Apr 20, 2020

    @michalmiesiak

    Hello!
    I have a similar issue, but it occurs only on the newest version of openapi-core (0.13.3). I can't seem to validate any array of objects. Currently I must stick to the 0.12.0, which works perfectly but DOES NOT show errors (when a test fails) which is a bit problematic.
    I would like to know if there is any horizon to fix this bug or maybe a workaround exists?

    I remember that versions between 0.12.0 and 0.13.3 did not work for me neither (I can reinstall them and detail the information if needed, but first I wanted to focus on the most recent 0.13.3).

    Use case description.
    The object I'm trying to validate is defined as follows:

        TruckGroupsGet:
          type: object
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/TruckGroup'
    

    And then:

        TruckGroup:
          allOf:
          - $ref: '#/components/schemas/TruckGroupShort'
          - type: object
            properties:
              truck_ids:
                type: array
                items:
                  type: integer
              description:
                type: string
                nullable: true
              last_modified:
                type: string
    

    And finally:

        TruckGroupShort:
          type: object
          properties:
            truck_group_id:
              type: integer
            name:
              type: string
          required:
            - name
            - truck_group_id
    

    I had also tried removing the allOf and merging all into one object, but it did not help.

    What is expected.
    The object is validated correctly, just like in 0.12 and previous versions.

    What is obtained
    The error I get when trying to validate my array of objects says that "your array is not of type object".

    openapi_core.unmarshalling.schemas.exceptions.InvalidSchemaValue: Value {'data': [{'truck_group_id': 1, 'name': 'default', 'truck_ids': [1, 3, 4, 2], 'description': None, 'last_modified': '2020-04-20T17:56:55.820577+02:00'}]} not valid for schema of type SchemaType.OBJECT: (<ValidationError: "[{'truck_group_id': 1, 'name': 'default', 'truck_ids': [1, 3, 4, 2], 'description': None, 'last_modified': '2020-04-20T17:56:55.820577+02:00'}] is not of type object">,)

    I would be glad for any help! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions