-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
mashmallow or pydantic models from json-schema #1879
Comments
I'll have to come back to read your additional comments. But when running your tests, did you set the TROPO_REAL_BOOL environment variable? The mapping is done here. This was added for backwards compatibility and will be the default in the next major revision. |
The |
I would like to second that using Pydantic is really sweet. Typehints, serialization, Literals, etc.; it has been so agile to use. Looking at this PR for example: https://github.com/cloudtools/troposphere/pull/1858/files |
@dazza-codes @lautjy I found a python library https://github.com/MacHu-GWU/cottonformation-project#welcome-to-cottonformation-documentation seems like they did exactly what you said about the Typehint, Parameter suggest and validation. Seems like this guy use the cloudformation schema json file from AWS and jinja2 automatically generates all those code, I think we can borrow this to here.
|
Apologies if this already discussed somewhere - I am new to this project. To get started I used
cfn2py
script and tested some round-trip serializations back to json and yaml using somedeepdiff
andcfn-lint
checks.One concern is that boolean values are not JSON booleans but strings. Why does the
t.to_dict()
andt.to_json()
data contain strings instead of JSON booleans? It seems likeencode_to_dict(obj)
should be replaced with just ajson.loads(json.dumps(obj))
and let thejson
lib take care of all the necessary python/JSON compatibility and encodings.Or using marshmallow or pydantic models in general should take care of all the schema mappings and serializations. It might also be easier to use botocore service descriptions or other AWS json payloads to auto-generate json-schema and models. It's not quite the same thing as CFN templates, but botocore has service API descriptions in e.g.
lib/python3.7/site-packages/botocore/data/cloudformation/2010-05-15/service-2.json
; see alsoThe resource-type-schemas might be amenable to auto-generation of service models using mashmallow or pydantic schema parsers and code generators. If something like this were to work well, it might eliminate most if not all of the issues about supporting new features in CFN services.
In this example, the
cfn_schemas
is a directory with unzipped data from a regional download .zip file.The pydantic models have built in serializations.
The resulting
aws_s3_bucket.py
contains:The text was updated successfully, but these errors were encountered: