Exemplo n.º 1
0
Arquivo: _route.py Projeto: so1n/pait
 def openapi_route(request: Request) -> JSONResponse:
     _get_request_pin_code(request)
     pait_dict: Dict[str, PaitCoreModel] = load_app(request.app)
     pait_openapi: PaitOpenApi = PaitOpenApi(
         pait_dict,
         title=title,
         open_api_server_list=[{
             "url": f"http://{request.url.hostname}:{request.url.port}",
             "description": ""
         }],
         open_api_tag_list=open_api_tag_list,
     )
     return JSONResponse(pait_openapi.open_api_dict)
Exemplo n.º 2
0
Arquivo: _route.py Projeto: so1n/pait
 def openapi_route() -> dict:
     _get_request_pin_code()
     pait_dict: Dict[str, PaitCoreModel] = load_app(current_app)
     pait_openapi: PaitOpenApi = PaitOpenApi(
         pait_dict,
         title=title,
         open_api_server_list=[{
             "url": f"http://{request.host}",
             "description": ""
         }],
         open_api_tag_list=open_api_tag_list,
     )
     return pait_openapi.open_api_dict
Exemplo n.º 3
0
 async def get(self) -> None:
     self._get_request_pin_code()
     pait_dict: Dict[str, PaitCoreModel] = load_app(self.application)
     pait_openapi: PaitOpenApi = PaitOpenApi(
         pait_dict,
         title=title,
         open_api_server_list=[{
             "url": f"http://{self.request.host}",
             "description": ""
         }],
         open_api_tag_list=open_api_tag_list,
     )
     self.write(pait_openapi.open_api_dict)
Exemplo n.º 4
0
from typing import Dict

from example.param_verify.sanic_example import create_app
from pait.api_doc.markdown import PaitMd
from pait.api_doc.open_api import PaitOpenApi
from pait.app import load_app
from pait.model.core import PaitCoreModel

if __name__ == "__main__":
    filename: str = "./example_doc/sanic"
    pait_dict: Dict[str, PaitCoreModel] = load_app(create_app())
    PaitMd(pait_dict, use_html_details=True).output(filename)
    for i in ("json", "yaml"):
        PaitOpenApi(
            pait_dict,
            title="Pait Doc",
            open_api_tag_list=[
                {
                    "name": "test",
                    "description": "test api"
                },
                {
                    "name": "user",
                    "description": "user api"
                },
            ],
            type_=i,
        ).output(filename + "_openapi")
Exemplo n.º 5
0
Arquivo: cli.py Projeto: so1n/pait
def main() -> None:
    output_type_list: List[str] = ["md", "openapi_json", "openapi_yaml"]
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "app",
        help=
        "Enter the file name and app name of the app that needs to generate the document,"
        " for example:app stands for. /example.py app",
    )
    parser.add_argument("-o",
                        "--output_type",
                        help=f"now support: {','.join(output_type_list)}")
    parser.add_argument("-t",
                        "--title",
                        help="Title of doc",
                        default="Pait Doc")
    parser.add_argument("-f",
                        "--filename",
                        help="Name of save file",
                        default=None)
    parser.add_argument("-u",
                        "--use_html_details",
                        help="Whether to output html text in the md document",
                        default=True,
                        type=bool)
    parser.add_argument("-i",
                        "--indent",
                        help="json formatted output of indent values",
                        default=2,
                        type=int)

    args, unknown = parser.parse_known_args()

    module_name, app_name = args.app.split(":")
    input_output_type_list: List[str] = [
        i for i in args.output_type.split(",") if i in output_type_list
    ]
    title: str = args.title
    filename: Optional[str] = args.filename
    use_html_details: bool = args.use_html_details
    indent: int = args.indent

    module = importlib.import_module(module_name)
    app = getattr(module, app_name, None)
    if not app:
        raise ImportError(f"Can't found {app} in {module}")
    if inspect.isfunction(app):
        app = app()
    pait_dict: Dict[str, PaitCoreModel] = load_app(app)

    for type_ in input_output_type_list:
        if type_ == "md":
            PaitMd(pait_dict, title=title,
                   use_html_details=use_html_details).output(filename)
        elif type_ == "openapi_json":
            PaitOpenApi(pait_dict, title=title, type_="json").output(filename)
        elif type_ == "openapi_yaml":
            PaitOpenApi(pait_dict, title=title, type_="yaml").output(filename)
        else:
            raise ValueError(
                f"Not support output type: {type_}, please select from the following options"
            )