Skip to content

Derive OpenApiResponderInner for #[derive(Responder)] enums #146

@Keshi

Description

@Keshi

Using this feature rwf2/Rocket#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<Person>), // 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<okapi::openapi3::Responses> {
        let mut responses = okapi::openapi3::Responses::default();
        responses
            .responses
            .extend(Json::<Person>::responses(gen)?.responses);
        responses
            .responses
            .extend(NoContent::responses(gen)?.responses);
        Ok(responses)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestrocket-okapi-codegenThis affects the rocket-okapi-codegen crate

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions