cloudformation-cli
cloudformation-cli copied to clipboard
Unable to use `oneOf` construct to select between 2 different `properties` structures with overlapping fields
I have a property FilterAndOperator which has 2 sub-properties:
-
Prefix -
Tagswhich is a list containing items of typeTag.
The requirement for FilterAndOperator is this:
- It should contain a
Prefixand at least oneTagin theTagslist. OR - It should contain 2 or more
Tagitems in theTagslist if aPrefixis not provided.
I tried representing this using the following JSON schema:
{
"definitions": {
"Tag": {
"type": "object",
"additionalProperties": false,
"properties": {
"Key": {
"type": "string"
},
"Value": {
"type": "string"
}
},
"required": [
"Key",
"Value"
]
}
},
"additionalProperties": false,
"properties": {
"ID": {
"type": "string"
},
"FilterAndOperator": {
"type": "object",
"oneOf": [
{
"additionalProperties": false,
"properties": {
"Prefix": {
"type": "string"
},
"Tags": {
"type": "array",
"uniqueItems": true,
"minItems": 1,
"items": {
"$ref": "#/definitions/Tag"
}
}
},
"required": [
"Prefix",
"Tags"
]
},
{
"additionalProperties": false,
"properties": {
"Prefix": {
"type": "string"
},
"Tags": {
"type": "array",
"uniqueItems": true,
"minItems": 2,
"items": {
"$ref": "#/definitions/Tag"
}
}
},
"required": [
"Tags"
]
}
]
}
}
}
When I try to build, I get an error:
=== Unhandled exception ===
Please report this issue to the team.
Issue tracker: https://github.com/aws-cloudformation/aws-cloudformation-rpdk/issues
Please include the log file 'rpdk.log'
[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 127 (Exit value: 127)
at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)
at org.apache.commons.exec.DefaultExecutor.execute (DefaultExecutor.java:166)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:804)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:751)
at org.codehaus.mojo.exec.ExecMojo.execute (ExecMojo.java:313)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.381 s
[INFO] Finished at: 2021-01-21T09:55:06-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:exec (generate) on project aws-s3outposts-bucket-handler: Command execution failed.: Process exited with an error: 127 (Exit value: 127) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Here is the rpdk.log output
[2021-01-21T14:55:06Z] DEBUG - FilterAndOperator POJO: /Users/nadaksha/github/resource-providers-s3outposts/aws-s3outposts-bucket/target/generated-sources/rpdk/software/amazon/s3outposts/bucket/FilterAndOperator.java
[2021-01-21T14:55:06Z] DEBUG - Unhandled exception
Traceback (most recent call last):
File "/Users/nadaksha/Library/Python/3.8/lib/python/site-packages/rpdk/core/cli.py", line 100, in main
args.command(args)
File "/Users/nadaksha/Library/Python/3.8/lib/python/site-packages/rpdk/core/generate.py", line 15, in generate
project.generate()
File "/Users/nadaksha/Library/Python/3.8/lib/python/site-packages/rpdk/core/project.py", line 407, in generate
self._plugin.generate(self)
File "/Users/nadaksha/Library/Python/3.8/lib/python/site-packages/rpdk/java/codegen.py", line 35, in wrapper
result = func(*args, **kwargs)
File "/Users/nadaksha/Library/Python/3.8/lib/python/site-packages/rpdk/java/codegen.py", line 414, in generate
contents = pojo_template.render(
File "/Users/nadaksha/Library/Python/3.8/lib/python/site-packages/jinja2/environment.py", line 1090, in render
self.environment.handle_exception()
File "/Users/nadaksha/Library/Python/3.8/lib/python/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/Users/nadaksha/Library/Python/3.8/lib/python/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "/Users/nadaksha/Library/Python/3.8/lib/python/site-packages/rpdk/java/templates/generate/POJO.java", line 25, in top-level template code
private {{ type|translate_type }} {{ name|lowercase_first_letter|safe_reserved }};
File "/Users/nadaksha/Library/Python/3.8/lib/python/site-packages/rpdk/java/resolver.py", line 21, in translate_type
primitive_format = PRIMITIVE_TYPES[resolved_type.type][
TypeError: unhashable type: 'OrderedSet'
ammokhov@ from the CFN team has confirmed this is a bug. (please refer to the sage)
Acceptance Criteria
- [ ]
cfn generateshould successfully create a resource model using the above schema i.e. build should be successful. - [ ] The generated resource model should allow the following 2 inputs:
INPUT 1
{
"FilterAndOperator": {
"Tags": [
{
"Key": "",
"Value": ""
},
{
"Key": "1",
"Value": ""
}
]
}
}
INPUT 2
{
"FilterAndOperator": {
"Prefix": "",
"Tags": [
{
"Key": "",
"Value": ""
}
]
}
}