aws-cloudformation / aws-cloudformation/cloudformation-cli

CLI crashes when "oneOf" is used the in schema

Open
#867 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
336
Forks
172
Avg merge
3d 5m
Merged PRs (30d)
3

Description

When `oneof` is used the resource schema, the Cli crashes.
Here is an example of a resource schema that uses `oneof`:
```
{
"typeName": "brian::foo::me",
"description": "An example resource schema demonstrating some basic constructs and validation rules.",
"sourceUrl": "https://github.com/aws-cloudformation/aws-cloudformation-rpdk.git",
"definitions": {
"InitechDateFormat": {
"$comment": "Use the `definitions` block to provide shared resource property schemas",
"type": "string",
"format": "date-time"
},
"Memo": {
"type": "object",
"properties": {
"Heading": {
"type": "string"
},
"Body": {
"type": "string"
}
},
"additionalProperties": false
},
"Tag": {
"description": "A key-value pair to associate with a resource.",
"type": "object",
"properties": {
"Key": {
"type": "string",
"description": "The key name of the tag. You can specify a value that is 1 to 128 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -.",
"minLength": 1,
"maxLength": 128
},
"Value": {
"type": "string",
"description": "The value for the tag. You can specify a value that is 0 to 256 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -.",
"minLength": 0,
"maxLength": 256
}
},
"required": [
"Key",
"Value"
],
"additionalProperties": false
}
},
"properties": {
"Cookies": {
"oneOf": [
{
"additionalProperties": false,
"properties": {
"Forward": {
"description": "Specifies which cookies to forward to the origin for this cache behavior.",
"enum": [
"all",
"none"
],
"type": "string"
}
},
"required": [
"Forward"
]
},
{
"additionalProperties": false,
"properties": {
"Forward": {
"description": "Specifies which cookies to forward to the origin for this cache behavior.",
"enum": [
"whitelist"
],
"type": "string"
},
"WhitelistedNames": {
"description": "Required if you specify whitelist for the value of Forward.",
"items": {
"type": "string"
},
"minItems": 1,
"type": "array"
}
},
"required": [
"Forward",
"WhitelistedNames"
]
}
],
"type": "object"
}
},
"additionalProperties": false,
"required": [
"TestCode",
"Title"
],
"readOnlyProperties": [
"/properties/TPSCode"
],
"primaryIdentifier": [
"/properties/TPSCode"
],
"handlers": {
"create": {
"permissions": [
"initech:CreateReport"
]
},
"read": {
"permissions": [
"initech:DescribeReport"
]
},
"update": {
"permissions": [
"initech:UpdateReport"
]
},
"delete": {
"permissions": [
"initech:DeleteReport"
]
},
"list": {
"permissions": [
"initech:ListReports"
]
}
}
}
```
```
$ cfn generate
Explicitly specify value for insertionOrder for array: WhitelistedNames
Explicitly specify value for tagging
Resource schema is valid.
=== Unhandled exception ===
Please report this issue to the team.
Issue tracker: github.com/aws-cloudformation/cloudformation-cli/issues
Please include the log file 'rpdk.log'
```

rpdk.log
```
[2022-03-04T19:38:08Z] DEBUG - Logging set up successfully
[2022-03-04T19:38:08Z] DEBUG - Running generate: Namespace(version=False, subparser_name='generate', command=, verbose=0, endpoint_url=None, region=None, target_schemas=[])
[2022-03-04T19:38:08Z] DEBUG - Root directory: /private/tmp/foo
[2022-03-04T19:38:08Z] DEBUG - Loading project file '/private/tmp/foo/.rpdk-config'
[2022-03-04T19:38:08Z] INFO - Validating your resource specification...
[2022-03-04T19:38:08Z] WARNING - Explicitly specify value for insertionOrder for array: WhitelistedNames
[2022-03-04T19:38:08Z] WARNING - Explicitly specify value for tagging
[2022-03-04T19:38:08Z] DEBUG - Rewriting refs in '' (file:///private/tmp/foo/brian-foo-me.json)
[2022-03-04T19:38:08Z] WARNING - Resource schema is valid.
[2022-03-04T19:38:08Z] INFO - Validating your resource schema...
[2022-03-04T19:38:08Z] DEBUG - Writing Execution Role CloudFormation template: /private/tmp/foo/resource-role.yaml
[2022-03-04T19:38:08Z] DEBUG - Overwriting '/private/tmp/foo/resource-role.yaml'
[2022-03-04T19:38:08Z] DEBUG - Generate started
[2022-03-04T19:38:08Z] DEBUG - Removing generated sources: /private/tmp/foo/target/generated-sources/rpdk
[2022-03-04T19:38:08Z] DEBUG - Removing generated tests: /private/tmp/foo/target/generated-test-sources/rpdk
[2022-03-04T19:38:08Z] DEBUG - Making generated folder structure: /private/tmp/foo/target/generated-sources/rpdk/com/brian/foo/me
[2022-03-04T19:38:08Z] DEBUG - Making generated tests folder structure: /private/tmp/foo/target/generated-test-sources/rpdk/com/brian/foo/me
[2022-03-04T19:38:08Z] DEBUG - generate_resource started
[2022-03-04T19:38:08Z] DEBUG - Writing handler wrapper: /private/tmp/foo/target/generated-sources/rpdk/com/brian/foo/me/HandlerWrapper.java
[2022-03-04T19:38:08Z] DEBUG - Overwriting '/private/tmp/foo/target/generated-sources/rpdk/com/brian/foo/me/HandlerWrapper.java'
[2022-03-04T19:38:08Z] DEBUG - Writing handler wrapper: /private/tmp/foo/target/generated-sources/rpdk/com/brian/foo/me/HandlerWrapperExecutable.java
[2022-03-04T19:38:08Z] DEBUG - Overwriting '/private/tmp/foo/target/generated-sources/rpdk/com/brian/foo/me/HandlerWrapperExecutable.java'
[2022-03-04T19:38:08Z] DEBUG - Writing base configuration: /private/tmp/foo/target/generated-sources/rpdk/com/brian/foo/me/BaseConfiguration.java
[2022-03-04T19:38:08Z] DEBUG - Overwriting '/private/tmp/foo/target/generated-sources/rpdk/com/brian/foo/me/BaseConfiguration.java'
[2022-03-04T19:38:08Z] DEBUG - Writing base handler: /private/tmp/foo/target/generated-sources/rpdk/com/brian/foo/me/BaseHandler.java
[2022-03-04T19:38:08Z] DEBUG - Overwriting '/private/tmp/foo/target/generated-sources/rpdk/com/brian/foo/me/BaseHandler.java'
[2022-03-04T19:38:08Z] DEBUG - Writing 3 POJOs
[2022-03-04T19:38:08Z] DEBUG - ResourceModel POJO: /private/tmp/foo/target/generated-sources/rpdk/com/brian/foo/me/ResourceModel.java
[2022-03-04T19:38:08Z] DEBUG - Overwriting '/private/tmp/foo/target/generated-sources/rpdk/com/brian/foo/me/ResourceModel.java'
[2022-03-04T19:38:08Z] DEBUG - Cookies POJO: /private/tmp/foo/target/generated-sources/rpdk/com/brian/foo/me/Cookies.java
[2022-03-04T19:38:08Z] DEBUG - Unhandled exception
Traceback (most recent call last):
File "/private/tmp/foo/env/lib/python3.9/site-packages/rpdk/core/cli.py", line 100, in main
args.command(args)
File "/private/tmp/foo/env/lib/python3.9/site-packages/rpdk/core/generate.py", line 15, in generate
project.generate(args.endpoint_url, args.region, args.target_schemas)
File "/private/tmp/foo/env/lib/python3.9/site-packages/rpdk/core/project.py", line 558, in generate
self._plugin.generate(self)
File "/private/tmp/foo/env/lib/python3.9/site-packages/rpdk/java/codegen.py", line 39, in wrapper
result = func(*args, **kwargs)
File "/private/tmp/foo/env/lib/python3.9/site-packages/rpdk/java/codegen.py", line 449, in generate
self.generate_resource(src, project)
File "/private/tmp/foo/env/lib/python3.9/site-packages/rpdk/java/codegen.py", line 39, in wrapper
result = func(*args, **kwargs)
File "/private/tmp/foo/env/lib/python3.9/site-packages/rpdk/java/codegen.py", line 526, in generate_resource
contents = pojo_template.render(
File "/private/tmp/foo/env/lib/python3.9/site-packages/jinja2/environment.py", line 1090, in render
self.environment.handle_exception()
File "/private/tmp/foo/env/lib/python3.9/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/private/tmp/foo/env/lib/python3.9/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "/private/tmp/foo/env/lib/python3.9/site-packages/rpdk/java/templates/generate/POJO.java", line 22, in top-level template code
private {{ type|translate_type }} {{ name|lowercase_first_letter|safe_reserved }};
File "/private/tmp/foo/env/lib/python3.9/site-packages/rpdk/java/resolver.py", line 21, in translate_type
primitive_format = PRIMITIVE_TYPES[resolved_type.type][
TypeError: unhashable type: 'OrderedSet'
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.