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

#[derive(JsonSchema)] compile errors when fields are dynamically generated #66

Closed
up9cloud opened this issue Dec 24, 2020 · 4 comments
Closed
Milestone

Comments

@up9cloud
Copy link

Something like this:

/tmp/b$ cat Cargo.toml

[package]
name = "b"
version = "0.1.0"
authors = ["up9cloud <8325632+up9cloud@users.noreply.github.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
schemars = "0.8"

/tmp/b$ cat src/main.rs

macro_rules! build_struct {
    (
        $id:ident { $($t:tt)* }
    ) => {
        #[derive(Debug, schemars::JsonSchema)]
        pub struct $id {
            x: u8,
            $($t)*
        }
    };
}
build_struct!(A { v: i32, });
fn main() {
   println!("{:?}", A { x: 0, v: 1 });
}

/tmp/b$ cargo run

   Compiling b v0.1.0 (/private/tmp/b)
error[E0425]: cannot find value `gen` in this scope
  --> src/main.rs:12:22
   |
12 | build_struct!(A { v: i32, });
   |                      ^^^ not found in this scope

error[E0425]: cannot find value `schema_object` in this scope
  --> src/main.rs:12:22
   |
12 | build_struct!(A { v: i32, });
   |                      ^^^ not found in this scope

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.
error: could not compile `b`

To learn more, run the command again with --verbose.

If I remove schemars::JsonSchema from derive, it works without errors.

@pjankiewicz
Copy link

I have exactly the same problem. Did you find any solution?

@up9cloud
Copy link
Author

Unfortunately, no. If there is any solution, please let me know 🥲

@GREsau GREsau added this to the v0.8.3 milestone Apr 5, 2021
@GREsau
Copy link
Owner

GREsau commented Apr 5, 2021

A fix for this has been merged and will be released in the next version 🙂

@GREsau
Copy link
Owner

GREsau commented Apr 5, 2021

Fixed in v0.8.3 - https://crates.io/crates/schemars/0.8.3

@GREsau GREsau closed this as completed Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants