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

Epic: automate openapi spec generation and synchronization #3676

Closed
1 of 5 tasks
LizardWizzard opened this issue Feb 22, 2023 · 6 comments
Closed
1 of 5 tasks

Epic: automate openapi spec generation and synchronization #3676

LizardWizzard opened this issue Feb 22, 2023 · 6 comments
Assignees
Labels
c/storage Component: storage t/Epic Issue type: Epic

Comments

@LizardWizzard
Copy link
Contributor

LizardWizzard commented Feb 22, 2023

Motivation

For components written in rust (mainly pageserver and safekeeper, but soon proxy as well) we have http apis which are documented by manually writing openapi specs for them.
Manual spec maintenance leads to several problems. Code and spec can diverge. E g #3669

Additionally these specs are used in different repo (cloud) and there is no checks that spec is up to date, so it can diverge from time to time.

DoD

  • Spec file is generated automatically from annotations on request handlers
  • CI integration to raise warnings when spec changes (similar to backwards compatibility test we have). This is useful for indication when spec needs to be updated in other repos

Implementation ideas

There are several libraries that fulfill the goal of the first step.

1. Poem

https://github.com/poem-web/poem

Is is a different web micro framework build on top of hyper. It has builtin support for openapi spec generation https://github.com/poem-web/poem/tree/master/poem-openapi

2. Utoipa

https://github.com/juhaku/utoipa

Utoipa follows different strategy, instead of being a web framework it is a library that has support for most popular web frameworks. And our current configuration of routerify + hyper is not in the list of supported integrations. Probably makes sense to shift to axum or warp then. The syntax for annotations is also a bit different from poem.

3. Paperclip

https://paperclip-rs.github.io/paperclip/

The project has wider scope, it includes an ability to generate type-safe clients for provided openapi spec. For framework integration it supports only actix.

Tasks

Preview Give feedback
  1. a/ci a/test c/storage/pageserver

Other related tasks and Epics

@LizardWizzard LizardWizzard added t/Epic Issue type: Epic c/storage Component: storage labels Feb 22, 2023
@SomeoneToIgnore
Copy link
Contributor

Code and spec can diverge

To note, we have a few HTTP methods that have the working Rust code, but are not deliberately added into the openapi spec file, e.g. eviction API: #3486 (comment)

Either the tool has to allow such exceptions, or we have to think of a better way to gate our new, unfinished management API methods.

@LizardWizzard
Copy link
Contributor Author

I think partially the reason they're not added is the hassle to properly document them. To me its ok to have them documented, but we can keep them under some unstable prefix/suffix so it is clear that these methods do not provide backwards compatibility guarantees.

I the the following use case: Clients we use for tests can be autogenerated from the spec, and in those clients its reasonable to have access to this kind of testing/unstable endpoints

@LizardWizzard
Copy link
Contributor Author

Tried poem, it uses its own set of traits to define types of parameters, even request/response bodies are not using serde types, so I had to manually implement a bunch of traits for our types like tenant ids.

Next step is to try utoipa + axum. Combination of axum + tower_http is quite promising, tower_http has many useful middleware for observability so we can avoid our own hacks to have per handler spans

@LizardWizzard
Copy link
Contributor Author

Discovered that poem has tower compatibility: https://github.com/poem-web/poem/blob/10de9d11daceed3def451999ea8496b636f7d1b2/examples/poem/tower-layer/src/main.rs#L2 So may work with tower_http

@LizardWizzard
Copy link
Contributor Author

Here is my analysis:

https://github.com/LizardWizzard/rust_openapi_playground

So to me poem's strict typing gives it a huge advantage over utoipa

@LizardWizzard
Copy link
Contributor Author

related #1297

Last time we discussed it the conclusion was that some time in the future we'd rather switch to grpc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/storage Component: storage t/Epic Issue type: Epic
Projects
None yet
Development

No branches or pull requests

2 participants