I am creating this topic so that we can have good documentation for all REST API endpoints which are currently available in the open edX platform.
Where can I find the REST API endpoint for user creation?
I have seen this question very often on the discussion forum and on the slack channels. And yes, we have an endpoint for this.
Normally when anyone lookup for the API for open edX they (or me) end up with this link: https://courses.edx.org/api-docs/. This link has APIs listed but some of the endpoints are missing (for example user_api/v1/account/registration/).
The foundation for the API documentation was laid by @nedbat
I have gone through this PR which was merged previously but in open-release/juniper.master some of the changes made with this PR are removed (Don’t know why!).
In the last, I would say that it will be nice if we can have all the REST API endpoints under one roof (centralized).
I think we can start like this:
Create new doc which will have endpoint, method, description (if we have), codebase location
By codebase location, developers or maintainers will be able to get the required body parameters
Then gradually we can add the body parameters and can go on if everything goes well
People, please suggest if you have any good ideas about this.
Thanks for bringing this up. I would love to see more movement on this. I’m personally disappointed that I couldn’t make more progress.
What do you mean by “create new doc”? I’m strongly in favor of putting the words near the code, and using tooling to collect them and publish them. Are you thinking of something different than that?
(For background information: @jramnai came to the meetup of the BTR working group and mentioned this issue. I suggested that I could help fix it himself and get the fix merged upstream.)
What you need to do is to generate a new docs/swagger.yaml file that contains the documentation for the endpoints that you are interested in. To generate this file, run:
Once this file has been generated, it will be converted to human-readable documentation by the following command, which is part of make api-docs-sphinx:
So, basically, you need to figure out WHY the /user_api/v1/account/registration endpoint is not included in swagger.yaml, while the /api/user/v1/me is, for instance.
It appears that this generator returns only endpoints which start with “/api”. By setting a breakpoint in the get_endpoints method (with import pdb; pdb.set_trace()) we can observe that “/user_api/v1/account/registration/” is in endpoints, but not in subpoints.
Do you start to see the underlying issue @jramnai? Do you understand how to resolve it?
No, I am not thinking other than that but by “create new doc” my meaning was to include the remaining endpoints and generate the new doc.
Yes, we need to change the get_endpoints method in such a way that it should return all the API endpoints not only which starts with “/api/” (correct me if I am wrong here)
The goal was to only document /api/, and for other endpoints that should be documented, add an “alias” in /api/ so that they would be available in a unified namespace.
Yes, something along those lines. I would also change the name of the deprecated url to something like “user_api_registration_legacy”.
You should do the same for the “user_api/v1/account/login_session/” url.
Please test those changes and see if they work (i.e: modify the swagger.yaml file). If yes, then you should be ready to open a PR.
Yes @regis, I am testing the changes. But I think we should not change its name as it is being used in many test cases and here, too.
I tried this with debugger and get_endpoints method is not returning 24 API endpoints 'cause they do not start with /api/. By adding alias we will have registration and login_session API endpoints in the API documentation but what about the rest of endpoints?
If we do not have any strong reason to keep startswith /api/ condition in get_endpoints method then we should remove it and then it will return all the endpoints. But this will affect the unified namespace.
@nedbat & @regis, let me know your thoughts on above.
We want the REST API to become more uniform and disciplined. Insisting on the /api/ namespace is one way to do that. The REST API Conventions clearly indicate using the /api/ namespace.
I understand. My point was that the new url should have the “user_api_registration” while the older url should be renamed to “user_api_registration_legacy”. That way, all calls to reverse("user_api_registration") will point to the new url – which is good.
As Ned explained, we do want all API urls to start with /api. If you are interested in documenting some of these endpoints, then you can apply the same procedure for those endpoints. All those changes can go in a single pull request.
@jramnai: Does that answer your questions? Do you have what it takes to proceed with opening a PR?