Create an OpenAPI contribution guide
We are working on creating a complete autogenerated OpenAPI documentation. Currently, there is no contribution guide. This issue is about collecting best practices and compiling them into a contribution guide.
The guide can be added to https://docs.gitlab.com/ee/development/documentation/restful_api_styleguide.html
Related conversation: &8926 (comment 1151742900)
API annotations.
This is an example of an issue description that lining out steps to be done to update the annotation of an endpoint:
For the API::Search endpoint, we have to:
- Check the
API::Searchclass and:
- Check if the parameter documentation needs to be updated
- Check if the description block needs to be updated. Ideally this should include a
successentry. Specifying a model likesuccess Entities::EntityNamewill work. If you want to add more details, you can use a hash like in this example.
- If the endpoint responds with an Array, use the
is_array truehelper.- Compare the parameters and description to the markdown documentation for this endpoint
- Optionally add a tag to the description. (example)
- Add the endpoint to the OpenApiV2 documentation by modifying
lib/api/api.rband movingmount Searchinto the other namespace, next toadd_open_api_documentation!- Run
rake gitlab:openapi:generate- Review changes in
doc/api/openapi/openapi_v2.yaml. You can check the content of the file by pasting it into https://editor.swagger.io. Errors will be shown on the left side.- Please do not commit the changes in
doc/api/openapi/openapi_v2.yaml. Many teams will work on this in parallel. To avoid conflicts, we will try to have only one MR modifying the file at a time.@elim-extor@Andysoironwill create a new MR with the latest updates every few days.- Commit the other changes and create an MR.
📺 Video guide
https://www.youtube.com/watch?v=V1hUlFOBbYY
Example MRs
Edge cases
Edge cases are collected in &8926 (comment 1127618337)
Do not document 5XX error codes
5XX error codes shouldn't be documented because we shouldn't be returning explicit 5XX errors, and clients have to assume that a server could return any 5XX error - they are, after all, server errors
How to document 4XX error codes
4XX codes seem to be very generic. Most endpoints will be able to respond with a 404 error. We can add a section about how to document those, or add a helper that adds the documentation automatically.