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

File unexpectedly passes validation - should complain about arrays in response or undefined type #98

Closed
jamescooke opened this issue Aug 12, 2019 · 6 comments · Fixed by #99
Labels

Comments

@jamescooke
Copy link
Contributor

Am running v0.13.3 installed inside a Node 12.4 Docker container.

Given the following openapi v3 spec:

openapi: 3.0.0
info:
  description: Test arrays returned
  version: '0'
  title: Things service
servers:
  - url: 'https://example.com/test'
paths:
  '/things':
    post:
      summary: Do things
      operationId: do_things
      responses:
        '200':
          description: OK.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ThingsArray'
components:
  schemas:
    ThingsArray:
      description: List of empty Things
      items:
        type: object

This example file is very closely related to the example in #71 - but I've removed the type: array specification from ThingsArray. This is a little bit of a grey area I guess since the openapi file is not explicit about the type of ThingsArray, however, the Swagger Editor renders this as an Array and gives an example JSON of:

[
  {}
]

Current behaviour

The file above passes the validator.

Expected behaviour

The file above should fail with something - I can see one of two options, but would be generally happy as long as some kind of error or warning is returned for this case.

Treat it as an array

Assume that ThingsArray which has unspecified 'type' is an array and give the error:

errors

  Message :   Arrays MUST NOT be returned as the top-level structure in a response body.
  Path    :   paths./things.post.responses.200.content.application/json.schema
  Line    :   18

Complain about missing type

Add a warning that indicates that 'type' has not been provided:

warnings

  Message :   Property type not provided.
  Path    :   components.schemas.ThingsArray.items.type
  Line    :   25
@dpopp07
Copy link
Member

dpopp07 commented Aug 12, 2019

Hmm yeah that's an interesting one. Neither would be tough to add and I agree that this should probably be flagged somehow. I'm inclined to lean towards treating the schema as an array due to the presence of the items property, rather than flagging the missing type, but I'm not sure.

@mkistler what do you think?

@mkistler
Copy link
Contributor

I won't advocate this as a general rule, but in this particular case, I think we should treat a schema with items as being an array.

@dpopp07
Copy link
Member

dpopp07 commented Aug 14, 2019

@jamescooke If you agree with that, I can implement that fix this week

@jamescooke
Copy link
Contributor Author

@dpopp07 @mkistler Thanks for reviewing this issue. I'm happy with treating this as an array and giving the "Arrays MUST NOT be returned as the top-level structure in a response body." error 👍

@dpopp07
Copy link
Member

dpopp07 commented Aug 27, 2019

🎉 This issue has been resolved in version 0.13.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jamescooke
Copy link
Contributor Author

Thanks 👍 - can confirm this is working great in v0.13.5 https://github.com/IBM/openapi-validator/releases/tag/v0.13.5

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

Successfully merging a pull request may close this issue.

3 participants