Skip to content
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 option to exclude OPTIONS requests #123

Merged
merged 3 commits into from
May 25, 2020

Conversation

Brcrwilliams
Copy link
Contributor

@Brcrwilliams Brcrwilliams commented Oct 21, 2018

Fixes #111.
See #112 for prior discussion.

These changes add a new optional parameter called document_options to the FlaskApiSpec constructor that will exclude OPTIONS requests from the swagger specification if set to False.

Flask automatically generates OPTIONS requests for each route. There are cases, such as when using CORS, where one would want these OPTIONS requests to be generated but do not want to have them in their swagger docs.

My line of reasoning for wanting to exclude these is: My API users will never explicitly make an OPTIONS request. The browser will automatically send a pre-flight OPTIONS request when making a cross-origin request, and I want to have OPTIONS endpoints in order to support that, but I don't want to have this functionality adding a bunch of endpoints to my swagger docs which will largely be ignored by users.

These changes add a new optional parameter called `document_options`
to the FlaskApiSpec constructor that will exclude OPTIONS requests
from the swagger specification if set to `False`.

Flask automatically generates OPTIONS requests for each route. There are
cases, such as when using CORS, where one would want these OPTIONS
requests to be generated but do not want to have them in their swagger
docs.

My line of reasoning for wanting to exclude these is: My API users
will never explicitly make an OPTIONS request. The browser will
automatically send a pre-flight OPTIONS request when making a
cross-origin request, and I want to have OPTIONS endpoints in order
to support that, but I don't want to have this functionality adding
a bunch of endpoints to my swagger docs which will largely be ignored
by users.
@codecov-io
Copy link

Codecov Report

Merging #123 into master will decrease coverage by 0.25%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #123      +/-   ##
==========================================
- Coverage   97.64%   97.38%   -0.26%     
==========================================
  Files           8        8              
  Lines         339      344       +5     
==========================================
+ Hits          331      335       +4     
- Misses          8        9       +1
Impacted Files Coverage Δ
flask_apispec/extension.py 100% <100%> (ø) ⬆️
flask_apispec/apidoc.py 95.83% <80%> (-1.23%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 535fc9d...203800d. Read the comment docs.

Copy link

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like APISPEC_SPEC is set as a config option, maybe FlaskApiSpec.document_options should be as well? Otherwise it looks good to me, hope it'll get merged 👍

@rocconnick
Copy link

This would be handy for me right now. Thanks for working on it.

@alexbaileyuk
Copy link

Without meaning to drag up old issues, did this ever get anywhere? It looks to me like it wasn't implemented but I would say it's useful for many users who do not conciously need to make use of pre-flight/

@codecov-commenter
Copy link

codecov-commenter commented May 25, 2020

Codecov Report

Merging #123 into master will decrease coverage by 0.23%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #123      +/-   ##
==========================================
- Coverage   97.82%   97.58%   -0.24%     
==========================================
  Files           8        8              
  Lines         367      372       +5     
==========================================
+ Hits          359      363       +4     
- Misses          8        9       +1     
Impacted Files Coverage Δ
flask_apispec/apidoc.py 96.20% <80.00%> (-1.14%) ⬇️
flask_apispec/extension.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ec30f52...7a27abf. Read the comment docs.

@sloria sloria merged commit 1296885 into jmcarp:master May 25, 2020
@sloria
Copy link
Collaborator

sloria commented May 25, 2020

Sorry for the long delay on this. This is released in 0.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Swagger auto generate the OPTIONS method
7 participants