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
OpenAPI documentation generation with rswag specs #20572
Comments
|
Agreed, this would make development easier and more accessible and would give us an accurate API. |
|
Another huge advantage would be auto-generated, testable (!) documentation (i.e. its examples are tested as well). I agree that generating a spec, especially for an publicly interesting application such as Mastodon, should be considered an industry best practice, and it’d be vital to its continued success and to maintain relevance. Previous attempts at creating a general spec (OpenAPI/Swagger) were met with disinterested by the core folks (as late as 2021, so before I’d touch any code regarding this (assuming we’d be using
Anything below that threshold, given the busy nature of this project, is just not realistic. |
|
Duplicate of #1404 ? But I agree this is badly needed. Thanks for the detailed write-up. |
|
I agree with all you state. Especially to:
And
I'd specify that outsiders like me could do the start-up effort, until the current spec has a more or less complete coverage of the existing API's. I created a draft PR #20607 in order to clarify a bit what I have in mind. Demonstrate intention with: |
|
I'd say they're very overlapping, one is just more implementation specific, but the important thing is just to ensure there's no duplicate work and that both issues are closed if a solution is implemented. |
|
@ineffyble fair enough. I did see that issue before I created mine. I did not identify my intend in that issue, so I created a new one. If it were my issue board, I'd close an issue inactive since 2017 in 2022 in any case. Regardless if it is a duplicate or what not. But that is off topic here ;) |
in case it's useful, the draft/demo OpenApi definition above can be browsed at ReDoc |
Nice. Thx! There is a newer version of the schema in the pr now though. |
|
I have been diving into Mastodon recently, and I recently wrote a blog post showing how we can use AppMap to record the Mastodon tests, and then we can use that data to export the API documentation based on the code's runtime. https://dev.to/appmap/automatically-generating-openapi-docs-for-mastodon-42ig The benefit here is that we don't need to add additional code with rswag, we can simply use the existing API rspec tests and output their usage to OpenAPI. |
|
Hello @petecheslock
This looks very interesting. If I'm not mistaken, your approach is to extract the schema from the debuggers call stack, when the specs are running? That sounds quite nice, and could potentially save a lot of work, writing OpenAPI docs manually. On the other hand, though, a few things come to my mind:
Please tell me, if you think my assumptions are right or wrong, and how you see these aspects. Combine the approachesProvided a rswag specs generated OpenAPI schema is more accurate, detailed and is an actual contract verification, but will be a lot of work to write: How about documenting everything that rswag did not yet cover, with the generated approach, and fill in the better quality docs with rswag specs step by step? |
This aims to be a complete specification and source of truth for how the endpoint behaves. It specifies the responses in both happy and sad paths, error handling, and authentication and authorization handling. Use JSON-schema definitions to validate the API responses via `match_json_schema` added in mastodon#21395. There is some repeated code and abstractions here. The next step is to extract [RSpec shared_examples](https://relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples) to DRY. Another option to consider is moving towards the [`rswag` gem](https://github.com/rswag/rswag) per issue mastodon#20572.
|
Was this closed because it was resolved? 🤔 |
Nah. I don't know how to close my issue without GitHub marking it as such. I just did not want to leave any trash behind, when I decided not to contribute that RSwag OpenAPI docs thing. |
Pitch
Create a generated OpenAPI documentation using the rswag gem.
This gem allows to not only generate the OpenAPI schema by writing special rswag request specs. It also allows generating the documentation OpenAPI schema, using exactly these specs.
Motivation
The only documentation I can find on API responses, seems to be things like the entities section (e.g. Account in account.md).
This is not what I'd expect to find, when I'm looking for a proper API documentation.
If I were to start writing any kind of application consuming the mastodon API's, I'd ask for a valid and up to date OpenAPI schema as the first thing.
With a valid OpenAPI-Schema, I can:
With the current api documentation in mastodon/documentation I can't:
Demonstrate intention
ReDoc Rendering of the schema
Duplicate or not
Some may see this issue as a duplicate of #1404
I, personally, don't see is as that, as long as the other issue doesn't specify the use of rswag and testing of the OpenAPI schema against the endpoints.
The text was updated successfully, but these errors were encountered: