Skip to content
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

Bug: when API endpoint return list, InvalidMediaTypeValue exception was generated #28

Closed
andyceo opened this issue Apr 23, 2018 · 3 comments

Comments

@andyceo
Copy link

andyceo commented Apr 23, 2018

When some API endpoint return list (array) of something, openapi-core generates InvalidMediaTypeValue exception:

/peers/all
Request errors: [] Response errors: [InvalidMediaTypeValue('Failed to cast value of [ to SchemaType.OBJECT',)]
 [FAIL] 1 errors found 
Response body: [
]

This exception generated no matter list is empty or not.

@andyceo andyceo changed the title Bug: when API return list, InvalidMediaTypeValue exception was generated Bug: when API endpoint return list, InvalidMediaTypeValue exception was generated Apr 23, 2018
@andyceo
Copy link
Author

andyceo commented Apr 23, 2018

Some important addition: it seems that this error is generated only if returned result should be a list of objects:

  /peers/connected:
    get:
      summary: Get current connected peers
      operationId: getConnectedPeers
      tags:
        - peers
      responses:
        '200':
          description: Array of peer objects
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Peer'

In case when list should be list of strings, error did not generated and validation is ok:

  /peers/blacklisted:
    get:
      summary: Get blacklisted peers
      operationId: getBlacklistedPeers
      tags:
        - peers
      responses:
        '200':
          description: Array of the addresses
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string
                  description: Blacklisted node address

@p1c2u
Copy link
Collaborator

p1c2u commented Apr 23, 2018

@andyceo of corse, you're right. I forgot that JSON text can be an array too (not just object). I will prepare fix.

@andyceo
Copy link
Author

andyceo commented Apr 24, 2018

Great work! Thank you so much! Can confirm this error is gone. May be new release? 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants