Open franfabrizio opened 6 years ago
I am also getting this error. I'm reproducing the example from the docs here.
I never got that example or anything close to it working. What I ended up doing is actually putting an endpoint into my project to expose it. It looks like this:
@api.route('/')
class Spec(Resource):
def get(self):
from apis import api
return api.__schema__
Pretty sure this is a total hack but it's the only way we could think of for it to work.
That's what I resorted to as well
The below works for me.
from myapp import api
import json
with app.test_request_context():
print(json.dumps(api.__schema__, sort_keys=True, indent=4, separators=(',', ': ')))
The code of the module will be
version = "1.0.0"
blueprint = Blueprint('api', __name__, url_prefix='/api/1')
api = Api(blueprint,version=version, title='My API',
description='My API description')
api.add_namespace(namespace1)
api.add_namespace(namespace2)
api.add_namespace(namespace3)
app.register_blueprint(blueprint)
Here's the script I've used to work around it:
from app import api, app
app.config["SERVER_NAME"] = "localhost"
app.app_context().__enter__()
import json
print(json.dumps(api.__schema__, indent=2))
Flask newbie here. I'm trying to follow the documentation to export the Swagger specification for my app. Docs say to do this:
My app is structured like this:
bibapi/ --bibapi.py --exportspec.py #script I'm trying to run --apis/ ----__init__.py #defines api
but when I run exportspec.py, which looks like:
I get:
Googling that RuntimeError says that you cannot generate URLs without application context. I came across a solution that showed how you can provide a minimum application context for Flask to work:
When I run that I get:
I've been banging my head on this one for a while now. What am I doing wrong?
Thanks, Fran