question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

External yml with flask_restful method

See original GitHub issue

Is this an expected behaviour?

This works:

class todo(Resource):
    def get(self, todo_id):
        """
        file: todo_get.yml
        """
        abort_if_todo_doesnt_exist(todo_id)
        return TODOS[todo_id]

This:

from flasgger import swag_from

class todo(Resource):
    @swag_from('todo_get.yml', validation=True)
    def get(self, todo_id):
        abort_if_todo_doesnt_exist(todo_id)
        return TODOS[todo_id]

Gives: Code: 200 Data: { “message”: null }

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
juliencuvilliercommented, Aug 21, 2017

Hi, I have the same issue here, using manual validation

Response is:

{"message": null}

When using this code:

class ChronosAddRequest(Resource):

    @swag_from("swaggerdocs/chronos_post.yml")
    def post(self):
        validate(request.json, 'ChronosPost', 'swaggerdocs/chronos_post.yml')

Everything is fine when removing the validation step

0reactions
lindvallcommented, Aug 29, 2019

I’ve experienced a similar or same issue.

By changing the abort call in parse_request: https://github.com/flasgger/flasgger/blob/31c86c4db66b3e4d6446bb024cca50cf51652561/flasgger/base.py#L638

to:

abort(400, e.message)

It successfully returns the ValidationError message with the status code 400. I tried to figure out why it fails to abort with the Response object, but couldn’t find the cause.

However, for a better end user experience perhaps the try/except clause should be replaced by something like this?:

v = jsonschema.Draft7Validator(
    schemas[location], format_checker=self.format_checker)
errors = ['%s: %s' % (
    error.path.pop(), error.message) for error in v.iter_errors(data)]
if errors:
    abort(400, errors))

The formatting of the messages should perhaps be configured by the user, but this is just an example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extending Flask-RESTful — Flask-RESTful 0.3.8 documentation
It is possible to configure how the default Flask-RESTful JSON representation will format JSON by providing a RESTFUL_JSON attribute on the application ...
Read more >
flasgger/flasgger: Easy OpenAPI specs and Swagger UI for ...
Using docstrings as specification · Using external YAML files · Using dictionaries as raw specs · Using Marshmallow Schemas · Using Flask RESTful...
Read more >
Python REST APIs With Flask, Connexion, and SQLAlchemy
This tutorial series is a hand-on guide on how to create a REST API with Flask and interact with it using CRUD operations....
Read more >
Working with APIs using Flask, Flask-RESTPlus and Swagger UI
I defined the application as a flask application using the method Flask() which sets the name using __name__ . Next, I'll used Api...
Read more >
README.md · Flasgger/flasgger - Gitee.com
Getting started · Using docstrings as specification · Using external YAML files · Using dictionaries as raw specs · Using Marshmallow Schemas ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found