-
Notifications
You must be signed in to change notification settings - Fork 515
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
Add "ParsedMethodView" and example #222
Add "ParsedMethodView" and example #222
Conversation
This is a great improvement, I'll try to test and review by this weekend! If you can also take a look @javabrett :) |
I Like the implementation with the But I also think we can provide the same functionality for when only function based views are used, and also when no viewa at all are used. (this would address the issues #202 and #216 Example:
Then we just parse the YAML and generate the swagger UI even without having any view defined. |
Thanks your suggestion, you are right, I will update this PR soon |
222caa6
to
eb3c622
Compare
@rochacbruno You can review this PR now, the base idea is same with earlier "ParseMethodView", but it has more applicability:
Any suggestions or criticisms are welcome |
@strongbugman this is awesome! I'll review ASAP! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is fairly current, but please rebase to current master
for final review.
From http://localhost:5000/parsed_view_func/apidocs/#/item/get_api_items__id__ I' I'm getting this error:
Errors
Hide
Resolver error at paths./api/items/{id}/.get.responses.200.schema.$ref
Could not resolve reference because of: Could not resolve pointer: /definitions/item does not exist in document
examples/parsed_view_func.py
Outdated
@@ -0,0 +1,170 @@ | |||
""" | |||
Example of auto load doc file by endpoint name(view function/method name), | |||
parse by flask_restful.reqparse.RequestParser and validate by jsonschema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/parse/parsed
s/validate/validated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
examples/parsed_view_func.py
Outdated
from flasgger import Swagger | ||
|
||
|
||
_TEST_META_SKIP_FULL_VALIDATION = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this active/needed, what does it do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it should be removed
examples/parsed_view_func.py
Outdated
def get(self): | ||
""" | ||
If we set "parse" is True in Flasgger app, we will get parsed and | ||
validate data store in "flask.request". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/validate/validated
s/store/stored
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
examples/parsed_view_func.py
Outdated
If we set "parse" is True in Flasgger app, we will get parsed and | ||
validate data store in "flask.request". | ||
|
||
Different location`s var store in different key, eg: key "args" store |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe ` -> ' here?
eb3c622
to
6509cfb
Compare
@javabrett Thx for your review, I fixed the errors and rebased the origin/master |
Changes look good, 🍰 . I don't think your rebase picked up the latest master but never mind - you might have forgotten to |
6509cfb
to
76466c0
Compare
@javabrett Yes you are right, I forgot to fetch upstream😅, now it's rebased |
@strongbugman awesome! @javabrett first, thanks for the awesome contribution to Flasgger reviewing and helping maintaining this project ✨ @javabrett I am with little time this week to review OSS projects (due to work + FlaskConf which is this weekend). So I would like to ask if you can take care of this PR! this is awesome improvement and I do not want to hold it. As long as the code is good, working and we have some kind of doc (readme) about how to use it please decide if you want to merge it or request more changes! I'll let this one for you to review/merge! :) thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@strongbugman I don't have large blocks of time to work on the review at the moment, so hopefully you can live with my incremental suggestions :).
Left a comment on the auth in the example below.
examples/parsed_view_func.py
Outdated
400: | ||
description: Miss name or code | ||
""" | ||
if request.parsed_data['json']['data']['password'] != 'test': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding this, and related auth
bits - I'm just wondering whether this is an essential part of the example code, or whether is it orthogonal and potentially confusing.
With the password, I had to check the example source to find it. It also seems a bit irregular auth passing the credentials with the data payload.
If auth is integral to the example, fine let's keep it, but if it is unnecessary and orthogonal, maybe we can have auth in other examples but not here. Thoughts?
When you next rebase you'll pick up the new Dockerfile which can be useful for testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example is a test about nest json body and variable route rule without converter, but the "auth" feature is unnecessary, so I`ll change the example
examples/parsed_view_func.py
Outdated
|
||
app = Flask(__name__) | ||
app.config['SWAGGER'] = { | ||
'title': 'Flasgger ParsedMethodView Example', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding ParsedMethodView
(three mentions, appears in UI) - on first seeing this in camel-case, I wondered if it was going to be a subclass of Flask MethodView
, but it's not, it's just a name used in the example. So maybe "Flasgger Parsed MethodView Example" might be better?
flasgger/base.py
Outdated
# "static_folder": "static", # must be set by user | ||
"swagger_ui": True, | ||
"specs_route": "/apidocs/", | ||
"doc_dir": "./docs/api/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc-parsing is new and presumably optional and opt-in, but doc_dir
is being set in the DEFAULT_CONFIG
here. As a result all existing examples are passing through the new code in get_specs
, and the doc_dir=None
is not having any effect.
So I guess I'm checking whether it is really intended to set this as a default here. If not, and especially if all other options are mentioned here, it might be OK to leave it commented per static_folder
.
If the intention is to make this new feature default-on with some default path to the docs, then the parse
option would need review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc auto loading is a optional feature, although it won't affect flasgger's other feature if there is no ./docs/api
in local directory, for more clearly, I'll remove the doc_dir
config in DEFAULT_CONFIG
76466c0
to
45f1893
Compare
@javabrett Thx for your suggestions and patience, I changed the code according to your suggestions |
request with documented
45f1893
to
be670d6
Compare
Thanks @strongbugman for this contribution! 🍰 |
#220
@rochacbruno I don't kwon if the file/class name/structure is suitable, feel free to tell me if I'm wrong.