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

Multiple missing mandatory fields result in only one error #100

Closed
berend opened this issue Sep 13, 2018 · 3 comments
Closed

Multiple missing mandatory fields result in only one error #100

berend opened this issue Sep 13, 2018 · 3 comments
Labels
area/schema Indicates an issue on schema area kind/bug/confirmed

Comments

@berend
Copy link
Contributor

berend commented Sep 13, 2018

Given a openapi spec with multiple mandatory fields and a request missing several, the result of RequestValidator.validate only shows the first field.

To reproduce have a look at this repo, it contains a simple flask app, openapi spec and a curl command to test it.

The gist of it here:

Openapi spec (extract)

"requestBody": {
   "required": true,
   "content": {
      "application/json": {
         "schema": {
            "type": "object",
            "properties": {
               "name": {
                  "type": "string"
               },
               "brand": {
                  "type": "string"
               },
               "ps": {
                  "type": "integer"
               }
            },
            "required": [
               "name",
               "brand"
            ]
         },

Two mandatory fields. When sending only the optional field like this:

curl -X POST \
  http://127.0.0.1:8080/cars \
  -H 'Content-Type: application/json' \
  -d '{"ps": 123}'

I would expect result.errors to contain two entries, but there is only one:

[MissingSchemaProperty('Missing schema property name')]

There is no notion of brand missing as well.

@p1c2u p1c2u added kind/bug/confirmed area/schema Indicates an issue on schema area labels Oct 25, 2018
@berend
Copy link
Contributor Author

berend commented Jan 28, 2019

After I fixed the tests locally for me ( see #107 ), I looked into this. The main problem is, that error handling is done via Exceptions and you can only raise one exception at the time.

So, to have multiple errors reported as once, you either need to put multiple errors in one exception or rewrite the error handling. Did you think about this already? If you have a direction you want to go - I am willing to help.

I have a (very rough) failing test to reproduce this here

@p1c2u
Copy link
Collaborator

p1c2u commented Mar 10, 2019

I work on new jsonschema validation process that will fix the issue.

@p1c2u
Copy link
Collaborator

p1c2u commented Feb 17, 2020

Fix with new unmarshalling mechanism. Hence closing

@p1c2u p1c2u closed this as completed Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/schema Indicates an issue on schema area kind/bug/confirmed
Projects
None yet
Development

No branches or pull requests

2 participants