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

Unable to ignore field : compile error with fn field on a struct #1203

Open
reneklacan opened this issue Nov 14, 2024 · 2 comments
Open

Unable to ignore field : compile error with fn field on a struct #1203

reneklacan opened this issue Nov 14, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@reneklacan
Copy link

Utoipa version: 5.2

Minimal code to replicate:

#[derive(ToSchema)]
pub struct Foo {
    // ...
    #[schema(ignore)]
    pub bar: Option<fn(String) -> String>,
}

Build error:

error: unexpected type in component part get type path, expected one of: Path, Tuple, Reference, Group, Array, Slice, TraitObject

Expected behavior: I'd at least hope field like this can be ignored and won't trigger a compilation error.

Workaround (create type that has subset of fields and alias it with as):

pub struct Foo {
    // ...
    #[schema(ignore)]
    pub bar: Option<fn(String) -> String>,
}

#[derive(ToSchema)]
#[schema(as = Foo)]
pub struct FooSimple {
    // ...
}
@juhaku
Copy link
Owner

juhaku commented Nov 14, 2024

This is due to utoipa is not able to recognize pub bar: Option<fn(String) -> String>, type with fn argument as value while parsing ToSchema. This support could be added though and should be quite simple, but I might be wrong as well. For quick fix as well you can add #[schema(value_type=()] for example to get around the compile error.

@juhaku juhaku changed the title Unable to ignore field Unable to ignore field : compile error with fn field on a struct Nov 14, 2024
@juhaku juhaku added the enhancement New feature or request label Nov 14, 2024
@reneklacan
Copy link
Author

For quick fix as well you can add #[schema(value_type=()] for example to get around the compile error.

That unfortunately doesn't work. It was one of the first things I tried, it still fails with the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

2 participants