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

Support schema export #268

Open
airwoodix opened this issue Nov 29, 2024 · 3 comments
Open

Support schema export #268

airwoodix opened this issue Nov 29, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@airwoodix
Copy link

airwoodix commented Nov 29, 2024

Is there tooling or preliminary work looking into exporting a schema for the settings described by miniconf?

In particular for MQTT, something like asyncapi could be nice and provide a way to automatically document the settings.

@jordens
Copy link
Member

jordens commented Nov 29, 2024

Not that I'm aware of.

@jordens
Copy link
Member

jordens commented Nov 30, 2024

Easiest approach is probably to co-derive with schemars matching skip, rename etc. and then transform or re-interpret.

@jordens jordens added the enhancement New feature or request label Nov 30, 2024
@airwoodix
Copy link
Author

Thanks for the feedback! The interaction with schemars sounds promising. I guess one could start with being able to derive from JsonSchema, and handle the actual schema output separately?

For the JsonSchema derivation: one could rely on schemars' serde compatibilty to write something like:

#[derive(JsonSchema, Tree)]
struct Settings {
    #[serde(skip)] // or #[schemars(skip)]
    #[tree(skip)]
    foo: Leaf<bool>,
    // ...
}

but the duplication is ugly and even more annoying for rename.

The easy way around would be to forward the serde or schemars attributes to the Tree derive, but that would heavily break the existing API. Writing the schemars/serde attributes from the tree ones won't work with a derive macro (but with an attribute one). Optionally adding the JsonSchema implementation as Tree derive is not so easy, because the implementation functions are not exported by schemars.

Do you see nicer ways than what's outlined above?

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
None yet
Development

No branches or pull requests

2 participants