aws-cloudformation / cloudformation-cli-go-plugin

The CloudFormation Provider Development Toolkit Go Plugin allows you to autogenerate Go code based on an input schema.
52 stars 31 forks source link

Generate correct types for maps #106

Closed stilvoid closed 4 years ago

stilvoid commented 4 years ago

Issue #, if available: #104

Description of changes: Generate correct Go types for maps and undefined types in schema.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

brianterry commented 4 years ago

So, if a user adds a schema without any properties, the generator returns a map[string] TYPE{} instead of a TYPE{}?

stilvoid commented 4 years ago

The metaschema doesn't allow schemas without any properties.

If you define a property like this

{
    "type": "object"
}

you get map[string]interface{} in your model.

If you define the property as

{
    "type": "object",
    "patternProperties": {
        "*": {
            "type": "string"
        }
    }
}

you get map[string]*encoding.String in your model.