oasgen icon indicating copy to clipboard operation
oasgen copied to clipboard

Support status codes with axum

Open musjj opened this issue 1 year ago • 2 comments

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))
}

musjj avatar Sep 20 '24 20:09 musjj

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.

kurtbuilds avatar Sep 20 '24 21:09 kurtbuilds

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

jocutajar avatar Feb 01 '25 22:02 jocutajar