-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
719 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""One-line description for README and other doc files.""" | ||
|
||
__version__ = '0.9.19' | ||
__version__ = '0.9.20' |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Helpers for generating Swagger documentation for the FutureX Open edX Extensions API.""" | ||
from __future__ import annotations | ||
|
||
import copy | ||
from typing import Any, Callable | ||
|
||
from edx_api_doc_tools import schema, schema_for | ||
|
||
from futurex_openedx_extensions.dashboard.docs_src import docs_src | ||
|
||
|
||
def docs(class_method_name: str) -> Callable: | ||
""" | ||
Decorator to add documentation to a class method. | ||
:param class_method_name: The name of the class method. | ||
:type class_method_name | ||
:return: The documentation for the class method. | ||
:rtype: dict | ||
""" | ||
def _schema(view_func: Any) -> Any: | ||
"""Decorate a view class with the specified schema.""" | ||
if not callable(view_func): | ||
raise ValueError( | ||
f'docs decorator must be applied to a callable function or class. Got: {view_func.__class__.__name__}' | ||
) | ||
|
||
try: | ||
docs_copy = copy.deepcopy(docs_src[class_method_name]) | ||
except KeyError as error: | ||
raise ValueError(f'docs_utils Error: no documentation found for {class_method_name}') from error | ||
|
||
if view_func.__class__.__name__ == 'function': | ||
return schema(**docs_src[class_method_name])(view_func) | ||
|
||
method_name = class_method_name.split('.')[1] | ||
docstring = docs_copy.pop('summary', '') + '\n' + docs_copy.pop('description', '') # type: ignore | ||
if docstring == '\n': | ||
docstring = None | ||
return schema_for( | ||
method_name, | ||
docstring=docstring, | ||
**docs_copy | ||
)(view_func) | ||
|
||
return _schema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.