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

jsonschema validation of a post request not working #1376

Closed
anekix opened this issue Oct 29, 2018 · 2 comments
Closed

jsonschema validation of a post request not working #1376

anekix opened this issue Oct 29, 2018 · 2 comments

Comments

@anekix
Copy link

anekix commented Oct 29, 2018

jsonschema validator is not working .

user_schema = {
    "type":"object",
    "properties": {
        "name":{ "type": "string" },
         "address":{ "type" : "string" }
      }
}

from falcon.media.validators import jsonschema
class Users

    @jsonschema.validate(user_schema)
    def on_post(self, req, resp):
       print("called")

The above code seems to work fine when address param is missing in the request body.
request is sent using POST, content-type is application/json

@anekix
Copy link
Author

anekix commented Oct 29, 2018

for anyone looking in to this issue its becuase my schema was not setup properly.
i had to change it to:

user_schema = {
    "type":"object",
    "properties": {
        "name":{ "type": "string" },
         "address":{ "type" : "string" }
      },
"required":["name","address"]
}

to get it working

@vytas7
Copy link
Member

vytas7 commented Dec 28, 2018

@anekix cool that you sorted it out!

I am closing this issue then, but I will check if we need a follow-up documentation issue: I understand the current See json-schema.org for more information on defining a compatible dictionary is not necessarily the most helpful for the user.

We have also created a new umbrella issue for better documentation: #1393

@vytas7 vytas7 closed this as completed Dec 28, 2018
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