Skip to content

Commit

Permalink
plugin - docs
Browse files Browse the repository at this point in the history
  • Loading branch information
commonism committed Aug 9, 2023
1 parent ea99efb commit d70f4d9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
24 changes: 17 additions & 7 deletions aiopenapi3/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,33 @@ def api(self, v):
class Init(Plugin):
@dataclasses.dataclass
class Context:
initialized: "OpenAPI" = None
initialized: "aiopenapi3.OpenAPI" = None
"""available in :func:`~aiopenapi3.plugin.Init.initialized`"""
schemas: Dict[str, "Schema"] = None
"""available in :func:`~aiopenapi3.plugin.Init.schemas`"""
paths: Dict[str, "PathItemBase"] = None
"""available in :func:`~aiopenapi3.plugin.Init.paths`"""

def schemas(self, ctx: "Init.Context") -> "Init.Context": # pragma: no cover
"""modify the Schema before creating Models"""
pass

def paths(self, ctx: "Init.Context") -> "Init.Context": # pragma: no cover
"""modify the paths/PathItems before initializing the Operations"""
pass

def initialized(self, ctx: "Init.Context") -> "Init.Context": # pragma: no cover
"""it is initialized"""
pass


class Document(Plugin):
@dataclasses.dataclass
class Context:
url: yarl.URL
"""available in :func:`~aiopenapi3.plugin.Document.loaded` :func:`~aiopenapi3.plugin.Document.parsed`"""
document: Dict[str, Any]
"""available in :func:`~aiopenapi3.plugin.Document.loaded` :func:`~aiopenapi3.plugin.Document.parsed`"""

"""
loaded(text) -> parsed(dict)
Expand All @@ -64,25 +72,27 @@ def parsed(self, ctx: "Document.Context") -> "Document.Context": # pragma: no c


class Message(Plugin):
"""
sending: marshalled(dict)-> sending(str)
receiving: received -> parsed -> unmarshalled
"""

@dataclasses.dataclass
class Context:
operationId: str
"""available :func:`~aiopenapi3.plugin.Message.marshalled` :func:`~aiopenapi3.plugin.Message.sending` :func:`~aiopenapi3.plugin.Message.received` :func:`~aiopenapi3.plugin.Message.parsed` :func:`~aiopenapi3.plugin.Message.unmarshalled`"""
marshalled: Optional[Dict[str, Any]] = None
sending: Optional[str] = None
received: Optional[bytes] = None
headers: "httpx.Headers" = None
"""available :func:`~aiopenapi3.plugin.Message.sending` :func:`~aiopenapi3.plugin.Message.received` """
status_code: Optional[str] = None
content_type: Optional[str] = None
parsed: Optional[Dict[str, Any]] = None
unmarshalled: Optional[BaseModel] = None
expected_type: Optional[typing.Type] = None

"""
sending: marshalled(dict)-> sending(str)
receiving: received -> parsed -> unmarshalled
"""

def marshalled(self, ctx: "Message.Context") -> "Message.Context": # pragma: no cover
"""
modify the dict before sending
Expand Down
1 change: 1 addition & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Init plugins are used to signal the setup is done.
:members:

.. autoclass:: Init
:members: schemas, paths, initialized

Document Plugins
----------------
Expand Down
9 changes: 7 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ def linkcode_resolve(domain, info):

mod = importlib.import_module(info["module"])
if "." in info["fullname"]:
objname, attrname = info["fullname"].split(".")
obj = getattr(mod, objname)
*objname, attrname = info["fullname"].split(".")
obj = mod
try:
for i in objname:
obj = getattr(obj, i)
except AttributeError:
return None
try:
# object is a method of a class
obj = getattr(obj, attrname)
Expand Down

0 comments on commit d70f4d9

Please sign in to comment.