Marwes / schemafy

Crate for generating rust types from a json schema
MIT License
242 stars 51 forks source link

How is this crate used? #46

Closed johnoneil closed 3 years ago

johnoneil commented 3 years ago

This crate seems very clever and useful, but I'm having difficulty using it in a practical way.

I've consulted the doctest examples and they elide over many particulars, mostly about how to infer the generated struct names from the schema. Is it possible to examine the generated code?

In the doctest example, the nested.json schema, the code simply uses the Defnested type which is mysterious to me in a number of ways:

So, presumably one should infer by trial and error the name of the generated types?

How then can I infer the generated types the schema has no title or type at the root?

I'm sorry to be a bit lost here, but if I'm having some difficulties I'd imagine many people would have the same difficulties.

johnoneil commented 3 years ago

Okay I had to look it up, but the way to examine the contents of the procedural macro code is like:

# first install cargo-expand
# Then you can get expanded code for whatever your target is. Here a test.
cargo expand --test test_name

Appreciate your work on this crate.

bgilbert commented 3 years ago

You can also run cargo doc --no-deps and look at the generated documentation.