Repository navigation
Commit 810fc5f
committed
Make the generated API docs valid Swagger 2.0
The apidocs spec has been `pending 'Is not valid swagger at the moment'` for as
long as anyone remembers, so the document /api/v8/apidocs serves — the input to
swagger-ui and to any client generator pointed at it — has been free to drift.
Validating it against spec/resources/swagger-schema.json reported exactly three
errors, all of them malformed swagger metadata in controllers, none of them a
problem with the routes they describe.
Two path keys were missing their leading slash:
api/v8/exercises/{exercise_id}/users/{user_id}/submissions
api/v8/exercises/{exercise_id}/users/current/submissions
A Swagger 2.0 path key must begin with `/`; these two were the only offenders and
they were being dropped by tooling rather than merged with their siblings.
/api/v8/core/exercises/details declared its `ids` query parameter with a nested
`schema`. Only a body parameter may carry `schema`; every other location describes
its type inline, and an array must supply `items`. The parameter already had a
redundant `type: :array` next to the schema, so the fix is to keep that and move
`items` up beside it. `collectionFormat: csv` is now explicit because the action
reads the value with `split(',')`.
/api/v8/users/get_user_with_email had a query string embedded in its path key,
`/api/v8/users/get_user_with_email?email={email}`, and a `content` key in its 200
response, which is OpenAPI 3 and is not allowed in a Swagger 2.0 response object.
The route itself is fine — `get :get_user_with_email, on: :collection`, and the
action reads `params[:email]` — so the endpoint is unchanged and only its
description is corrected: the path key loses the query string and `email` becomes a
query parameter. That also fixes two dangling `$ref`s found while doing it. The
referenced `#/parameters/user_email` was never defined (the definition was named
`path_user_email`), so the parameter was silently absent from the rendered docs
altogether; it is now `query_user_email`, `in: query`, named `email` to match the
action. set_password_managed_by_courses_mooc_fi referenced a non-existent
`#/parameters/user_id` the same way and now points at `path_user_id`.
With those fixed the document validates, so the spec becomes a real test instead of
a pending one — the point of keeping it is that it now stops this from regressing.
It reports through `fully_validate` rather than the boolean `validate` so a future
failure names the offending property instead of just saying `false` is not truthy.
A second example asserts no path key contains a `?`. The Swagger 2.0 JSON schema
matches path keys with `^/` only, so it accepted the get_user_with_email key and
flagged just the `content` alongside it; without this assertion the exact defect
that was fixed above could come back unnoticed.1 parent b9e3c5c commit 810fc5f
5 files changed
Lines changed: 25 additions & 19 deletions
File tree
- app/controllers/api/v8
- core/exercises
- exercises/users
- spec/controllers/api/v8
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
66 | | - | |
67 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
27 | 25 | | |
28 | 26 | | |
29 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
91 | 90 | | |
92 | 91 | | |
93 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
13 | | - | |
14 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
15 | 24 | | |
16 | 25 | | |
0 commit comments