From 53667d8932e6257aaf436f96ac29b1bc65fa8ba9 Mon Sep 17 00:00:00 2001 From: Anton Mokhovikov Date: Thu, 25 Mar 2021 16:01:26 -0700 Subject: [PATCH 1/2] Adding conditionallyCreateOnlyProperties to metaschema --- .../cloudformation/resource/ResourceTypeSchema.java | 10 ++++++++++ .../schema/provider.definition.schema.v1.json | 4 ++++ .../resource/ResourceTypeSchemaTest.java | 11 +++++++++++ src/test/resources/test-schema.json | 6 ++++++ 4 files changed, 31 insertions(+) diff --git a/src/main/java/software/amazon/cloudformation/resource/ResourceTypeSchema.java b/src/main/java/software/amazon/cloudformation/resource/ResourceTypeSchema.java index 594c772..87396c7 100644 --- a/src/main/java/software/amazon/cloudformation/resource/ResourceTypeSchema.java +++ b/src/main/java/software/amazon/cloudformation/resource/ResourceTypeSchema.java @@ -52,6 +52,7 @@ public class ResourceTypeSchema { private final String replacementStrategy; private final boolean taggable; private final List createOnlyProperties = new ArrayList<>(); + private final List conditionallyCreateOnlyProperties = new ArrayList<>(); private final List deprecatedProperties = new ArrayList<>(); private final List primaryIdentifier = new ArrayList<>(); private final List> additionalIdentifiers = new ArrayList<>(); @@ -96,6 +97,11 @@ public ResourceTypeSchema(Schema schema) { : true; this.unprocessedProperties.remove("taggable"); + this.unprocessedProperties.computeIfPresent("conditionallyCreateOnlyProperties", (k, v) -> { + ((ArrayList) v).forEach(p -> this.conditionallyCreateOnlyProperties.add(new JSONPointer(p.toString()))); + return null; + }); + this.unprocessedProperties.computeIfPresent("createOnlyProperties", (k, v) -> { ((ArrayList) v).forEach(p -> this.createOnlyProperties.add(new JSONPointer(p.toString()))); return null; @@ -159,6 +165,10 @@ public String getDescription() { return schema.getDescription(); } + public List getConditionallyCreateOnlyPropertiesAsStrings() throws ValidationException { + return this.conditionallyCreateOnlyProperties.stream().map(JSONPointer::toString).collect(Collectors.toList()); + } + public List getCreateOnlyPropertiesAsStrings() throws ValidationException { return this.createOnlyProperties.stream().map(JSONPointer::toString).collect(Collectors.toList()); } diff --git a/src/main/resources/schema/provider.definition.schema.v1.json b/src/main/resources/schema/provider.definition.schema.v1.json index c5de5a4..7cdaaad 100644 --- a/src/main/resources/schema/provider.definition.schema.v1.json +++ b/src/main/resources/schema/provider.definition.schema.v1.json @@ -387,6 +387,10 @@ "description": "A list of JSON pointers to properties (typically sensitive) that are able to be specified by the customer but unable to be returned in a Read request", "$ref": "#/definitions/jsonPointerArray" }, + "conditionallyCreateOnlyProperties": { + "description": "A list of JSON pointers to properties that are only able to cause replacement during the Update request.", + "$ref": "#/definitions/jsonPointerArray" + }, "createOnlyProperties": { "description": "A list of JSON pointers to properties that are only able to be specified by the customer when creating a resource. Conversely, any property *not* in this list can be applied to an Update request.", "$ref": "#/definitions/jsonPointerArray" diff --git a/src/test/java/software/amazon/cloudformation/resource/ResourceTypeSchemaTest.java b/src/test/java/software/amazon/cloudformation/resource/ResourceTypeSchemaTest.java index 7bba480..272cb84 100644 --- a/src/test/java/software/amazon/cloudformation/resource/ResourceTypeSchemaTest.java +++ b/src/test/java/software/amazon/cloudformation/resource/ResourceTypeSchemaTest.java @@ -51,6 +51,16 @@ public void getProperties() { assertThat(schema.getUnprocessedProperties()).isEmpty(); } + @Test + public void getConditionallyCreateOnlyProperties() { + JSONObject o = loadJSON(TEST_SCHEMA_PATH); + final ResourceTypeSchema schema = ResourceTypeSchema.load(o); + + List result = schema.getConditionallyCreateOnlyPropertiesAsStrings(); + + assertThat(result).containsExactly("/properties/propertyF"); + } + @Test public void getCreateOnlyProperties() { JSONObject o = loadJSON(TEST_SCHEMA_PATH); @@ -171,6 +181,7 @@ public void minimalSchema_hasNoSemantics() { assertThat(schema.getTypeName()).isEqualTo("AWS::Test::TestModel"); assertThat(schema.getUnprocessedProperties()).isEmpty(); assertThat(schema.getCreateOnlyPropertiesAsStrings()).isEmpty(); + assertThat(schema.getConditionallyCreateOnlyPropertiesAsStrings()).isEmpty(); assertThat(schema.getDeprecatedPropertiesAsStrings()).isEmpty(); assertThat(schema.getPrimaryIdentifierAsStrings()).containsExactly("/properties/PropertyA"); assertThat(schema.getAdditionalIdentifiersAsStrings()).isEmpty(); diff --git a/src/test/resources/test-schema.json b/src/test/resources/test-schema.json index 6d0b2cc..5f37586 100644 --- a/src/test/resources/test-schema.json +++ b/src/test/resources/test-schema.json @@ -28,6 +28,9 @@ "type": "string" } } + }, + "propertyF": { + "type": "string" } }, "propertyTransform": { @@ -37,6 +40,9 @@ "required": [ "propertyB" ], + "conditionallyCreateOnlyProperties": [ + "/properties/propertyF" + ], "createOnlyProperties": [ "/properties/propertyA", "/properties/propertyD" From 5c396b6548f7ef70b1e30b1ac6f41ec6085a6309 Mon Sep 17 00:00:00 2001 From: Anton Mokhovikov Date: Mon, 29 Mar 2021 13:44:36 -0700 Subject: [PATCH 2/2] changed property name and description --- .../cloudformation/resource/ResourceTypeSchema.java | 10 +++++----- .../schema/provider.definition.schema.v1.json | 4 ++-- .../resource/ResourceTypeSchemaTest.java | 6 +++--- src/test/resources/test-schema.json | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/software/amazon/cloudformation/resource/ResourceTypeSchema.java b/src/main/java/software/amazon/cloudformation/resource/ResourceTypeSchema.java index 87396c7..c7c7d27 100644 --- a/src/main/java/software/amazon/cloudformation/resource/ResourceTypeSchema.java +++ b/src/main/java/software/amazon/cloudformation/resource/ResourceTypeSchema.java @@ -52,7 +52,7 @@ public class ResourceTypeSchema { private final String replacementStrategy; private final boolean taggable; private final List createOnlyProperties = new ArrayList<>(); - private final List conditionallyCreateOnlyProperties = new ArrayList<>(); + private final List conditionalCreateOnlyProperties = new ArrayList<>(); private final List deprecatedProperties = new ArrayList<>(); private final List primaryIdentifier = new ArrayList<>(); private final List> additionalIdentifiers = new ArrayList<>(); @@ -97,8 +97,8 @@ public ResourceTypeSchema(Schema schema) { : true; this.unprocessedProperties.remove("taggable"); - this.unprocessedProperties.computeIfPresent("conditionallyCreateOnlyProperties", (k, v) -> { - ((ArrayList) v).forEach(p -> this.conditionallyCreateOnlyProperties.add(new JSONPointer(p.toString()))); + this.unprocessedProperties.computeIfPresent("conditionalCreateOnlyProperties", (k, v) -> { + ((ArrayList) v).forEach(p -> this.conditionalCreateOnlyProperties.add(new JSONPointer(p.toString()))); return null; }); @@ -165,8 +165,8 @@ public String getDescription() { return schema.getDescription(); } - public List getConditionallyCreateOnlyPropertiesAsStrings() throws ValidationException { - return this.conditionallyCreateOnlyProperties.stream().map(JSONPointer::toString).collect(Collectors.toList()); + public List getConditionalCreateOnlyPropertiesAsStrings() throws ValidationException { + return this.conditionalCreateOnlyProperties.stream().map(JSONPointer::toString).collect(Collectors.toList()); } public List getCreateOnlyPropertiesAsStrings() throws ValidationException { diff --git a/src/main/resources/schema/provider.definition.schema.v1.json b/src/main/resources/schema/provider.definition.schema.v1.json index 7cdaaad..52b2734 100644 --- a/src/main/resources/schema/provider.definition.schema.v1.json +++ b/src/main/resources/schema/provider.definition.schema.v1.json @@ -387,8 +387,8 @@ "description": "A list of JSON pointers to properties (typically sensitive) that are able to be specified by the customer but unable to be returned in a Read request", "$ref": "#/definitions/jsonPointerArray" }, - "conditionallyCreateOnlyProperties": { - "description": "A list of JSON pointers to properties that are only able to cause replacement during the Update request.", + "conditionalCreateOnlyProperties": { + "description": "A list of JSON pointers for properties that can only be updated under certain conditions. For example, you can upgrade the engine version of an RDS DBInstance but you cannot downgrade it. When updating this property for a resource in a CloudFormation stack, the resource will be replaced if it cannot be updated.", "$ref": "#/definitions/jsonPointerArray" }, "createOnlyProperties": { diff --git a/src/test/java/software/amazon/cloudformation/resource/ResourceTypeSchemaTest.java b/src/test/java/software/amazon/cloudformation/resource/ResourceTypeSchemaTest.java index 272cb84..002493d 100644 --- a/src/test/java/software/amazon/cloudformation/resource/ResourceTypeSchemaTest.java +++ b/src/test/java/software/amazon/cloudformation/resource/ResourceTypeSchemaTest.java @@ -52,11 +52,11 @@ public void getProperties() { } @Test - public void getConditionallyCreateOnlyProperties() { + public void getConditionalCreateOnlyProperties() { JSONObject o = loadJSON(TEST_SCHEMA_PATH); final ResourceTypeSchema schema = ResourceTypeSchema.load(o); - List result = schema.getConditionallyCreateOnlyPropertiesAsStrings(); + List result = schema.getConditionalCreateOnlyPropertiesAsStrings(); assertThat(result).containsExactly("/properties/propertyF"); } @@ -181,7 +181,7 @@ public void minimalSchema_hasNoSemantics() { assertThat(schema.getTypeName()).isEqualTo("AWS::Test::TestModel"); assertThat(schema.getUnprocessedProperties()).isEmpty(); assertThat(schema.getCreateOnlyPropertiesAsStrings()).isEmpty(); - assertThat(schema.getConditionallyCreateOnlyPropertiesAsStrings()).isEmpty(); + assertThat(schema.getConditionalCreateOnlyPropertiesAsStrings()).isEmpty(); assertThat(schema.getDeprecatedPropertiesAsStrings()).isEmpty(); assertThat(schema.getPrimaryIdentifierAsStrings()).containsExactly("/properties/PropertyA"); assertThat(schema.getAdditionalIdentifiersAsStrings()).isEmpty(); diff --git a/src/test/resources/test-schema.json b/src/test/resources/test-schema.json index 5f37586..fe0a828 100644 --- a/src/test/resources/test-schema.json +++ b/src/test/resources/test-schema.json @@ -40,7 +40,7 @@ "required": [ "propertyB" ], - "conditionallyCreateOnlyProperties": [ + "conditionalCreateOnlyProperties": [ "/properties/propertyF" ], "createOnlyProperties": [