Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Generics don't resolve inner type properly #979

Closed
theelderbeever opened this issue Jul 26, 2024 · 1 comment · Fixed by #1034
Closed

Nested Generics don't resolve inner type properly #979

theelderbeever opened this issue Jul 26, 2024 · 1 comment · Fixed by #1034
Labels
Generics - Hard Stuff concerning generics implementation

Comments

@theelderbeever
Copy link

theelderbeever commented Jul 26, 2024

The following code shows the response as { data: string, error: string } in Swagger instead of resolving the inner struct.

#[derive(OpenApi)]
#[openapi(
    paths(get_usage),
    tags((name = "Account Usage")),
    components(schemas(crate::api::v1::usage::schemas::Window, JsonAccountUsage, AccountUsage))
)]
pub struct ApiDoc;

#[derive(Serialize, Deserialize, Debug, ToSchema)]
#[aliases(JsonAccountUsage = JsonResponse<AccountUsage>)]
pub struct JsonResponse<T>
where
    T: Serialize,
{
    pub data: Option<T>,
    pub error: Option<String>,
}

#[derive(Debug, FromQueryResult, Serialize, Deserialize, ToSchema)]
pub struct AccountUsage {
    #[serde(with = "services::serde::time")]
    pub window_start: OffsetDateTime,
    #[serde(with = "services::serde::time")]
    pub window_end: OffsetDateTime,
    pub account: Uuid,
    pub instance: Option<Uuid>,
    pub method: Option<String>,
    pub archive: Option<bool>,
    pub chain: Option<String>,
    pub network: Option<String>,
    pub addon: Option<i32>,
    pub multiplier: Option<i32>,
    pub usage: i64,
    pub credits: i64,
}

#[utoipa::path(
    get,
    path = "/{account}/usage",
    responses(
        (status = 200, body = BillingAccountUsage),
    ),
    tag = "Account Usage",
    params(
        ("account" = Uuid, Path, description = "Account UUID"),
        AccountUsageParams,
    )
)]
pub async fn get_usage(
...
@juhaku juhaku added the Generics - Hard Stuff concerning generics implementation label Sep 4, 2024
@juhaku
Copy link
Owner

juhaku commented Sep 10, 2024

@theelderbeever There is now new implementation for generics coming up in #1034 which should solve the issue with aliases approach.

@juhaku juhaku moved this from Done to Released in utoipa kanban Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Generics - Hard Stuff concerning generics implementation
Projects
Status: Released
Development

Successfully merging a pull request may close this issue.

2 participants