Compare commits

...

3 Commits

Author SHA1 Message Date
Joe Korbel 957b4b125e Update openapi.rst (#327)
Minor typo on "because"
2019-03-08 18:24:55 +02:00
Cristi Vîjdea a59f632516 Add OAS 3 types
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md
2018-09-16 18:47:55 +03:00
Cristi Vîjdea 20786e53c3 Provide more OpenAPISchemaGenerator extension points
Add ``should_include_endpoint`` and ``get_paths_object``.
2018-09-13 05:51:34 +03:00
4 changed files with 1036 additions and 8 deletions
-5
View File
@@ -55,11 +55,6 @@
</option>
</inspection_tool>
<inspection_tool class="PyShadowingNamesInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PyUnusedLocalInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false">
<option name="ignoreTupleUnpacking" value="true" />
<option name="ignoreLambdaParameters" value="true" />
<option name="ignoreLoopIterationVariables" value="true" />
</inspection_tool>
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="true" />
<option name="processLiterals" value="true" />
+1 -1
View File
@@ -14,7 +14,7 @@ This library generates OpenAPI 2.0 documents. The authoritative specification fo
be the official documentation over at `swagger.io <https://swagger.io/>`__ and the `OpenAPI 2.0 specification
page <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md>`__.
Beause the above specifications are a bit heavy and convoluted, here is a general overview of how the specification
Because the above specifications are a bit heavy and convoluted, here is a general overview of how the specification
is structured, starting from the root ``Swagger`` object.
* :class:`.Swagger` object
+23 -2
View File
@@ -311,6 +311,27 @@ class OpenAPISchemaGenerator(object):
"""
return self._gen.determine_path_prefix(paths)
def should_include_endpoint(self, path, method, view, public):
"""Check if a given endpoint should be included in the resulting schema.
:param str path: request path
:param str method: http request method
:param view: instantiated view callback
:param bool public: if True, all endpoints are included regardless of access through `request`
:returns: true if the view should be excluded
:rtype: bool
"""
return public or self._gen.has_view_permissions(path, method, view)
def get_paths_object(self, paths):
"""Construct the Swagger Paths object.
:param OrderedDict[str,openapi.PathItem] paths: mapping of paths to :class:`.PathItem` objects
:returns: the :class:`.Paths` object
:rtype: openapi.Paths
"""
return openapi.Paths(paths=paths)
def get_paths(self, endpoints, components, request, public):
"""Generate the Swagger Paths for the API from the given endpoints.
@@ -331,7 +352,7 @@ class OpenAPISchemaGenerator(object):
for path, (view_cls, methods) in sorted(endpoints.items()):
operations = {}
for method, view in methods:
if not public and not self._gen.has_view_permissions(path, method, view):
if not self.should_include_endpoint(path, method, view, public):
continue
operation = self.get_operation(view, path, prefix, method, components, request)
@@ -346,7 +367,7 @@ class OpenAPISchemaGenerator(object):
path_suffix = '/' + path_suffix
paths[path_suffix] = self.get_path_item(path, view_cls, operations)
return openapi.Paths(paths=paths), prefix
return self.get_paths_object(paths), prefix
def get_operation(self, view, path, prefix, method, components, request):
"""Get an :class:`.Operation` for the given API endpoint (path, method). This method delegates to
File diff suppressed because it is too large Load Diff