GREsau / GREsau/okapi

Derive OpenApiResponderInner for #[derive(Responder)] enums

Open
#146 1 comment 2 reactions 0 assignees View on GitHub
enhancement rocket-okapi-codegen
Dominant language
Rust
Stars
740
Forks
127
PR merge metrics
No merged PRs in 30d

Description

Using this feature https://github.com/rwf2/Rocket/issues/590 results in `the trait bound '[...] rocket_okapi::response::OpenApiResponderInner' is not satisfied` when the enum type is as a result type in a `#[openapi]` endpoint function.

It would be great if #[openapi] or similar could be used on an enum deriving Responder to also derive the appropriate forwarding OpenApiResponderInner implementation for the enum.

Example:
```
#[openapi] // inserting okapi openapi or derive macro here?
#[derive(Responder)]
enum MyResponse {
Person(Json), // 200, json object
Nothing(NoContent), // 204, no content
}

```
Should generate:
```
impl rocket_okapi::response::OpenApiResponderInner for MyResponse {
fn responses(
gen: &mut rocket_okapi::gen::OpenApiGenerator,
) -> rocket_okapi::Result {
let mut responses = okapi::openapi3::Responses::default();
responses
.responses
.extend(Json::::responses(gen)?.responses);
responses
.responses
.extend(NoContent::responses(gen)?.responses);
Ok(responses)
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.