oasgen
oasgen copied to clipboard
Support status codes with axum
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))
}
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.
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