Skip to content

Integer validation error #19

@ehsanonline

Description

@ehsanonline

I was testing this example code:

from quart import request,jsonify
from quart_openapi import Pint,Resource

app = Pint(__name__)

expected = app.create_validator('sample_request', {
  'type': 'object',
  'properties': {
    'foobar': {
      'type': 'string'
    },
    'baz': {
      'oneOf': [
        { 'type': 'integer' },
        { 'type': 'number', 'format': 'float' }
      ]
    }
  }
})
@app.route('/')
class Testing(Resource):
  @app.expect(expected)
  async def post(self):
    return jsonify({'message': 'OK'})
if __name__ == '__main__' :
  app.run(debug=True)

Then send this request:

curl -X POST -d '{"foobar":"ss","baz":123}' -H "Content-Type: application/json" http://127.0.0.1:5000 

I got this respond:

HTTP/1.1 400 
content-type: application/json
content-length: 235
date: Sun, 16 Dec 2018 21:00:01 GMT
server: hypercorn-h11

{
  "message": "Request Body failed validation",
  "error": {
    "msg": "123 is valid under each of {'type': 'number', 'format': 'float'}, {'type': 'integer'}",
    "value": 123,
    "schema": {
      "oneOf": [{
        "type": "integer"
      }, {
        "type": "number",
        "format": "float"
      }]
    }
  }
}

But I was expecting {'message':'OK'} respond.
It works with float value for baz key.

Funny note: at respond in msg it says 'is valid' !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions