Skip to content

Commit

Permalink
update docs with the latest spec
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSanal committed Oct 13, 2024
1 parent 4bd4921 commit abe068d
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 53 deletions.
45 changes: 21 additions & 24 deletions docs_src/src/pages/documentation/api_reference/openapi.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ python app.py --disable-openapi

## How to use?

- Query Params: The typing for query params can be added as `def get(r: Request, query_params=GetRequestParams)` where `GetRequestParams` is a subclass of `RequestQuery`
- Query Params: The typing for query params can be added as `def get(r: Request, query_params: GetRequestParams)` where `GetRequestParams` is a subclass of `QueryParams`
- Path Params are defaulted to string type (ref: https://en.wikipedia.org/wiki/Query_string)

<CodeGroup title="Basic App">

```python {{ title: 'untyped' }}
from robyn.types import RequestBody, RequestQuery

from robyn import Robyn, OpenAPI
from robyn.openapi import OpenAPIInfo, Contact, License, ExternalDocumentation, Components
from robyn import Robyn
from robyn.robyn import QueryParams

app = Robyn(
file_object=__file__,
Expand Down Expand Up @@ -61,7 +59,7 @@ async def welcome():
return "hi"


class GetRequestParams(RequestQuery):
class GetRequestParams(QueryParams):
appointment_id: str
year: int

Expand All @@ -83,12 +81,11 @@ if __name__ == "__main__":
```

```python {{ title: 'typed' }}
from robyn.types import RequestBody, RequestQuery
from robyn.robyn import QueryParams

from robyn import Robyn, OpenAPI, Request
from robyn.openapi import OpenAPIInfo, Contact, License, ExternalDocumentation, Components
from robyn import Robyn, Request

app: Robyn = Robyn(
app = Robyn(
file_object=__file__,
openapi=OpenAPI(
info=OpenAPIInfo(
Expand Down Expand Up @@ -118,7 +115,7 @@ async def welcome():
return "hi"


class GetRequestParams(RequestQuery):
class GetRequestParams(QueryParams):
appointment_id: str
year: int

Expand Down Expand Up @@ -146,9 +143,8 @@ if __name__ == "__main__":
<CodeGroup title="Subrouters">

```python {{ title: 'untyped' }}
from robyn.types import RequestQuery

from robyn import SubRouter
from robyn.robyn import QueryParams

subrouter = SubRouter(__name__, prefix="/sub")

Expand All @@ -159,7 +155,7 @@ async def subrouter_welcome():
return "hiiiiii subrouter"


class SubRouterGetRequestParams(RequestQuery):
class SubRouterGetRequestParams(QueryParams):
_id: int
value: str

Expand All @@ -180,7 +176,7 @@ app.include_router(subrouter)
```

```python {{ title: 'typed' }}
from robyn.types import RequestQuery
from robyn.robyn import QueryParams

from robyn import Request, SubRouter

Expand All @@ -193,7 +189,7 @@ async def subrouter_welcome():
return "hiiiiii subrouter"


class SubRouterGetRequestParams(RequestQuery):
class SubRouterGetRequestParams(QueryParams):
_id: int
value: str

Expand Down Expand Up @@ -222,20 +218,20 @@ We support all the params mentioned in the latest OpenAPI specifications (https:
<CodeGroup title="Request & Response Body">

```python {{ title: 'untyped' }}
from robyn.types import JSONResponse, RequestBody
from robyn.types import JSONResponse, Body

class Initial(RequestBody):
class Initial(Body):
is_present: bool
letter: Optional[str]


class FullName(RequestBody):
class FullName(Body):
first: str
second: str
initial: Initial


class CreateItemBody(RequestBody):
class CreateItemBody(Body):
name: FullName
description: str
price: float
Expand All @@ -253,25 +249,26 @@ def create_item(request: Request, body: CreateItemBody) -> CreateResponse:
```

```python {{ title: 'typed' }}
from robyn.types import JSONResponse, RequestBody
from robyn.types import JSONResponse, Body

class Initial(RequestBody):
class Initial(Body):
is_present: bool
letter: Optional[str]


class FullName(RequestBody):
class FullName(Body):
first: str
second: str
initial: Initial


class CreateItemBody(RequestBody):
class CreateItemBody(Body):
name: FullName
description: str
price: float
tax: float


class CreateResponse(JSONResponse):
success: bool
items_changed: int
Expand Down
96 changes: 67 additions & 29 deletions docs_src/src/pages/documentation/example_app/openapi.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,37 @@ python app.py --disable-openapi

## How to use?

- Query Params: The typing for query params can be added as `def get(r: Request, query_params=GetRequestParams)` where `GetRequestParams` is a subclass of `RequestQuery`
- Query Params: The typing for query params can be added as `def get(r: Request, query_params: GetRequestParams)` where `GetRequestParams` is a subclass of `QueryParams`
- Path Params are defaulted to string type (ref: https://en.wikipedia.org/wiki/Query_string)

<CodeGroup title="Basic App">

```python {{ title: 'untyped' }}
from robyn.types import RequestBody, RequestQuery

from robyn import Robyn, OpenAPI
from robyn.openapi import OpenAPIInfo, Contact, License, ExternalDocumentation, Components


app = Robyn(file_object=__file__)
from robyn import Robyn
from robyn.robyn import QueryParams

app = Robyn(
file_object=__file__,
openapi=OpenAPI(
info=OpenAPIInfo(
title="Sample App",
description="This is a sample server application.",
termsOfService="https://example.com/terms/",
version="1.0.0",
contact=Contact(
name="API Support",
url="https://www.example.com/support",
email="[email protected]",
),
license=License(
name="BSD2.0",
url="https://opensource.org/license/bsd-2-clause",
),
externalDocs=ExternalDocumentation(description="Find more info here", url="https://example.com/"),
components=Components(),
),
),
)


@app.get("/")
Expand All @@ -40,7 +58,7 @@ async def welcome():
return "hi"


class GetRequestParams(RequestQuery):
class GetRequestParams(QueryParams):
appointment_id: str
year: int

Expand All @@ -62,12 +80,32 @@ if __name__ == "__main__":
```

```python {{ title: 'typed' }}
from robyn.types import RequestBody, RequestQuery

from robyn import Robyn, OpenAPI, Request
from robyn.openapi import OpenAPIInfo, Contact, License, ExternalDocumentation, Components

app: Robyn = Robyn(file_object=__file__)
from robyn.robyn import QueryParams

from robyn import Robyn, Request

app = Robyn(
file_object=__file__,
openapi=OpenAPI(
info=OpenAPIInfo(
title="Sample App",
description="This is a sample server application.",
termsOfService="https://example.com/terms/",
version="1.0.0",
contact=Contact(
name="API Support",
url="https://www.example.com/support",
email="[email protected]",
),
license=License(
name="BSD2.0",
url="https://opensource.org/license/bsd-2-clause",
),
externalDocs=ExternalDocumentation(description="Find more info here", url="https://example.com/"),
components=Components(),
),
),
)


@app.get("/")
Expand All @@ -76,7 +114,7 @@ async def welcome():
return "hi"


class GetRequestParams(RequestQuery):
class GetRequestParams(QueryParams):
appointment_id: str
year: int

Expand Down Expand Up @@ -104,9 +142,8 @@ if __name__ == "__main__":
<CodeGroup title="Subrouters">

```python {{ title: 'untyped' }}
from robyn.types import RequestQuery

from robyn import SubRouter
from robyn.robyn import QueryParams

subrouter = SubRouter(__name__, prefix="/sub")

Expand All @@ -117,7 +154,7 @@ async def subrouter_welcome():
return "hiiiiii subrouter"


class SubRouterGetRequestParams(RequestQuery):
class SubRouterGetRequestParams(QueryParams):
_id: int
value: str

Expand All @@ -138,7 +175,7 @@ app.include_router(subrouter)
```

```python {{ title: 'typed' }}
from robyn.types import RequestQuery
from robyn.robyn import QueryParams

from robyn import Request, SubRouter

Expand All @@ -151,7 +188,7 @@ async def subrouter_welcome():
return "hiiiiii subrouter"


class SubRouterGetRequestParams(RequestQuery):
class SubRouterGetRequestParams(QueryParams):
_id: int
value: str

Expand Down Expand Up @@ -180,20 +217,20 @@ We support all the params mentioned in the latest OpenAPI specifications (https:
<CodeGroup title="Request & Response Body">

```python {{ title: 'untyped' }}
from robyn.types import JSONResponse, RequestBody
from robyn.types import JSONResponse, Body

class Initial(RequestBody):
class Initial(Body):
is_present: bool
letter: Optional[str]


class FullName(RequestBody):
class FullName(Body):
first: str
second: str
initial: Initial


class CreateItemBody(RequestBody):
class CreateItemBody(Body):
name: FullName
description: str
price: float
Expand All @@ -211,25 +248,26 @@ def create_item(request: Request, body: CreateItemBody) -> CreateResponse:
```

```python {{ title: 'typed' }}
from robyn.types import JSONResponse, RequestBody
from robyn.types import JSONResponse, Body

class Initial(RequestBody):
class Initial(Body):
is_present: bool
letter: Optional[str]


class FullName(RequestBody):
class FullName(Body):
first: str
second: str
initial: Initial


class CreateItemBody(RequestBody):
class CreateItemBody(Body):
name: FullName
description: str
price: float
tax: float


class CreateResponse(JSONResponse):
success: bool
items_changed: int
Expand Down

0 comments on commit abe068d

Please sign in to comment.