-
Notifications
You must be signed in to change notification settings - Fork 73
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
Custom docstring ignore tag #72
Custom docstring ignore tag #72
Conversation
Thanks for the PR. Code looks good. Regarding the test, I'd prefer a minimalist test that tests each case (explicit |
flask_rest_api/blueprint.py
Outdated
@@ -61,6 +61,7 @@ class Blueprint( | |||
def __init__(self, *args, **kwargs): | |||
|
|||
self.description = kwargs.pop('description', '') | |||
self.docstring_sep = kwargs.pop('docstring_sep', '---') |
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 where you were thinking of adding the arg?
- Where are the docs for the Blueprint so that I can add it there?
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 was thinking of making it a class attribute the user could override in a subclass, like HTTP_METHODS
.
class Blueprint:
DOCSTRING_SEP = '---'
I'd document this in docs/openapi.rst.
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.
Do you still want me to move it to a class attribute rather than (or in addition to) an initialization arg?
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.
Class attribute only would be consistent with the rest of the lib.
The separator will most probably be something the user will use consistently in all his Blueprint
s so subclassing and using a class attribute seems nice to me.
description
is obviously different because it differs in all instances.
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.
Sounds good. I added it as a class attribute.
I also left the initialization arg so that users can do any of these:
# No need to subclass
blp0 = Blueprint('test', __name__, url_prefix='test', docstring_sep="~~~")
# But you can if you want to
class MyBlueprint(Blueprint):
DOCSTRING_SEP = "~~~"
blp1 = MyBlueprint('test', __name__, url_prefix='test')
# and you can still override your subclass on a per-instance bases if desired.
blp2 = MyBlueprint('test', __name__, url_prefix='test', docstring_sep="^^^")
If that's not to your liking please let me know and I'll remove the init arg completely.
OK, I'll change that. Do you want to keep everything in that single test case with multiple asserts? Or would you rather a new test function for each? Eg: def test_load_from_docstring_default_sep():
def test_load_from_docstring_custom_sep():
def test_load_from_docstring_none_sep(): Other questions:
|
flask_rest_api/blueprint.py
Outdated
@@ -136,12 +139,12 @@ def store_method_docs(method, function): | |||
for method in self.HTTP_METHODS: | |||
if method in obj.methods: | |||
func = getattr(obj, method.lower()) | |||
store_method_docs(method, func) | |||
store_method_docs(method, func, sep=self.docstring_sep) |
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.
Can't you access self.docstring_sep
in store_method_docs
itself?
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, at least not with the base I'm working from. store_method_docs
is defined within Blueprint._store_endpoint_docs
and does not accept the instance as an arg.
My current base is a1c2dfc, v0.15.0.
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'm not familiar with closures. I thought self
would be accessible since it is defined in the scope of Blueprint._store_endpoint_docs
where store_method_docs
is defined.
Currently out of office, I'll try to check this and the rest when I come back.
I don't really mind. But thanks for asking.
That's perfect.
Don't bother. I can do it. I generally don't create an "unreleased" section. I just add the next version when needed.
I think updating relevant section in docs/openapi.rst (https://github.com/Nobatek/flask-rest-api/blob/master/docs/openapi.rst#add-summary-and-description) is enough. Thanks. Sorry for the delay... |
Rebased, squashed (perhaps a little too much) and reworked. Let's merge. |
This allows the user to customize the docstring ignore separator.
The custom separator is set during blueprint initialization:
Fixes #49.