Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add openapi spec for weblate rest api #12585

Closed
wants to merge 2 commits into from

Conversation

walpox
Copy link

@walpox walpox commented Sep 24, 2024

Changelog

The format is based on Keep a Changelog.

Added

  • OpenAPI document describing the Weblate REST API.

Proposed changes

It closes #12584 .

Checklist

  • Lint and unit tests pass locally with my changes.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added documentation to describe my feature.
  • I have squashed my commits into logic units.
  • I have described the changes in the commit messages.

Other information

I tried to use a tool called drf-spectacular to generate the OpenAPI document automatically from Weblate's source code, but it didn't work for me at all, so I decided to do it manually with information gathered from testing (with Weblate v5.7.2 instances) and from what is already written in the API documentation.

The OpenAPI document shows fine in my local Swagger UI installation, as shown in the screenshot in the linked issue.

I don't think the PR is ready yet. The OpenAPI document is missing:

  • Response bodies operations such as POST, PUT and PATCH. In the operations where the body is present, it usually has only the mandatory properties documented, excluding the optional properties you can set for a resource.
  • A few #TODOs in the documents.
  • Some response codes for operations are missing the appropriate response from the server and are using generic response template instead.

I'm happy to discuss further changes to do here.

@walpox
Copy link
Author

walpox commented Sep 25, 2024

Note: my local Swagger UI container takes between 2.5 and 7 minutes to load the entire Weblate specification, with around 270 XHR requests. This is probably caused by the high number of $refs in the documents to keep things organized and DRY.

@nijel
Copy link
Member

nijel commented Sep 25, 2024

Thanks!

The annoying part of API documentation is keeping it in sync with code. It is easy to miss updating the list of fields in the docs when adding one to the serializer. Having a way to validate DRF implementation against docs would be great. Do you think something like that would be possible with OpenAPI when we decide to maintain it manually?

Maybe drf-spectacular would be a better approach in the end, so that all this can be generated (I guess some additional annotation in the code is needed for that)?

Also, have looked at options of integrating this into our existing documentation?

@walpox
Copy link
Author

walpox commented Sep 26, 2024

I agree that using an automated tool such as drf_spectacular is better in the long term for maintainability of the API documentation. Unfortunately, I couldn't get this tool to work in my local environment with Weblate code: it kept throwing exceptions.

I have tested the OpenAPI document in this PR with two Sphinx plugins and uploaded the corresponding screenshots in the linked issue. They are both a worse experience that Swagger UI... Still, if we can get drf_spectacular to work, we could use it to generate an OpenAPI document and link it in the regular API documentation. Like this:

download-weblate-openapi

That way, at least the OpenAPI document would be up to date with Weblate code, even if the API document page is not.

@walpox
Copy link
Author

walpox commented Sep 26, 2024

I'm closing this PR until I have enough Python experience to fix the issue with drf_spectacular to generate OpenAPI documents from Weblate source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Describe the Weblate REST API with OpenAPI
2 participants