@cubocicloide/stack-react-django 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/base/CLAUDE.md.hbs +14 -2
- package/templates/base/README.md.hbs +2 -2
- package/templates/base/backend/README.md.hbs +8 -3
- package/templates/base/backend/apps/core/views.py +8 -2
- package/templates/base/backend/apps/users/views.py +19 -0
- package/templates/base/backend/config/api_docs.py.hbs +123 -0
- package/templates/base/backend/config/settings/base.py.hbs +15 -1
- package/templates/base/backend/config/urls.py.hbs +5 -3
- package/templates/base/backend/pyproject.toml.hbs +2 -0
- package/templates/base/backend/templates/api-docs.html.hbs +98 -0
- package/templates/base/docs/docs/dude.md.hbs +2 -2
- package/templates/base/docs/docs/index.md.hbs +1 -1
- package/templates/base/frontend/src/openapi/utils/openapi.yaml.hbs +9 -6
- package/templates/s3/backend/apps/files/views.py +26 -3
package/package.json
CHANGED
|
@@ -151,8 +151,20 @@ Migrations also run automatically when the backend container boots.
|
|
|
151
151
|
| `dude api review` | Validate `frontend/src/openapi/` against the saved spec |
|
|
152
152
|
|
|
153
153
|
**Workflow**: always run `dude api sync` after changing backend endpoints, then
|
|
154
|
-
commit the updated `frontend/src/openapi/` alongside the change.
|
|
155
|
-
served at http://localhost:8000/api/docs
|
|
154
|
+
commit the updated `frontend/src/openapi/` alongside the change. The reference is
|
|
155
|
+
served at http://localhost:8000/api/docs/ (Scalar).
|
|
156
|
+
|
|
157
|
+
**Documenting an endpoint** — the schema only carries what the code declares:
|
|
158
|
+
|
|
159
|
+
- Every view gets a `@extend_schema` (or `@extend_schema_view`) with a `tags`
|
|
160
|
+
entry, an imperative `summary` (≤ 6 words) and a `description` that says
|
|
161
|
+
something the schema does not already show — preconditions, side effects, who
|
|
162
|
+
may call it, which error a wrong call returns.
|
|
163
|
+
- Every tag used must exist in `API_TAGS` in `backend/config/api_docs.py`, or the
|
|
164
|
+
operation lands ungrouped at the bottom of the sidebar. `API_TAGS` order **is**
|
|
165
|
+
the sidebar order.
|
|
166
|
+
- Cross-cutting prose (auth header, conventions, the domain lifecycle) belongs in
|
|
167
|
+
`API_DESCRIPTION` in the same file, not repeated per endpoint.
|
|
156
168
|
|
|
157
169
|
### Testing
|
|
158
170
|
|
|
@@ -62,8 +62,8 @@ Once the containers are up, open the URLs below.
|
|
|
62
62
|
|---------|-----|-------|
|
|
63
63
|
| **Frontend** | http://localhost:5173 | React + Vite — HMR active |
|
|
64
64
|
| **API** | http://localhost:8000 | Django REST Framework |
|
|
65
|
-
| **
|
|
66
|
-
| **OpenAPI schema** | http://localhost:8000/api/schema/ | Raw schema (YAML) |
|
|
65
|
+
| **API reference** | http://localhost:8000/api/docs/ | Interactive reference (Scalar) — narrative in `backend/config/api_docs.py` |
|
|
66
|
+
| **OpenAPI schema** | http://localhost:8000/api/schema/ | Raw schema (YAML, drf-spectacular) |
|
|
67
67
|
| **Health** | http://localhost:8000/api/health/ | JSON health check |
|
|
68
68
|
| **Django admin** | http://localhost:8000/admin/ | Create an account with `dude db superuser` |
|
|
69
69
|
{{#if withS3}}
|
|
@@ -79,9 +79,14 @@ uv run python manage.py migrate
|
|
|
79
79
|
uv run python manage.py runserver 0.0.0.0:8000
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
Then open <http://localhost:8000/api/health/> — interactive API
|
|
83
|
-
<http://localhost:8000/api/docs/> (
|
|
84
|
-
the raw OpenAPI schema at
|
|
82
|
+
Then open <http://localhost:8000/api/health/> — the interactive API reference
|
|
83
|
+
lives at <http://localhost:8000/api/docs/> (Scalar, rendered from
|
|
84
|
+
`backend/templates/api-docs.html`) and the raw OpenAPI schema at
|
|
85
|
+
<http://localhost:8000/api/schema/>.
|
|
86
|
+
|
|
87
|
+
The reference's prose — authentication, conventions, the domain lifecycle — is
|
|
88
|
+
hand-written in `backend/config/api_docs.py`. Keep it current: the schema is
|
|
89
|
+
generated, that file is not.
|
|
85
90
|
|
|
86
91
|
## Tests
|
|
87
92
|
|
|
@@ -14,9 +14,15 @@ class HealthView(APIView):
|
|
|
14
14
|
|
|
15
15
|
@extend_schema(
|
|
16
16
|
operation_id="health_retrieve",
|
|
17
|
-
|
|
17
|
+
summary="Check service health",
|
|
18
|
+
description=(
|
|
19
|
+
'Returns `{"status": "ok"}` while the process is accepting requests. '
|
|
20
|
+
"This is a liveness probe, not a status page — it does not test the "
|
|
21
|
+
"database, the cache or any downstream service. The only endpoint that "
|
|
22
|
+
"needs no credentials."
|
|
23
|
+
),
|
|
18
24
|
responses=HealthSerializer,
|
|
19
|
-
tags=["
|
|
25
|
+
tags=["Health"],
|
|
20
26
|
auth=[],
|
|
21
27
|
)
|
|
22
28
|
def get(self, request: Request) -> Response:
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from drf_spectacular.utils import extend_schema, extend_schema_view
|
|
1
2
|
from rest_framework.permissions import AllowAny
|
|
2
3
|
from rest_framework.viewsets import ReadOnlyModelViewSet
|
|
3
4
|
|
|
@@ -5,6 +6,24 @@ from apps.users.models import User
|
|
|
5
6
|
from apps.users.serializers import UserSerializer
|
|
6
7
|
|
|
7
8
|
|
|
9
|
+
@extend_schema(tags=["Users"])
|
|
10
|
+
@extend_schema_view(
|
|
11
|
+
list=extend_schema(
|
|
12
|
+
summary="List users",
|
|
13
|
+
description=(
|
|
14
|
+
"Paginated and ordered by `id` ascending. Select a page with "
|
|
15
|
+
"`?page=<n>`; the page size is fixed at 50. Results always come back "
|
|
16
|
+
"in the envelope (`count`, `next`, `previous`, `results`), never as a "
|
|
17
|
+
"bare array."
|
|
18
|
+
),
|
|
19
|
+
),
|
|
20
|
+
retrieve=extend_schema(
|
|
21
|
+
summary="Retrieve a user",
|
|
22
|
+
description=(
|
|
23
|
+
'An unknown id returns `404` with `{"detail": "No User matches the given query."}`.'
|
|
24
|
+
),
|
|
25
|
+
),
|
|
26
|
+
)
|
|
8
27
|
class UserViewSet(ReadOnlyModelViewSet):
|
|
9
28
|
"""List (paginated) and retrieve users.
|
|
10
29
|
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Narrative + sidebar structure for the public API reference.
|
|
2
|
+
|
|
3
|
+
`API_DESCRIPTION` becomes `info.description` in the OpenAPI schema and renders as
|
|
4
|
+
the landing page of the reference at ``/api/docs/``. `API_TAGS` is the sidebar:
|
|
5
|
+
its order is the sidebar order (``SORT_OPERATIONS`` is off), and every tag used
|
|
6
|
+
by a view must appear here or the operation lands ungrouped at the bottom.
|
|
7
|
+
|
|
8
|
+
Both are wired up in ``config/settings/base.py`` (``SPECTACULAR_SETTINGS``).
|
|
9
|
+
|
|
10
|
+
This file is where the reference stops being generated and starts being written.
|
|
11
|
+
Edit it as the API grows — the sections marked **TODO** describe your product,
|
|
12
|
+
not the scaffold.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
API_DESCRIPTION = """
|
|
16
|
+
The **{{projectName}}** HTTP API. It is consumed by the {{projectName}} web frontend and by any
|
|
17
|
+
service you authorise. Every response is JSON; every path below is relative to
|
|
18
|
+
`/api/`.
|
|
19
|
+
|
|
20
|
+
<!-- TODO: replace this paragraph with what the API actually is — the domain in
|
|
21
|
+
plain words, who calls it, and what a caller can accomplish with it. If it is
|
|
22
|
+
internal-only, say so here rather than making integrators discover it from a 401. -->
|
|
23
|
+
|
|
24
|
+
## Authentication
|
|
25
|
+
|
|
26
|
+
The scaffold ships Django REST Framework's default authenticators — **session
|
|
27
|
+
cookie** and **HTTP Basic**. Every endpoint requires an authenticated user unless
|
|
28
|
+
its view opts out with an explicit `permission_classes` declaration.
|
|
29
|
+
|
|
30
|
+
Session (browser, same-origin — what the frontend uses):
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
Cookie: sessionid=<session-id>
|
|
34
|
+
X-CSRFToken: <csrf-token>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
HTTP Basic (scripts and `curl`):
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
Authorization: Basic <base64(username:password)>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Create a user with `dude db superuser`, then log in at `/admin/` to get a session.
|
|
44
|
+
|
|
45
|
+
<!-- TODO: swap in the real scheme before exposing this API. Add
|
|
46
|
+
`DEFAULT_AUTHENTICATION_CLASSES` to `REST_FRAMEWORK` in
|
|
47
|
+
`config/settings/base.py` (e.g. `djangorestframework-simplejwt`), then document
|
|
48
|
+
the exact header verbatim here, plus token lifetimes and how a caller obtains
|
|
49
|
+
credentials. Prefix mistakes are the most common integration failure — spell the
|
|
50
|
+
header out, do not paraphrase it. -->
|
|
51
|
+
|
|
52
|
+
## Base URLs
|
|
53
|
+
|
|
54
|
+
| Environment | Base URL |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| Local development | `http://localhost:8000` |
|
|
57
|
+
|
|
58
|
+
<!-- TODO: add the deployed environments and mirror them in `SERVERS`
|
|
59
|
+
(`SPECTACULAR_SETTINGS`, `config/settings/base.py`) so the **Test Request**
|
|
60
|
+
panel can target them. -->
|
|
61
|
+
|
|
62
|
+
## Conventions
|
|
63
|
+
|
|
64
|
+
- **Trailing slashes are required.** DRF's routers register `/api/users/`, not
|
|
65
|
+
`/api/users`. Without the slash Django replies `301` and most HTTP clients drop
|
|
66
|
+
the request body on the redirect.
|
|
67
|
+
- **Pagination** — list endpoints return an envelope, never a bare array:
|
|
68
|
+
`{"count": 123, "next": "…?page=3", "previous": "…?page=1", "results": [...]}`.
|
|
69
|
+
Page size is 50; select a page with `?page=<n>`. `next`/`previous` are `null` at
|
|
70
|
+
the ends.
|
|
71
|
+
- **Timestamps** — ISO-8601 with an offset, always UTC (`2026-01-31T09:15:00Z`).
|
|
72
|
+
- **IDs** — sequential integers, not UUIDs. Do not assume they are unguessable.
|
|
73
|
+
- **Errors** — two distinct body shapes:
|
|
74
|
+
- non-field failures (401, 403, 404, 405, throttled): `{"detail": "Not found."}`
|
|
75
|
+
- validation failures (400): a map of field name → list of messages,
|
|
76
|
+
`{"email": ["Enter a valid email address."]}`, with non-field problems under
|
|
77
|
+
the `non_field_errors` key.
|
|
78
|
+
{{#if withS3}}
|
|
79
|
+
- **Files** — uploads are `multipart/form-data` on the `file` field. The response
|
|
80
|
+
never contains the binary: it returns metadata plus `url`, a **presigned link
|
|
81
|
+
that expires**. Fetch it fresh from the API rather than storing it.
|
|
82
|
+
{{/if}}
|
|
83
|
+
|
|
84
|
+
## Lifecycle
|
|
85
|
+
|
|
86
|
+
<!-- TODO: this section carries the most weight in the whole reference, and the
|
|
87
|
+
scaffold cannot write it for you. Describe the state machine a caller must
|
|
88
|
+
respect: which state an object starts in, what each transition requires as a
|
|
89
|
+
precondition, what locks afterwards, and which status code a premature call
|
|
90
|
+
gets. Per-endpoint docs cannot express this; leaving it out is what makes
|
|
91
|
+
integrators guess. Delete this section only if the domain genuinely has no
|
|
92
|
+
stateful objects. -->
|
|
93
|
+
|
|
94
|
+
## Status
|
|
95
|
+
|
|
96
|
+
- The API is **unversioned**. Breaking changes ship without a path bump — pin
|
|
97
|
+
nothing, read the changelog.
|
|
98
|
+
- `GET /api/health/` is the only unauthenticated endpoint. It is a liveness probe,
|
|
99
|
+
not a status page: it reports that the process is up, not that the database is.
|
|
100
|
+
{{#if withS3}}
|
|
101
|
+
- File storage runs against MinIO locally and S3 in deployed environments. Presigned
|
|
102
|
+
URL lifetimes differ between the two.
|
|
103
|
+
{{/if}}
|
|
104
|
+
- No webhooks, no rate limiting, and no API keys yet.
|
|
105
|
+
""".strip()
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
API_TAGS = [
|
|
109
|
+
{
|
|
110
|
+
"name": "Health",
|
|
111
|
+
"description": "Liveness probe. Unauthenticated, used by container health checks and the frontend boot sequence.",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"name": "Users",
|
|
115
|
+
"description": "The accounts that authenticate against this API. Read-only in the scaffold — user creation lives in `apps.users.services`.",
|
|
116
|
+
},
|
|
117
|
+
{{#if withS3}}
|
|
118
|
+
{
|
|
119
|
+
"name": "Files",
|
|
120
|
+
"description": "Binaries stored on the object-storage backend. Uploaded as multipart, read back through short-lived presigned URLs.",
|
|
121
|
+
},
|
|
122
|
+
{{/if}}
|
|
123
|
+
]
|
|
@@ -13,6 +13,8 @@ from pathlib import Path
|
|
|
13
13
|
|
|
14
14
|
import environ
|
|
15
15
|
|
|
16
|
+
from config.api_docs import API_DESCRIPTION, API_TAGS
|
|
17
|
+
|
|
16
18
|
env = environ.Env()
|
|
17
19
|
|
|
18
20
|
# backend/ directory (contains manage.py) — /app inside the container
|
|
@@ -65,7 +67,8 @@ ROOT_URLCONF = "config.urls"
|
|
|
65
67
|
TEMPLATES = [
|
|
66
68
|
{
|
|
67
69
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
68
|
-
|
|
70
|
+
# backend/templates/ — holds api-docs.html (the API reference page).
|
|
71
|
+
"DIRS": [BASE_DIR / "templates"],
|
|
69
72
|
"APP_DIRS": True,
|
|
70
73
|
"OPTIONS": {
|
|
71
74
|
"context_processors": [
|
|
@@ -156,10 +159,21 @@ REST_FRAMEWORK = {
|
|
|
156
159
|
"DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"],
|
|
157
160
|
}
|
|
158
161
|
|
|
162
|
+
# ── OpenAPI schema (drf-spectacular) ──────────────────────────────────────────
|
|
163
|
+
# The reference is served at /api/docs/ by Scalar; the prose lives in
|
|
164
|
+
# config/api_docs.py. Regenerate the frontend client with `dude api sync`.
|
|
165
|
+
|
|
159
166
|
SPECTACULAR_SETTINGS = {
|
|
160
167
|
"TITLE": env("APP_TITLE", default="{{projectName}}") + " API",
|
|
168
|
+
"DESCRIPTION": API_DESCRIPTION,
|
|
161
169
|
"VERSION": "1.0.0",
|
|
170
|
+
# The schema endpoint is not itself an operation.
|
|
162
171
|
"SERVE_INCLUDE_SCHEMA": False,
|
|
172
|
+
# Keep the author-chosen order — TAGS drives the sidebar, not the alphabet.
|
|
173
|
+
"SORT_OPERATIONS": False,
|
|
174
|
+
"TAGS": API_TAGS,
|
|
175
|
+
# Add deployed environments here so the "Test Request" panel can target them.
|
|
176
|
+
"SERVERS": [{"url": "http://localhost:8000", "description": "Local development"}],
|
|
163
177
|
}
|
|
164
178
|
{{#if withCelery}}
|
|
165
179
|
|
|
@@ -6,7 +6,8 @@ declares its own routes (and an ``app_name``) in ``apps/<app>/urls.py``.
|
|
|
6
6
|
|
|
7
7
|
from django.contrib import admin
|
|
8
8
|
from django.urls import include, path
|
|
9
|
-
from
|
|
9
|
+
from django.views.generic import TemplateView
|
|
10
|
+
from drf_spectacular.views import SpectacularAPIView
|
|
10
11
|
|
|
11
12
|
urlpatterns = [
|
|
12
13
|
path("admin/", admin.site.urls),
|
|
@@ -16,7 +17,8 @@ urlpatterns = [
|
|
|
16
17
|
{{#if withS3}}
|
|
17
18
|
path("api/", include("apps.files.urls")),
|
|
18
19
|
{{/if}}
|
|
19
|
-
# OpenAPI schema +
|
|
20
|
+
# OpenAPI schema (drf-spectacular) + the reference page (Scalar, rendered from
|
|
21
|
+
# backend/templates/api-docs.html). One docs URL — no Swagger UI, no ReDoc.
|
|
20
22
|
path("api/schema/", SpectacularAPIView.as_view(), name="schema"),
|
|
21
|
-
path("api/docs/",
|
|
23
|
+
path("api/docs/", TemplateView.as_view(template_name="api-docs.html"), name="docs"),
|
|
22
24
|
]
|
|
@@ -42,6 +42,8 @@ target-version = "py313"
|
|
|
42
42
|
select = ["E", "F", "I", "N", "UP", "B", "S", "RUF"]
|
|
43
43
|
|
|
44
44
|
[tool.ruff.lint.per-file-ignores]
|
|
45
|
+
# Markdown narrative + tag prose — line length is not a useful rule there.
|
|
46
|
+
"config/api_docs.py" = ["E501"]
|
|
45
47
|
# Tests use asserts (S101) and throw-away credentials (S105/S106).
|
|
46
48
|
"apps/*/tests/*" = ["S101", "S105", "S106"]
|
|
47
49
|
# Hand-written / autogenerated migrations may exceed the line length.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>{{projectName}} API reference</title>
|
|
7
|
+
<link
|
|
8
|
+
rel="icon"
|
|
9
|
+
href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Crect width='48' height='48' rx='12' fill='%231677ff'/%3E%3C/svg%3E"
|
|
10
|
+
/>
|
|
11
|
+
<style>
|
|
12
|
+
html,
|
|
13
|
+
body {
|
|
14
|
+
margin: 0;
|
|
15
|
+
}
|
|
16
|
+
:root {
|
|
17
|
+
--scalar-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
|
|
18
|
+
Arial, sans-serif;
|
|
19
|
+
--scalar-font-code: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
20
|
+
}
|
|
21
|
+
/* Brand accent — matches the frontend's antd primary colour. */
|
|
22
|
+
.light-mode {
|
|
23
|
+
--scalar-color-accent: #1677ff;
|
|
24
|
+
}
|
|
25
|
+
.dark-mode {
|
|
26
|
+
--scalar-color-accent: #4096ff;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* Brand bar. Delete this block and the <header> below together if you'd
|
|
30
|
+
rather have Scalar's own header on its own. */
|
|
31
|
+
.brandbar {
|
|
32
|
+
position: sticky;
|
|
33
|
+
top: 0;
|
|
34
|
+
z-index: 1000;
|
|
35
|
+
display: flex;
|
|
36
|
+
align-items: center;
|
|
37
|
+
gap: 0.75rem;
|
|
38
|
+
height: 56px;
|
|
39
|
+
padding: 0 1.25rem;
|
|
40
|
+
background: #1677ff;
|
|
41
|
+
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
|
|
42
|
+
}
|
|
43
|
+
.brandbar .name {
|
|
44
|
+
color: #fff;
|
|
45
|
+
font: 600 1rem/1 system-ui, -apple-system, sans-serif;
|
|
46
|
+
}
|
|
47
|
+
.brandbar .spacer {
|
|
48
|
+
flex: 1;
|
|
49
|
+
}
|
|
50
|
+
.brandbar .tag {
|
|
51
|
+
color: #fff;
|
|
52
|
+
opacity: 0.92;
|
|
53
|
+
font: 600 0.78rem/1 system-ui, -apple-system, sans-serif;
|
|
54
|
+
letter-spacing: 0.06em;
|
|
55
|
+
text-transform: uppercase;
|
|
56
|
+
}
|
|
57
|
+
</style>
|
|
58
|
+
</head>
|
|
59
|
+
<body>
|
|
60
|
+
<header class="brandbar">
|
|
61
|
+
<span class="name">{{projectName}}</span>
|
|
62
|
+
<span class="spacer"></span>
|
|
63
|
+
<span class="tag">API reference</span>
|
|
64
|
+
</header>
|
|
65
|
+
<div id="app"></div>
|
|
66
|
+
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
|
67
|
+
<script>
|
|
68
|
+
Scalar.createApiReference('#app', {
|
|
69
|
+
url: "{% url 'schema' %}",
|
|
70
|
+
theme: 'default',
|
|
71
|
+
layout: 'modern',
|
|
72
|
+
hideDownloadButton: true,
|
|
73
|
+
showDeveloperTools: 'never',
|
|
74
|
+
persistAuth: true,
|
|
75
|
+
withDefaultFonts: false,
|
|
76
|
+
metaData: {
|
|
77
|
+
title: '{{projectName}} API reference',
|
|
78
|
+
description: 'HTTP API reference for {{projectName}}.',
|
|
79
|
+
},
|
|
80
|
+
// Preselect a scheme so the Authentication panel opens with a filled
|
|
81
|
+
// field instead of "No authentication selected". Change this key when you
|
|
82
|
+
// swap the authenticators — it must match one of the keys drf-spectacular
|
|
83
|
+
// emits under components.securitySchemes (basicAuth, cookieAuth, jwtAuth…).
|
|
84
|
+
authentication: {
|
|
85
|
+
preferredSecurityScheme: 'basicAuth',
|
|
86
|
+
},
|
|
87
|
+
customCss: `
|
|
88
|
+
:root {
|
|
89
|
+
/* Room for the brand bar so Scalar still fits the viewport. Drop
|
|
90
|
+
this line together with the <header> if you remove the bar. */
|
|
91
|
+
--scalar-custom-header-height: 56px;
|
|
92
|
+
}
|
|
93
|
+
a[href*="scalar.com"] { display: none !important; }
|
|
94
|
+
`,
|
|
95
|
+
})
|
|
96
|
+
</script>
|
|
97
|
+
</body>
|
|
98
|
+
</html>
|
|
@@ -54,8 +54,8 @@ Once the stack is up, open these URLs:
|
|
|
54
54
|
|---------|-----|-------|
|
|
55
55
|
| **Frontend** | http://localhost:5173 | React + Vite — HMR active |
|
|
56
56
|
| **API** | http://localhost:8000 | Django REST Framework |
|
|
57
|
-
| **
|
|
58
|
-
| **OpenAPI schema** | http://localhost:8000/api/schema/ | Raw schema (YAML) |
|
|
57
|
+
| **API reference** | http://localhost:8000/api/docs/ | Interactive reference (Scalar) |
|
|
58
|
+
| **OpenAPI schema** | http://localhost:8000/api/schema/ | Raw schema (YAML, drf-spectacular) |
|
|
59
59
|
| **Health** | http://localhost:8000/api/health/ | JSON health check |
|
|
60
60
|
| **Django admin** | http://localhost:8000/admin/ | Create an account with `dude db superuser` |
|
|
61
61
|
{{#if withS3}}| **MinIO console** | http://localhost:9001 | Object-storage UI (minioadmin/minioadmin) |
|
|
@@ -55,7 +55,7 @@ dude docs # → http://localhost:8001
|
|
|
55
55
|
|----------|-----|
|
|
56
56
|
| Frontend (dev) | <http://localhost:5173> |
|
|
57
57
|
| Backend API | <http://localhost:8000> |
|
|
58
|
-
|
|
|
58
|
+
| API reference (Scalar) | <http://localhost:8000/api/docs/> |
|
|
59
59
|
| OpenAPI schema | <http://localhost:8000/api/schema/> |
|
|
60
60
|
| API health | <http://localhost:8000/api/health/> |
|
|
61
61
|
| Django admin | <http://localhost:8000/admin/> |
|
|
@@ -6,9 +6,10 @@ paths:
|
|
|
6
6
|
/api/health/:
|
|
7
7
|
get:
|
|
8
8
|
operationId: health_retrieve
|
|
9
|
-
|
|
9
|
+
summary: Check service health
|
|
10
|
+
description: 'Returns `{"status": "ok"}` while the process is accepting requests.'
|
|
10
11
|
tags:
|
|
11
|
-
-
|
|
12
|
+
- Health
|
|
12
13
|
security:
|
|
13
14
|
- {}
|
|
14
15
|
responses:
|
|
@@ -21,7 +22,8 @@ paths:
|
|
|
21
22
|
/api/users/:
|
|
22
23
|
get:
|
|
23
24
|
operationId: users_list
|
|
24
|
-
|
|
25
|
+
summary: List users
|
|
26
|
+
description: Paginated and ordered by `id` ascending.
|
|
25
27
|
parameters:
|
|
26
28
|
- name: page
|
|
27
29
|
required: false
|
|
@@ -30,7 +32,7 @@ paths:
|
|
|
30
32
|
schema:
|
|
31
33
|
type: integer
|
|
32
34
|
tags:
|
|
33
|
-
-
|
|
35
|
+
- Users
|
|
34
36
|
security:
|
|
35
37
|
- {}
|
|
36
38
|
responses:
|
|
@@ -43,7 +45,8 @@ paths:
|
|
|
43
45
|
/api/users/{id}/:
|
|
44
46
|
get:
|
|
45
47
|
operationId: users_retrieve
|
|
46
|
-
|
|
48
|
+
summary: Retrieve a user
|
|
49
|
+
description: An unknown id returns `404`.
|
|
47
50
|
parameters:
|
|
48
51
|
- name: id
|
|
49
52
|
in: path
|
|
@@ -52,7 +55,7 @@ paths:
|
|
|
52
55
|
schema:
|
|
53
56
|
type: integer
|
|
54
57
|
tags:
|
|
55
|
-
-
|
|
58
|
+
- Users
|
|
56
59
|
security:
|
|
57
60
|
- {}
|
|
58
61
|
responses:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from drf_spectacular.utils import extend_schema
|
|
1
|
+
from drf_spectacular.utils import extend_schema, extend_schema_view
|
|
2
2
|
from rest_framework.mixins import CreateModelMixin, ListModelMixin, RetrieveModelMixin
|
|
3
3
|
from rest_framework.parsers import MultiPartParser
|
|
4
4
|
from rest_framework.permissions import AllowAny
|
|
@@ -8,7 +8,21 @@ from apps.files.models import FileUpload
|
|
|
8
8
|
from apps.files.serializers import FileUploadSerializer
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
@extend_schema(tags=["
|
|
11
|
+
@extend_schema(tags=["Files"])
|
|
12
|
+
@extend_schema_view(
|
|
13
|
+
list=extend_schema(
|
|
14
|
+
summary="List uploaded files",
|
|
15
|
+
description=(
|
|
16
|
+
"Paginated, newest first. Each entry carries metadata plus a fresh "
|
|
17
|
+
"presigned `url` — the URLs expire, so read them from this endpoint "
|
|
18
|
+
"rather than caching them."
|
|
19
|
+
),
|
|
20
|
+
),
|
|
21
|
+
retrieve=extend_schema(
|
|
22
|
+
summary="Retrieve file metadata",
|
|
23
|
+
description="Returns the stored metadata and a newly signed download `url`.",
|
|
24
|
+
),
|
|
25
|
+
)
|
|
12
26
|
class FileUploadViewSet(CreateModelMixin, ListModelMixin, RetrieveModelMixin, GenericViewSet):
|
|
13
27
|
"""Upload (multipart), list and retrieve stored files.
|
|
14
28
|
|
|
@@ -24,6 +38,15 @@ class FileUploadViewSet(CreateModelMixin, ListModelMixin, RetrieveModelMixin, Ge
|
|
|
24
38
|
# explicit: every view must declare permission_classes (lint rule BE003).
|
|
25
39
|
permission_classes = [AllowAny]
|
|
26
40
|
|
|
27
|
-
@extend_schema(
|
|
41
|
+
@extend_schema(
|
|
42
|
+
operation_id="files_create",
|
|
43
|
+
summary="Upload a file",
|
|
44
|
+
description=(
|
|
45
|
+
"Send the binary as `multipart/form-data` on the `file` field. "
|
|
46
|
+
"`original_name`, `content_type` and `size` are derived server-side and "
|
|
47
|
+
"ignored if supplied. The response contains no binary — only metadata "
|
|
48
|
+
"and a presigned `url`."
|
|
49
|
+
),
|
|
50
|
+
)
|
|
28
51
|
def create(self, request, *args, **kwargs):
|
|
29
52
|
return super().create(request, *args, **kwargs)
|