-
Notifications
You must be signed in to change notification settings - Fork 87
Description
TL;DR
I propose to switch to OpenAPI (fka Swagger) for API documentation. I am willing to contribute to this effort, but we need to discuss if and how this should be pulled of before. I am aware of ajayyy/SponsorBlock#706.
Why switch?
I think the API and docs just grew as this project developed and there is nothing wrong with that. I think that a point is reached where a switch to OpenAPI would make sense. OpenAPI can not only provide the same information that the wiki page currently does, but also improve on it. There are also additional advantages to using this widely adopted standard that I will go into.
I am aware that there is an inofficial OpenAPI documentation as the result of ajayyy/SponsorBlock#706. But I think that this doesn't really get us anywhere. Besides the fact that this OpenAPI doc is unofficial, it is also hard to find. I only came across them by accident and only after a while and after starting my on draft. Because of that I think in the current situation this existing OpenAPI doc it is almost as good as none.
Advantages
You can read about the advantages of OpenAPI on the official website, but here are the main advantages that I see in this case.
- Better accessibility of the API
- raw spec instead of wiki page
- -> better accessible for machines
- -> better accessible for people e.g. via Swagger UI
- (even) nicer presentation than a wiki page
- allows to play around with an explore the API
- would allow for stuff that would be hard/tedious to squeeze into an wiki page (e.g. https://swagger.io/docs/specification/links/)
- Better docs
- less ambiguous than the current docs are, in some places
- more consistency/less "doc duplication"
- e.g. compare the "segments" data model returned by
/skipSegmentsand/skipSegments/:sha256HashPrefix. - The wiki shows two different models. In reality both responses use the same model.
- OpenAPI would just reuse the model in this case, reducing doc duplication and also preventing mistakes like this one.
- e.g. compare the "segments" data model returned by
- simpler way to version the api, deprecate stuff, etc.
- Code generation
- generate API clients for different languages
- generate server stubs for different languages
- e.g. https://github.com/swagger-api/swagger-codegen
- -> spend less time on boring boilerplate code and have more time for actual features
- -> less work for other developers that want to interact with SponsorBlock
I think code generation might have the biggest impact. It might be able to replace the manually written API client code in the web extension. And third party developers might be able to just go ahead use the API instead of writing their own code doing the tedious ground work first.
I'm not sure, if there is currently an generator suitable to the SponsorBlock server, but if not, there might be one in the future. It could also become handy if the server implementation is switched to a different language or reimplemented later on.
Options
In general there are two options on how the switch to OpenAPI could be done:
- Maintain docs separately
- Maintaining them completely separate is always possible. This would be the same kind of work, that currently happens in the wiki.
- There are also solutions, that allow you to put OpenAPI doc into doc blocks inside the code. This allows you for example, to document each API endpoint right above the exact function that will handle the corresponding request. This makes it easier to keep the docs up to date and check them against what's actually happening.
- One doc block solution that I played with is https://github.com/readmeio/oas. It works completely transparently and doesn't add any build dependency to the code itself, since it will just parse comments in the source code, completely independently from the build of the application
- Use a framework
- Frameworks for different languages are available. Many provide advantages like deducing API endpoints/parameters/data models/error codes from the actual code, completely removing the need to manually maintain this info. Some frameworks are also able to take care of some boilerplate code, providing you with already parsed request/response data and error handling.
I would like to contribute to this effort. As I said, I played around with a doc block based solution, and it worked just fine. I am not familiar with typescript, so I don't see myself diving into OpenAPI frameworks that could be used for this project. I want to discuss which approach should be pursued (or none at all) before I put too much work into it.