flask-react-spa
flask-react-spa copied to clipboard
Integratting with Swagger/OpenAPI
Has anyone had success integrating this with one Swagger/OpenAPI? I keep getting:
| File "/flask/venv/lib/python3.9/site-packages/flask_restful_swagger/swagger.py", line 329, in extract_operations backend_1 | for method in [m.lower() for m in resource.methods]: backend_1 | TypeError: 'NoneType' object is not iterable
When trying to bring this up with the normal pattern. Any tips or success with this? Mk...
Can you share any more code around how you've tried setting this up? The error suggests that the view class being passed in does not have its methods
attribute set correctly (it should be a list of HTTP methods, eg GET, POST, PUT, etc), but that's really all I can see from the error
The code we are trying to insert to get Swagger/OpenAPI up is:
extensions.py
from flask_restful_swagger import swagger from backend.api import Api
api = swagger.docs( Api('api', prefix='/api/v1'), apiVersion="0.1", basePath="http://localhost:5000", resourcePath="/", produces=["application/json", "text/html"], api_spec_url="/api/spec", description="API", )
Apologize more for not sharing more before, I was seeing if anyone has any working examples of integrating this with flask-react-spa. Thanks @briancappello
Ah okay hmm this maybe won't be super straight forward to integrate... the api
extension is initialized in backend/extensions/api.py
(which is where I'd try adding the swagger.docs(Api(...))
code), but this project customizes the flask_restful.Api
extension class to improve integration with flask-marshmallow serializers (see backend/api/extension.py
). So even though it's built with flask-restful, it's not a stock implementation any more, and that may (or may not?) interfere with this swagger extension. At first glance it's not obvious to me how you're supposed to use flask-restful-swagger in conjunction with the application factory pattern (which this project uses) so that may be a roadblock on its own.
That's kinda what I thought given the pattern. I'll keep this up here in case anyone has any ideas on how to get swagger up with this framework pattern. It's usually super easy to do and that's why I kinda hit a wall with it. Looking for alternatives too outside of flask-restful-swagger. Thanks for any additoinal thought. Really like your implementation otheriwse.