Skip to content

Commit 89b73e8

Browse files
committed
Add more documentation
1 parent 2bc8b4c commit 89b73e8

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

core/server.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def __init__(self, *, database: Database) -> None:
6161

6262
super().__init__(on_startup=[self.event_ready], views=views, routes=routes, middleware=middleware)
6363

64+
@starlette_plus.route("/docs")
65+
async def documentation_redirect(self, request: starlette_plus.Request) -> starlette_plus.Response:
66+
return starlette_plus.RedirectResponse("/api/documentation")
67+
6468
async def event_ready(self) -> None:
6569
self.schemas = SchemaGenerator(
6670
{

views/api.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,89 @@ async def paste_post(self, request: starlette_plus.Request) -> starlette_plus.Re
6565
summary: Create a paste.
6666
description:
6767
Creates a paste with or without multiple files for view on the web or via the API.
68+
You can use this endpoint to POST valid `JSON` data or `plain-text` content.\n\n\n
69+
70+
When using `plain-text`, only one file will be created, without a password or expiry.\n\n\n
71+
72+
Max Character per file is `300_000`.\n\n
73+
74+
Max file limit is `5`.\n\n
75+
76+
requestBody:
77+
description: The paste data. `password` and `expires` are optional.
78+
content:
79+
application/json:
80+
schema:
81+
type: object
82+
properties:
83+
files:
84+
type: array
85+
items:
86+
type: object
87+
properties:
88+
filename:
89+
type: string
90+
required: false
91+
content:
92+
type: string
93+
required: true
94+
example:
95+
- filename: thing.py
96+
content: print(\"Hello World!\")
97+
- content: Some text or code...
98+
password:
99+
required: false
100+
type: string
101+
example: null
102+
expires:
103+
required: false
104+
type: string
105+
example: null
106+
text/plain:
107+
schema:
108+
type: string
109+
110+
responses:
111+
200:
112+
description: The paste meta-data.
113+
content:
114+
application/json:
115+
schema:
116+
type: object
117+
properties:
118+
id:
119+
type: string
120+
example: abc123
121+
created_at:
122+
type: string
123+
example: 2024-01-01T00:00:00.000000+00:00
124+
expires:
125+
type: string
126+
example: 2024-01-01T00:00:00.000000+00:00
127+
safety:
128+
type: string
129+
400:
130+
description: The paste data was invalid.
131+
content:
132+
application/json:
133+
schema:
134+
type: object
135+
properties:
136+
error:
137+
type: string
138+
example: The reason the paste was invalid.
139+
429:
140+
description: You are requesting too fast.
141+
content:
142+
application/json:
143+
schema:
144+
type: object
145+
properties:
146+
error:
147+
type: string
148+
example: You are requesting too fast.
68149
"""
150+
69151
content_type: str | None = request.headers.get("content-type", None)
70152
body: dict[str, Any] | str
71153
data: dict[str, Any]

views/docs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ class DocsView(starlette_plus.View, prefix="api"):
3131
def __init__(self, app: Application) -> None:
3232
self.app: Application = app
3333

34-
@starlette_plus.route("/docs")
34+
@starlette_plus.route("/documentation")
3535
async def documentation(self, request: starlette_plus.Request) -> starlette_plus.Response:
3636
headers = {"Access-Control-Allow-Origin": "*"}
3737
return starlette_plus.FileResponse("web/docs.html", headers=headers)
3838

39+
@starlette_plus.route("/docs")
40+
async def documentation_redirect(self, request: starlette_plus.Request) -> starlette_plus.Response:
41+
return starlette_plus.RedirectResponse("/api/documentation")
42+
3943
@starlette_plus.route("/schema")
4044
async def openapi_schema(self, request: starlette_plus.Request) -> starlette_plus.Response:
4145
if not self.app.schemas:

0 commit comments

Comments
 (0)