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 20f0f2d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 24 deletions.
45 changes: 30 additions & 15 deletions aiopenapi3/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,37 @@ 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):
"""
loaded(text) -> parsed(dict)
"""

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

"""
loaded(text) -> parsed(dict)
"""
"""available in :func:`~aiopenapi3.plugin.Document.loaded` :func:`~aiopenapi3.plugin.Document.parsed`"""

def loaded(self, ctx: "Document.Context") -> "Document.Context": # pragma: no cover
"""modify the text before parsing"""
Expand All @@ -64,24 +72,34 @@ 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
"""available :func:`~aiopenapi3.plugin.Message.marshalled` """
sending: Optional[str] = None
"""available :func:`~aiopenapi3.plugin.Message.sending` """
received: Optional[bytes] = None
"""available :func:`~aiopenapi3.plugin.Message.received` """
headers: "httpx.Headers" = None
"""available :func:`~aiopenapi3.plugin.Message.sending` :func:`~aiopenapi3.plugin.Message.received` """
status_code: Optional[str] = None
"""available :func:`~aiopenapi3.plugin.Message.received` """
content_type: Optional[str] = None
"""available :func:`~aiopenapi3.plugin.Message.received` """
parsed: Optional[Dict[str, Any]] = None
unmarshalled: Optional[BaseModel] = None
"""available :func:`~aiopenapi3.plugin.Message.parsed` """
expected_type: Optional[typing.Type] = None

"""
sending: marshalled(dict)-> sending(str)
receiving: received -> parsed -> unmarshalled
"""
"""available :func:`~aiopenapi3.plugin.Message.parsed` """
unmarshalled: Optional[BaseModel] = None
"""available :func:`~aiopenapi3.plugin.Message.unmarshalled` """

def marshalled(self, ctx: "Message.Context") -> "Message.Context": # pragma: no cover
"""
Expand All @@ -95,9 +113,6 @@ def sending(self, ctx: "Message.Context") -> "Message.Context": # pragma: no co
"""
pass

def _prepared(self, ctx: "Message.Context") -> "Message.Context": # pragma: no cover
pass

def received(self, ctx: "Message.Context") -> "Message.Context": # pragma: no cover
"""
modify the received text
Expand Down
9 changes: 5 additions & 4 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,18 @@ Init plugins are used to signal the setup is done.

.. currentmodule:: aiopenapi3.plugin
.. autoclass:: aiopenapi3.plugin::Init.Context
:members:
:members: schemas, paths, initialized

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

Document Plugins
----------------

Document plugins are used to mangle description documents.

.. autoclass:: aiopenapi3.plugin::Document.Context
:members:
:members: url, document

.. autoclass:: Document
:members: loaded, parsed
Expand All @@ -100,10 +101,10 @@ Message Plugins
Message plugins are used to mangle message.

.. autoclass:: aiopenapi3.plugin::Message.Context
:members:
:members: operationId, marshalled, sending, received, headers, status_code, content_type, parsed, expected_type, unmarshalled

.. autoclass:: Message
:members: marshalled, parsed, received, sending, unmarshalled
:members: marshalled, sending, received, parsed, unmarshalled

Loader
======
Expand Down
18 changes: 13 additions & 5 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 All @@ -71,11 +76,14 @@ def linkcode_resolve(domain, info):
return None

# Path("…/aiopenapi3/__init__.py").parent.parent == "…"
libdir = Path(mod.__file__).parent.parent
file = Path(file).relative_to(libdir)
libdir = Path(mod.__file__).parent
while libdir.name != "aiopenapi3":
libdir = libdir.parent
libdir = libdir.parent
linkcode_file = Path(file).relative_to(libdir)
start, end = lines[1], lines[1] + len(lines[0]) - 1

return f"{linkcode_url}/{file}#L{start}-L{end}"
return f"{linkcode_url}/{linkcode_file}?file={file}&mod={mod.__file__}#L{start}-L{end}"


templates_path = ["_templates"]
Expand Down

0 comments on commit 20f0f2d

Please sign in to comment.