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

Documenting API using Swagger / rswag #3107

Open
mmd-osm opened this issue Feb 18, 2021 · 5 comments
Open

Documenting API using Swagger / rswag #3107

mmd-osm opened this issue Feb 18, 2021 · 5 comments
Labels
api Related to the XML or JSON APIs dx Developer Experience enhancement Improvements and new feature requests

Comments

@mmd-osm
Copy link
Collaborator

mmd-osm commented Feb 18, 2021

Documenting APIs on the WIki (https://wiki.openstreetmap.org/wiki/API_v0.6) has a few issues: it isn't maintained consistently, it's not considered authoritative by any means, and not easily consumable.

I looked at rswag as a way to include API documentation right inside this repo, along with a nice UI to test endpoints and a much easier way for API consumers to generate their own code based on the OAS3 spec that comes along with it.

I'm just posting a few screenshots how this could look like. It's mostly auto-generated content that can be enhanced by additional details/descriptions/error status code lists/examples, etc. Maybe this is even good enough to get rid of the Wiki page altogether and direct developers to the swagger docs instead.

A list of API 0.6 endpoints, as served via http://localhost:3000/api-docs/index.html

sw1

Testing the /api/capabilities endpoints in the browser

sw2

@simonpoole
Copy link
Contributor

Being the victim of absolute hopeless swagger generated documentation before (for example maproulette), it is important to note that it is just a system to semi-automatically generate good-looking documentation, not good documentation.

The later still requires significant effort regardless of the system. Given that

  • the rails port has essentially no code documentation at all
  • moving the API documentation from the wiki to the rails port would put the onus on the current maintainers (but see above)
  • and significantly raise the bar for contributing to it

I suspect that however well intentioned this is, it basically boils down to not documenting actual current behaviour of the API at all.

The other aspect is that, while a matter of contention among the maintainers and original rails-port devs, you could argue that the API should be specific implementation independent, and as a consequence as a matter of principle the documentation should be independent of any such implementation.

@tomhughes
Copy link
Member

Yes I'm not convinced about the wisdom of documenting the API in this repository when most of it (at least as used in production) isn't actually implemented here.

@mmd-osm
Copy link
Collaborator Author

mmd-osm commented Feb 19, 2021

moving the API documentation from the wiki to the rails port would put the onus on the current maintainers (but see above)

Valid point, I also thought about it and came to the following conclusion: OSMF board again has expressed their willingness to fund topics like "Andy Allan's "room by room" renovation - API overhauling" by having a "part-time maintainer to assist Andy Allan.". While people in this repo may find it difficult to grasp what exactly they mean by API overhauling, we should definitively leverage the momentum on the API topic.

I believe getting a new paid resource up to speed by improving documentation has a number of benefits:

  • Good way to get familiar with the existing Rails code base
  • Clear task with no impact on existing code base (-> less effort for maintainers to review potentially breaking pull requests)
  • Better documentation would improve overall developer experience

I think @gravitystorm would agree that Rails port will continue to be the center of gravity for functional requirements, database table definitions and a reference implementation, regardless of what we're doing in production.

@tuckerrc tuckerrc added api Related to the XML or JSON APIs dx Developer Experience enhancement Improvements and new feature requests labels Feb 19, 2021
@gravitystorm
Copy link
Collaborator

I think @gravitystorm would agree that Rails port will continue to be the center of gravity for functional requirements, database table definitions and a reference implementation, regardless of what we're doing in production.

Yep, I would agree with that whole-heartedly. I also have plans to make this codebase (slightly) more performant, which will reduce the need for some deployments to add cgimap. So even if OSMF don't use some of the API calls in production, other installations will continue to do so.

"part-time maintainer to assist Andy Allan."

Thanks for pointing this out; I haven't been involved in any of the discussions but I suspect this has been more focussed on OSMF budget opportunities rather than actually progressing it yet.

The later still requires significant effort regardless of the system.

@simonpoole I'm not familiar with swagger or the maproulette documentation. Could you give some idea here as to what else would be involved? Is it inline controller method documentation, or more, or something else? Do you have any links to good/bad examples?

I'm quite happy to have the documentation here in the repo, preferably near the code but I'd rather it was under source control than in a free-for-all.

Testing the /api/capabilities endpoints in the browser

@mmd-osm Is it just get requests that can be tested? I'm concerned because other systems I'm more familiar with that allow online testing like this either have a 'test mode' API, or it's only your own account that you can mess up by playing around while logged in. On the flip side, if all you can test are get requests, it becomes a bit less interesting! Do you have any details on this?

@tomhughes tomhughes changed the title [💡] Documenting API using Swagger / rswag Documenting API using Swagger / rswag Mar 3, 2021
@mmd-osm
Copy link
Collaborator Author

mmd-osm commented Mar 4, 2021

Is it just get requests that can be tested? I'm concerned because other systems I'm more familiar with that allow online testing like this either have a 'test mode' API, or it's only your own account that you can mess up by playing around while logged in. On the flip side, if all you can test are get requests, it becomes a bit less interesting! Do you have any details on this?

You can spin up a Swagger Petstore test frontend at https://editor.swagger.io/ and try out common HTTP verbs (GET, POST, PUT, PATCH, DELETE, ...) + authorization to get some idea how this works. For testing purposes, a few endpoints could be included, such as http://localhost:3000 and https://master.apis.dev.openstreetmap.org/. Users can then try things out using their own credentials.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to the XML or JSON APIs dx Developer Experience enhancement Improvements and new feature requests
Projects
None yet
Development

No branches or pull requests

5 participants