WeblateOrg / weblate

Web based localization tool with tight version control integration.
https://weblate.org/
GNU General Public License v3.0
4.65k stars 1.02k forks source link

Describe the Weblate REST API with OpenAPI #12584

Open walpox opened 2 months ago

walpox commented 2 months ago

Describe the problem

There is not a problem to solve per se. The current API documentation is good. In my opinion, the proposed OpenAPI standard might be an improvement upon such documentation.

Describe the solution you would like

OpenAPI (formerly known as Swagger) is one of the most popular specifications to describe REST APIs formally. It allows developers to define the entire Weblate REST API with a root OpenAPI document.

Some advantages this standard might offer over the current API documentation are:

Describe alternatives you have considered

No response

Screenshots

This is how the Weblate REST API looks in Swagger UI:

Click to show image

In Sphinx with sphinxcontrib-openapi:

Click to show image

In Sphinx with sphinxcontrib-redoc:

Click to show image

Additional context

Compared to Swagger UI, the Sphinx plugins are missing information and seem to work worse. If we can get drf_spectacular to work with Weblate, it should be possible to offer the OpenAPI document programmatically and letting people use it as they please.

nijel commented 2 months ago

https://github.com/WeblateOrg/weblate/pull/12612 integrates drf-spectacular to Weblate. This gives some OpenAPI schema, but it is very likely incomplete and needs additional annotations to make it really a replacement for the current documentation. But I think it's the correct direction that will allow us to discard manually maintained documentation in the future.

nijel commented 1 month ago

https://github.com/WeblateOrg/weblate/pull/12612 has been just merged. I would appreciate it if you could compare what you've manually crafted in https://github.com/WeblateOrg/weblate/pull/12585 to what it generates. We then need to customize the generated schema to match the reality.

nijel commented 1 month ago

I've made some cleanups in https://github.com/WeblateOrg/weblate/pull/12645 and https://github.com/WeblateOrg/weblate/pull/12644, but there is still a lot to review and fix.

nijel commented 1 month ago

I've also added CI action to lint - https://github.com/WeblateOrg/weblate/actions/workflows/api.yml. It shows quite some errors and warnings for now: https://github.com/WeblateOrg/weblate/actions/runs/11126455162