Skip to content

Commit

Permalink
Enabling hidden APIs in flask-rebar (plangrid#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
alidscott authored Aug 21, 2020
1 parent d56e688 commit 3cce2d6
Show file tree
Hide file tree
Showing 6 changed files with 713 additions and 1 deletion.
8 changes: 8 additions & 0 deletions flask_rebar/rebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class PathDefinition(
"authenticators",
"tags",
"mimetype",
"hidden",
],
)
):
Expand Down Expand Up @@ -410,6 +411,7 @@ def paths(self):
authenticators=definition_.authenticators,
tags=definition_.tags,
mimetype=definition_.mimetype,
hidden=definition_.hidden,
)

return paths
Expand All @@ -435,6 +437,7 @@ def add_handler(
authenticators=USE_DEFAULT,
tags=None,
mimetype=USE_DEFAULT,
hidden=False,
):
"""
Registers a function as a request handler.
Expand Down Expand Up @@ -464,6 +467,8 @@ def add_handler(
Arbitrary strings to tag the handler with. These will translate to Swagger operation tags.
:param Type[USE_DEFAULT]|None|str mimetype:
Content-Type header to add to the response schema
:param bool hidden:
if hidden, documentation is not created for this request handler by default
"""
# Fix #115: if we were passed bare classes we'll go ahead and instantiate
headers_schema = normalize_schema(headers_schema)
Expand Down Expand Up @@ -497,6 +502,7 @@ def add_handler(
authenticators=authenticators,
tags=tags,
mimetype=mimetype,
hidden=hidden,
)

@deprecated_parameters(
Expand All @@ -519,6 +525,7 @@ def handles(
authenticators=USE_DEFAULT,
tags=None,
mimetype=USE_DEFAULT,
hidden=False,
):
"""
Same arguments as :meth:`HandlerRegistry.add_handler`, except this can
Expand All @@ -538,6 +545,7 @@ def wrapper(f):
authenticators=authenticators,
tags=tags,
mimetype=mimetype,
hidden=hidden,
)
return f

Expand Down
2 changes: 2 additions & 0 deletions flask_rebar/swagger_generation/swagger_generator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def __init__(
response_converter_registry=None,
default_response_schema=Error(),
authenticator_converter_registry=None,
include_hidden=False,
):
self.include_hidden = include_hidden
self.title = title
self.version = version
self.description = description
Expand Down
8 changes: 8 additions & 0 deletions flask_rebar/swagger_generation/swagger_generator_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def __init__(
servers=None,
default_response_schema=Error(),
authenticator_converter_registry=None,
include_hidden=False,
):

super(SwaggerV3Generator, self).__init__(
openapi_major_version=3,
version=version,
Expand All @@ -76,6 +78,7 @@ def __init__(
headers_converter_registry=headers_converter_registry,
response_converter_registry=response_converter_registry,
authenticator_converter_registry=authenticator_converter_registry,
include_hidden=include_hidden,
)
self.tags = tags
self.servers = servers
Expand Down Expand Up @@ -139,6 +142,11 @@ def _get_paths(self, paths, default_headers_schema, default_security=None):
for path, methods in paths.items():
swagger_path, path_args = format_path_for_swagger(path)

if not self.include_hidden and all(
d.hidden for method, d in methods.items()
):
continue

# Different Flask paths might correspond to the same Swagger path
# because of Flask URL path converters. In this case, let's just
# work off the same path definitions.
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"bumpversion==0.5.3",
"gitchangelog>=3.0.4,<4.0.0",
"pre-commit>=1.14.4",
"pyyaml",
]

if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 3cce2d6

Please sign in to comment.