evestera / json_typegen

Tools and libraries to create types for Rust, Kotlin, TypeScript and Python from JSON samples
https://typegen.vestera.as
Apache License 2.0
273 stars 26 forks source link

Make generated types public #5

Closed AlexArgoAi closed 6 years ago

AlexArgoAi commented 6 years ago

The output from the json_typegen CLI contains non-public types (and fields). When saving it to a module, as shown in the Readme, these types are not exported and are therefore unusable.

This tool should add a pub modifier to all types and fields generated, possibly behing a flag.

evestera commented 6 years ago

Thanks for opening the issue, and sorry for letting the released version lag so far behind development.

If you install the current master, cargo install --git https://github.com/evestera/json_typegen/ json_typegen_cli you can add a visibility specifier to the name of the type. E.g. json_typegen 'http://vestera.as/json_typegen/examples/point.json' -o src/point.rs -n 'pub Point'

By default the field visibility will be the same as the type visiblity, but this can be further configured with an options block. E.g. json_typegen 'http://vestera.as/json_typegen/examples/point.json' -o src/point.rs -n 'pub Point' --options '{ field_visibility: "pub(crate)" }'

I unfortunately have not been able to spend much time working on json_typegen since graduating, but I'll try to get a 0.2 release out right away. Clearly, releasing the current master branch is better than keeping the 0.1 version the main version on crates.io.

AlexArgoAi commented 6 years ago

Indeed, that fixes it. Thanks!

evestera commented 6 years ago

Great! Let me know if you run into anything else.

Made a release now, so a regular cargo install json_typegen_cli should have the same features.

Also typed up some docs for the configuration, which might be useful: https://github.com/evestera/json_typegen/blob/master/CONFIGURATION.md