Skip to content

Commit

Permalink
use docstring as summary
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSanal committed Jul 17, 2024
1 parent f67a2d6 commit f8d4854
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
30 changes: 11 additions & 19 deletions robyn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import inspect
import json
import logging
import os
Expand Down Expand Up @@ -106,7 +107,7 @@ def json_handler():
self.add_route(route_type=HttpMethod.GET, endpoint="/openapi.json", handler=json_handler, is_const=False)
self.add_route(route_type=HttpMethod.GET, endpoint="/docs", handler=docs_handler, is_const=False)

def add_path_obj(self, route_type, endpoint, openapi_summary, openapi_tags):
def add_openapi_path_obj(self, route_type, endpoint, openapi_summary, openapi_tags):
modified_endpoint, path_obj = get_path_obj(endpoint, openapi_summary, openapi_tags)

if modified_endpoint not in self.openapi_schema["paths"]:
Expand Down Expand Up @@ -337,7 +338,6 @@ def get(
endpoint: str,
const: bool = False,
auth_required: bool = False,
openapi_summary: str = "",
openapi_tags: list = ["default"],
):
"""
Expand All @@ -347,7 +347,7 @@ def get(
"""

def inner(handler):
self.add_path_obj("get", endpoint, openapi_summary, openapi_tags)
self.add_openapi_path_obj("get", endpoint, inspect.getdoc(handler), openapi_tags)

return self.add_route(HttpMethod.GET, endpoint, handler, const, auth_required)

Expand All @@ -357,7 +357,6 @@ def post(
self,
endpoint: str,
auth_required: bool = False,
openapi_summary: str = "",
openapi_tags: list = ["default"],
):
"""
Expand All @@ -367,7 +366,7 @@ def post(
"""

def inner(handler):
self.add_path_obj("post", endpoint, openapi_summary, openapi_tags)
self.add_openapi_path_obj("post", endpoint, inspect.getdoc(handler), openapi_tags)

return self.add_route(HttpMethod.POST, endpoint, handler, auth_required=auth_required)

Expand All @@ -377,7 +376,6 @@ def put(
self,
endpoint: str,
auth_required: bool = False,
openapi_summary: str = "",
openapi_tags: list = ["default"],
):
"""
Expand All @@ -387,7 +385,7 @@ def put(
"""

def inner(handler):
self.add_path_obj("put", endpoint, openapi_summary, openapi_tags)
self.add_openapi_path_obj("put", endpoint, inspect.getdoc(handler), openapi_tags)

return self.add_route(HttpMethod.PUT, endpoint, handler, auth_required=auth_required)

Expand All @@ -397,7 +395,6 @@ def delete(
self,
endpoint: str,
auth_required: bool = False,
openapi_summary: str = "",
openapi_tags: list = ["default"],
):
"""
Expand All @@ -407,7 +404,7 @@ def delete(
"""

def inner(handler):
self.add_path_obj("delete", endpoint, openapi_summary, openapi_tags)
self.add_openapi_path_obj("delete", endpoint, inspect.getdoc(handler), openapi_tags)

return self.add_route(HttpMethod.DELETE, endpoint, handler, auth_required=auth_required)

Expand All @@ -417,7 +414,6 @@ def patch(
self,
endpoint: str,
auth_required: bool = False,
openapi_summary: str = "",
openapi_tags: list = ["default"],
):
"""
Expand All @@ -427,7 +423,7 @@ def patch(
"""

def inner(handler):
self.add_path_obj("patch", endpoint, openapi_summary, openapi_tags)
self.add_openapi_path_obj("patch", endpoint, inspect.getdoc(handler), openapi_tags)

return self.add_route(HttpMethod.PATCH, endpoint, handler, auth_required=auth_required)

Expand All @@ -437,7 +433,6 @@ def head(
self,
endpoint: str,
auth_required: bool = False,
openapi_summary: str = "",
openapi_tags: list = ["default"],
):
"""
Expand All @@ -447,7 +442,7 @@ def head(
"""

def inner(handler):
self.add_path_obj("head", endpoint, openapi_summary, openapi_tags)
self.add_openapi_path_obj("head", endpoint, inspect.getdoc(handler), openapi_tags)

return self.add_route(HttpMethod.HEAD, endpoint, handler, auth_required=auth_required)

Expand All @@ -457,7 +452,6 @@ def options(
self,
endpoint: str,
auth_required: bool = False,
openapi_summary: str = "",
openapi_tags: list = ["default"],
):
"""
Expand All @@ -467,7 +461,7 @@ def options(
"""

def inner(handler):
self.add_path_obj("options", endpoint, openapi_summary, openapi_tags)
self.add_openapi_path_obj("options", endpoint, inspect.getdoc(handler), openapi_tags)

return self.add_route(HttpMethod.OPTIONS, endpoint, handler, auth_required=auth_required)

Expand All @@ -477,7 +471,6 @@ def connect(
self,
endpoint: str,
auth_required: bool = False,
openapi_summary: str = "",
openapi_tags: list = ["default"],
):
"""
Expand All @@ -487,7 +480,7 @@ def connect(
"""

def inner(handler):
self.add_path_obj("connect", endpoint, openapi_summary, openapi_tags)
self.add_openapi_path_obj("connect", endpoint, inspect.getdoc(handler), openapi_tags)

return self.add_route(HttpMethod.CONNECT, endpoint, handler, auth_required=auth_required)

Expand All @@ -497,7 +490,6 @@ def trace(
self,
endpoint: str,
auth_required: bool = False,
openapi_summary: str = "",
openapi_tags: list = ["default"],
):
"""
Expand All @@ -507,7 +499,7 @@ def trace(
"""

def inner(handler):
self.add_path_obj("trace", endpoint, openapi_summary, openapi_tags)
self.add_openapi_path_obj("trace", endpoint, inspect.getdoc(handler), openapi_tags)

return self.add_route(HttpMethod.TRACE, endpoint, handler, auth_required=auth_required)

Expand Down
7 changes: 5 additions & 2 deletions testing_application/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@

@app.get("/")
async def welcome():
"""hiiii"""
return "hiiiiii"


@app.get("/users/:name/:age", openapi_summary="Get User by ID", openapi_tags=["Users"])
@app.get("/users/:name/:age", openapi_tags=["Users"])
async def get_user(r: Request):
"""Get User by ID"""
return {"message": f"User {r.path_params['name']} : {r.path_params['age']}"}


@app.delete("/users/:name/:age", openapi_summary="Delete User by ID", openapi_tags=["Users"])
@app.delete("/users/:name/:age", openapi_tags=["Users"])
async def delete_user(r: Request):
"""Delete User by ID"""
return f"Successfully deleted {r.path_params['name']} : {r.path_params['age']}"


Expand Down

0 comments on commit f8d4854

Please sign in to comment.