-
Notifications
You must be signed in to change notification settings - Fork 338
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
@api.expect and @api.response decorators don't consistently handle documentation of pre-defined Model from string name #56
Comments
I was able to reproduce the issue. The two paths generate their docs in different manners, apparently.
however
the easiest workaround is to always reference your namespace APIs, Keeping your code exactly the same, set up your route as follows:
It's definitely strange that the different types of documentation can take different paths to completion. I'll write a separate comment specifying the root cause. However, please use the above workaround so you don't have to have an extra method. Also, this will work per |
Summary -- I suggest the following:
|
Code
I'm trying to organize my code so that model definitions are shared, in order to reduce clutter, and so that pure API logic ends up in its own files. Here's the structure that I've got right now.
In
app.py
(the entry point):In
api/__init__.py
:In
api/models.py
:In
api/demo.py
:Repro Steps (if applicable)
model
parameter in theapi.response
decorator to[Model('My Cool Model')]
.Expected Behavior
Constructing a model object should work the same in both places; if constructing an already-defined model object works for the api.expect decorator, it should also work for the api.response decorator, and vice versa.
Actual Behavior
With the above code, the model will properly render in the documentation for the api.expect decorator, but it will not render for the api.response decorator. However, changing the model parameter in the api.response decorator from
Model('My Cool Model')
to[Model('My Cool Model')]
(i.e. encapsulating it in a list) causes it to render. This is fine for when I want my defined API to produce a list of objects, but not so good for when I want my defined API to produce a single object.Environment
Running the python3.7-slim docker image, exact version is below:
Additional Context
My current workaround is to include a
make_model
function in theapi/models.py
file:This function can then be imported and called in
api/demo.py
as follows, and produces the expected result in the documentation:The text was updated successfully, but these errors were encountered: