-
Notifications
You must be signed in to change notification settings - Fork 11
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
How to get descriptions saved as comments? #83
Comments
Hi, currently that isn't possible through This is functionality I want as well, but so far the only way I've figured out would be writing a custom YAML engine (possibly on top of |
I guess it could be possible to take the json serialisation that pydantic provides and annotate it with the metadata in a format ruamel.yaml accepts? Technically it woudn't be a completely custom engine? |
Well, yes, you can look through the There's also the consideration of how you'd annotate it... If you have a simple use-case right now (i.e. just one or more nested Pydantic models with fields), it is actually not that difficult to implement - you can use Making this work in the general case is an issue, since you can have containers (lists, dicts, list-like, dict-like, ...) of Pydantic and non-Pydantic objects. And all can have field validations. I hope I will find something in |
Up-voting this! |
I'd love to see that! A one-line function to dump a "default YAML config file" with comments directly from a model to me would be a killer feature when building tools :) |
Hi, I believe I started looking into this before this project got going: https://github.com/opera-adt/dolphin/blob/main/src/dolphin/workflows/_yaml_model.py Since that part is already here, perhaps someone would be able to take the This for Pydantic V1, and i'm working on updating things (if there were any breaking changes) to V2 shortly. |
Hi there. Came across this discussion after having the same functional goal of writing my models and having them make self-documenting YAML templates. I spent some time looking at the pydantic-yaml code and the underlying ruamel.yaml library. I'm sure a plugin or subclass could make this happen, but it looked like a lot to learn and sort of reverse-engineer. Instead I wrote this gist that works at the file level and leverages the original models used to make the template file. I'm sure there are a TON of use cases the gist doesn't cover but its working for my needs. Hope it helps! |
Indeed, Adding comments to the YAML file from a fields' description (or docstring) would be amazing. |
In pydantic you can use the Field function to attach a description to the model properties, and I wonder if there is a way that pydantic-yaml could save that description as a comment?
The text was updated successfully, but these errors were encountered: