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

Build error with schema name "Value" #1189

Open
HollayHorvath opened this issue Nov 5, 2024 · 1 comment
Open

Build error with schema name "Value" #1189

HollayHorvath opened this issue Nov 5, 2024 · 1 comment
Labels
investigate Futher investigation needed before other action

Comments

@HollayHorvath
Copy link

When I have a schema component with the name Value the #[derive(OpenApi)] produces unparsable tokens:

error: expected expression, found `,`
 --> src/main.rs:8:10
  |
8 | #[derive(OpenApi)]
  |          ^^^^^^^ expected expression
  |
  = note: this error originates in the derive macro `OpenApi` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected one of `.`, `;`, `?`, `else`, or an operator, found `)`
 --> src/main.rs:8:10
  |
8 | #[derive(OpenApi)]
  |          ^^^^^^^ expected one of `.`, `;`, `?`, `else`, or an operator
  |
  = note: this error originates in the derive macro `OpenApi` (in Nightly builds, run with -Z macro-backtrace for more info)

error: proc-macro derive produced unparsable tokens
 --> src/main.rs:8:10
  |
8 | #[derive(OpenApi)]
  |          ^^^^^^^

The repro itself is shorter than the error:

use utoipa::{OpenApi, ToSchema};

#[derive(ToSchema)]
struct Value {
    val: &'static str,
}

#[derive(OpenApi)]
#[openapi(components(schemas(Value)))]
struct Api;

fn main() {
    println!("Hello, world!");
}

Renaming the Value struct fixes the issue.

The error is quite hard to decipher as the error reported has nothing to do with the actual problem.
It was working fine under Utoipa 4.x but it's broken under 5.0.

@juhaku
Copy link
Owner

juhaku commented Nov 14, 2024

Utoipa has Value and Object as reserved type names that will clash with other types if named similarly. Probably before utoipa has been lenient on that, but now everything needs explicit implementation for ToSchema which might have something to do with the error. This is due to fully support generics.

Value and Object types are used as meta names to indicate if type is just a json value or plain OpenAPI object. Changing this behavior would be a breaking change and needs further assessment what could be reasonable alternative for current behavior.

@juhaku juhaku added the investigate Futher investigation needed before other action label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Futher investigation needed before other action
Projects
None yet
Development

No branches or pull requests

2 participants