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

Improve API documentation #168

Open
Nutomic opened this issue Apr 14, 2023 · 6 comments
Open

Improve API documentation #168

Nutomic opened this issue Apr 14, 2023 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@Nutomic
Copy link
Member

Nutomic commented Apr 14, 2023

This seems to be the best option for API docs that I can find: https://github.com/juhaku/utoipa

It doesnt support the the pattern with Perform trait for API handlers. This pattern also doesnt serve any purpose in our code as far as I can tell, so I will get rid of it and use simple handler methods instead.

Another disadvantage is that we will have to specify the path separately in utoipa annotations, so the path needs to be present on the method itself, and in api_routes_http.rs. Unfortunately there seems to be no good alternative.

@Nutomic Nutomic added the enhancement New feature or request label Apr 14, 2023
@Nutomic Nutomic self-assigned this Apr 14, 2023
@Nutomic
Copy link
Member Author

Nutomic commented Apr 15, 2023

Unfortunately I was wrong, the Perform traits are absolutely necessary so that the same API handlers can be used for HTTP and websocket. Thats because HTTP handlers need to return HttpResponse, but websocket requires plain json structs. There might be another solution by using middleware to rewrite the responses, and that way use API handlers that work with utoipa documentation macros. But thats probably not worth the effort.

So I think the better solution to document the HTTP API would be to generate docs in lemmy-js-client, like we are already doing for websocket. It already has the necessary data (structs, HTTP methods and paths). What do you think @dessalines?

@dessalines
Copy link
Member

Yes, I prefer the existing lemmy-js-client docs anyway. Those are already auto-generated from its codebase, here: https://join-lemmy.org/api/

@Nutomic
Copy link
Member Author

Nutomic commented Apr 16, 2023

The current API docs are fine, but they are only for websocket. They arent useful at all if you want to use the HTTP api, because HTTP methods or paths arent mentioned. So when building LemmyBB I had to look these things up in the source code. This is not an option for people who are not familiar with Rust, and makes it unnecessarily difficult to develop Lemmy clients. Everyone is familiar with HTTP, and is unlikely to learn websocket for a simple project. Thats why I believe we need two sets of API documentation, one for websocket and one for HTTP.

@dessalines
Copy link
Member

The paths and methods are mentioned, here's an example:

https://join-lemmy.org/api/classes/LemmyHttp.html#likePost

@Nutomic Nutomic transferred this issue from LemmyNet/lemmy Apr 17, 2023
@Nutomic Nutomic changed the title Add utoipa for API documentation Improve API documentation Apr 17, 2023
@Nutomic
Copy link
Member Author

Nutomic commented Apr 17, 2023

Oh thats very easy to miss, I didnt notice that at all before. Can we change the color scheme to emphasize it? Or even switch to a different frontend? The one used by Peertube looks very nice.

@dessalines
Copy link
Member

I'd rather not add anything too custom, but typedoc does look like its supports some pre-made themes: https://typedoc.org/guides/themes/

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

No branches or pull requests

2 participants