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

docs(openapi): Proposal for better OpenAPI definitions #242

Merged
merged 7 commits into from
Dec 21, 2023

Conversation

jvallesm
Copy link
Collaborator

@jvallesm jvallesm commented Dec 19, 2023

Because

  • OpenAPI docs are poorly documented and hard to read.

This PR

  • Hides all unclear endpoints by setting their visibility to INTERNAL.
    • Previous definition is kept temporarily under openapiv2/internal.
  • Improves comments and adds options such as tags, responses, etc., to the vdp.pipeline.v1beta.PipelinePrivateService proto definition as a proposal for an OpenAPI document template.
  • Adds github actions to generate and lint the OpenAPI definitions as part of the CI/CD.

Notes and questions

  • ❓ From which point of view are we documenting these endpoints? From the gateway, public endpoints are prefixed by /vdp, /internal, /core, etc., so I doubt these definitions can be direclty transformed to cURL request (or that working code can be generated from them).
    • If we want different hosts (or base paths), we'll need one OpenAPI document per service. This can be easily done with buf generate --path {}, but it will change how we render the definitions. Something to keep in mind for the future, probably for beta this is enough.
  • docs(openapi): improve OpenAPI documentation #147 was checked along the documentation process, though only some of its changes made it to this PR.
    • There's a script there modifying some path parameters (e.g. pipelinePermalink becomes pipelines/permalink). I think this approach makes the proto -> openAPI translation unclear(er), hiding behind some undocumented rules. Therefore, I only used what googleapis and gprc-gateway provide.
  • I'm not the most knowledgeable about Instill's domain, so any feedback regarding documentation is welcome!
  • Not an expert on GHA either, feel free to suggest improvements.

Old vs new documentation

Generated with redocly preview-docs:

Old 👺

CleanShot 2023-12-20 at 19 36 54

New 👶

CleanShot 2023-12-20 at 19 36 13

In proto, a zero value with the `[TYPE]_UNSPECIFIED` name is required
for all enums. In OpenAPI, however, this isn't required and only adds
verbosity. Outputting these values is disabled until a case is found
where the zero value can be returned or carries meaning.
The visibility option is used to hide endpoints from the OpenAPI output.
They will start having visibility as they are aligned with the
documentation template provided in the following commits.
@jvallesm jvallesm self-assigned this Dec 19, 2023
Copy link

linear bot commented Dec 19, 2023

@jvallesm jvallesm changed the title Improve OpenAPI docs / vdp.pipeline.v1beta.PipelinePrivateService fix: improve OpenAPI docs / vdp.pipeline.v1beta.PipelinePrivateService Dec 19, 2023
@jvallesm jvallesm changed the title fix: improve OpenAPI docs / vdp.pipeline.v1beta.PipelinePrivateService feat: Proposal for OpenAPI docs template Dec 19, 2023
@jvallesm jvallesm changed the title feat: Proposal for OpenAPI docs template docs(openapi): Proposal for better OpenAPI definitions Dec 19, 2023
@jvallesm jvallesm force-pushed the jvalles/ins-3014-improve-comments-in-protobuf-repo branch 20 times, most recently from a7eeec8 to adf4283 Compare December 20, 2023 11:34
The base-level information of the OpenAPI document must contain a
license field if we want to apply linting to the document.
@jvallesm jvallesm force-pushed the jvalles/ins-3014-improve-comments-in-protobuf-repo branch 2 times, most recently from 2fc6da8 to a183c7e Compare December 20, 2023 17:27
@jvallesm jvallesm force-pushed the jvalles/ins-3014-improve-comments-in-protobuf-repo branch 5 times, most recently from 7f5c6fe to 47b6025 Compare December 20, 2023 18:01
When a pull request is created, a GHA workflow will generate the OpenAPI
definitions, which will be linted and pushed to the source branch if
anything in the definition has changed.

fix
The OpenAPI definitions for endpoints that haven't been corrected yet
are still useful, though maybe not ready for public visibility. An
internal OpenAPI document is generated to preserve these definitions.
@jvallesm jvallesm force-pushed the jvalles/ins-3014-improve-comments-in-protobuf-repo branch from fcf8a5d to abe45ec Compare December 20, 2023 18:23
@jvallesm jvallesm marked this pull request as ready for review December 20, 2023 18:38
@donch1989
Copy link
Member

The PR looks good to me.

❓ From which point of view are we documenting these endpoints? From the gateway, public endpoints are prefixed by /vdp, /internal, /core, etc., so I doubt these definitions can be direclty transformed to cURL request (or that working code can be generated from them).
If we want different hosts (or base paths), we'll need one OpenAPI document per service. This can be easily done with buf generate --path {}, but it will change how we render the definitions. Something to keep in mind for the future, probably for beta this is enough.

The API endpoints should be exposed from the gateway perspective. So in my understanding, there are two approaches

  1. One OpenAPI document, but we need to find a way to fix the prefix problem
  2. Three OpenAPI documents, we can easily generate the correct path.

I think three OpenAI document is fine for beta. Not sure what does @pinglin and @xiaofei-du think

BTW, we are planning to make our OpenAPI document hosted by https://readme.com/ .

@jvallesm
Copy link
Collaborator Author

The API endpoints should be exposed from the gateway perspective.

I do agree, but then all the Private services would need their own document as they aren't exposed through the gateway (if I understood the configuration correctly) and probably they have their own authentication.

I'll have a quick look at how to modify the public endpoints' base path. If there's no straightforward solution, I agree this is good enough for beta 🤝 .

@jvallesm jvallesm merged commit c5d89f4 into main Dec 21, 2023
3 checks passed
@jvallesm jvallesm deleted the jvalles/ins-3014-improve-comments-in-protobuf-repo branch December 21, 2023 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: 👋 Done
Development

Successfully merging this pull request may close these issues.

3 participants