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

Support status codes with axum #23

Open
musjj opened this issue Sep 20, 2024 · 2 comments
Open

Support status codes with axum #23

musjj opened this issue Sep 20, 2024 · 2 comments

Comments

@musjj
Copy link

musjj commented Sep 20, 2024

Is it possible to use status codes with oasgen and have it automatically generate the appropriate openapi attributes?

async fn create_foo(Json(payload): Json<Foo>) -> impl IntoResponse {
    ...

    (StatusCode::CREATED, Json(payload))
}
@kurtbuilds
Copy link
Owner

Right now it doesn't, but I'd welcome a PR to implement this. The working fallback is to access/modify the OpenAPI object at runtime.

@jocutajar
Copy link

It's possible to programmatically modify the docs:

let mut server = Server::axum().post("/send-code", send_code);
    for (route, method, op) in server.openapi.operations_mut() {
        op.responses
            .responses
            .insert(StatusCode::Code(205), RefOr::Item(Response::default()));
    }

you could use tags to that effect - tag the operation "returns205", detect it in this loop and change the responses accordingly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants