Add API documentation
This MR implements an auto-generated API documentation with drf-spectacular.
As the steering API uses a lot of subpath resources a few changes are necessary in order to make documentation feasible. As some of these changes are quite invasive (in the sense that they replace a lot of custom with generic logic) we should invest in a little bit of testing before this is merged.
Depending on the remaining time I can spent on this issue, I will implement these myself.
Possibly breaking changes in the external API:
-
APIException
objects are now converted to error lists in the form of[ { "message: "a message", "code": "an optional code" } ]
making them easier to handle for client code (see c9164158). This also affects the hard errors raised during schedule creation/updates. - Hard errors raised during schedule creation/updates now return a
400
HTTP status code instead of201
. - A schedule submitted as a dryrun now returns a
202
HTTP status code instead of201
. - The
note_id
property on a schedule collision object will always be present but may benull
. It was omitted in some cases. - The
error
property on a projected timeslot will always be present but may benull
. It was omitted in some cases.
Notes & Caveats:
- The serializers for the scheduling responses are only used for documentation purposes. The scheduling code should probably be refactored to actually depend on those serializers to generate API responses.
- Enums auto-generated by drf-spectacular come with no documentation even though the choices they are generated from may have some. This is the case for the
by_weekday
attribute of theSchedule
instance, as well as thesolution_choices
attribute ofCollisionSerializer
and thesolutions
attribute of theScheduleCreateUpdateRequestSerializer
. I’ve decided to manually patch the generated enums in post-processing as the context information provided by the choice descriptions seems vital to me. It might be a good idea to invest some time into drf-spectacular and send a pull-request upstream so that manual patching can be dropped as one might easily miss this when adding new or changing existing code. See steering/schema.py.
Merge request reports
Activity
added 1 commit
- c9164158 - feat: API errors now come with an optional code
added 5 commits
- 96347795 - fixup! refactor: implement consistent pk/slug retrieval for shows
- 89269076 - fix: raise ValidationError on invalid data
- addf232f - fix: always include API fields
- 6ee6a4e8 - fix: remove superfluous retrieve/update actions for APIUserViewSet
- 26e45d7a - fix: don’t restrict timeslot queryset on detail views
Toggle commit listadded 14 commits
-
26e45d7a...210d16d6 - 4 commits from branch
master
- a03f60a2 - fix: cba_id should be part of the serialized representation
- f7926bd9 - refactor: implement consistent pk/slug retrieval for shows
- 3507bbdb - refactor: move subroute filtering into viewset mixin
- ab4c64d2 - feat: API errors now come with an optional code
- 98dcfc5d - fix: raise ValidationError on invalid data
- 1b0a0ad5 - fix: always include API fields
- 0106797d - fix: remove superfluous retrieve/update actions for APIUserViewSet
- eb3f33ac - fix: don’t restrict timeslot queryset on detail views
- 09c8642b - feat: return schedule dry-runs with a separate status code
- 438d0245 - feat: add schema documentation with drf-spectacular
Toggle commit list-
26e45d7a...210d16d6 - 4 commits from branch
I keep having afterthoughts... :)
As stated in the MR description above I’d be nice to have some tests that execute successfully on the current default branch and run them against this branch. I’ve tested the endpoints, but given the scope of the changes I cannot guarantee I didn’t smuggle in breaking changes that I did not outline in my disclaimer.
mentioned in issue #103 (closed)
mentioned in issue #104 (closed)
mentioned in issue #105 (closed)
added 14 commits
-
21f4cfe2 - 1 commit from branch
master
- 0d695cf1 - fix: cba_id should be part of the serialized representation
- c650f609 - refactor: implement consistent pk/slug retrieval for shows
- a0e800d9 - refactor: move subroute filtering into viewset mixin
- 59219ebf - feat: API errors now come with an optional code
- e2cc7bb9 - fix: raise ValidationError on invalid data
- 78168ae2 - fix: always include API fields
- 5bc1f22b - fix: remove superfluous retrieve/update actions for APIUserViewSet
- 3c38698a - fix: don’t restrict timeslot queryset on detail views
- b82b0435 - feat: return schedule dry-runs with a separate status code
- edf2cf78 - feat: add new syntaxes for filtering by choices
- ec08012b - feat: add schema documentation with drf-spectacular
- 88595646 - CI: add autogenerated openapi.yaml file
- a5239bfb - fix: don’t enforce valid instance references in collection filters
Toggle commit list-
21f4cfe2 - 1 commit from branch
added 14 commits
- a03f60a2 - fix: cba_id should be part of the serialized representation
- f7926bd9 - refactor: implement consistent pk/slug retrieval for shows
- 3507bbdb - refactor: move subroute filtering into viewset mixin
- ab4c64d2 - feat: API errors now come with an optional code
- 98dcfc5d - fix: raise ValidationError on invalid data
- 1b0a0ad5 - fix: always include API fields
- 0106797d - fix: remove superfluous retrieve/update actions for APIUserViewSet
- eb3f33ac - fix: don’t restrict timeslot queryset on detail views
- 09c8642b - feat: return schedule dry-runs with a separate status code
- 673ee6d7 - feat: add new syntaxes for filtering by choices
- 2f71e281 - feat: add schema documentation with drf-spectacular
- a3ab02bf - CI: add autogenerated openapi.yaml file
- c217852f - Update Python bae image to the latest 3.9
- c1d1225e - Merge branch 'feature/api-docs' of ssh://gitlab.servus.at:22022/aura/steering into feature/api-docs
Toggle commit listmentioned in commit 6a9e9690