juhaku / utoipa

Simple, Fast, Code first and Compile time generated OpenAPI documentation for Rust
Apache License 2.0
2.01k stars 160 forks source link

Use include_str! in the openapi's tag definition #877

Closed fistons closed 2 months ago

fistons commented 4 months ago

Would it be possible to use the include_str! macro inside openapi derive macro tag attribute, like it is possible with the info attribute?

#[derive(OpenApi)]
#[openapi(
    info(description=include_str!("../documentation/description.md")),    // <--- This works
    paths(get_channels, create_channel),
    components(schemas(crate::routes::Channel, crate::routes::CreateChannelRequest)),
    tags(
        (name="My Tag", description=include_str!("../documentation/channels.md"))   // <--- This fails
    ),
)]
pub struct ApiDoc;

This is the error I got:

error: expected string literal
 --> src/openapi.rs:9:39
  |
9 |         (name="Channels", description=include_str!("../documentation/channels.md"))
  |

Looking quickly at the sources, it seems that Info Description uses a certain Type that allow both String and include_str!. Would it be possible to reuse this Type here?