-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
generate schema from models? #55
Comments
Hi. There is get_type_hints function you can use for this. |
ahh thats true, yeah I had a quick look into your code afterwards and realised it should be quite straightforward. Cheers~ |
Are there any plans for a non "poor mans" version? Or is there a compatible library that can generate jsonschema from a data class? |
Unfortunately, I don't know of any compatible library but you could try to reuse field metadata to generate a simple json schema.
To do this we need extensible validation mechanism which is not ready yet. |
sorry only tangently related but..
Any plans to support late initialization? eg
This along with schema would be perfect. In our situation we have quite large response models that are built up and would be nicer than passing the full dict to the constructor. |
I do agree that separating construction from validation would be best (vs. pydantic where the constructor validates by default and you have to use |
@hampsterx How do you build that models? If you want to deserialize dataclasses with another library and validate with mashumaro I wouldn’t say it’s a good idea.
@adriangb If I read you right, you want to be able to choose either to validate or not during the deserialization process. Or do you want to trigger validation manually at any time after an instance is created? |
Currently we just build up a big response dict but want to use models so we can lock it down and ideally generate client libraries (eg typescript, dart, etc) from the (json) schema. would be much nicer to start with Foo() and then build it up as we go rather than Foo(ret) at the end. |
I think manually triggering validation is more valuable:
|
Since mashumaro has grown and become quite stable I’ve revised my opinion about jsonschema generation. This is what I’m currently working on as part of the following issue: I don’t have a lot of experience in using jsonschema in the wild, so any help and suggestions are very welcome! |
Well, the pull request is merged, documentation is here. Everyone is welcome to give it a try 🎉 |
is there any way to generate a data dict of the model structure (field + type)? This would allow to generate typescript definitions for example ala poor mans openAPI generator type tool?
The text was updated successfully, but these errors were encountered: