Skip to content

Commit

Permalink
Adding conditionallyCreateOnlyProperties to metaschema (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
ammokhov authored Mar 29, 2021
1 parent 9d57e03 commit 7d82244
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ResourceTypeSchema {
private final String replacementStrategy;
private final boolean taggable;
private final List<JSONPointer> createOnlyProperties = new ArrayList<>();
private final List<JSONPointer> conditionalCreateOnlyProperties = new ArrayList<>();
private final List<JSONPointer> deprecatedProperties = new ArrayList<>();
private final List<JSONPointer> primaryIdentifier = new ArrayList<>();
private final List<List<JSONPointer>> additionalIdentifiers = new ArrayList<>();
Expand Down Expand Up @@ -96,6 +97,11 @@ public ResourceTypeSchema(Schema schema) {
: true;
this.unprocessedProperties.remove("taggable");

this.unprocessedProperties.computeIfPresent("conditionalCreateOnlyProperties", (k, v) -> {
((ArrayList<?>) v).forEach(p -> this.conditionalCreateOnlyProperties.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;
Expand Down Expand Up @@ -159,6 +165,10 @@ public String getDescription() {
return schema.getDescription();
}

public List<String> getConditionalCreateOnlyPropertiesAsStrings() throws ValidationException {
return this.conditionalCreateOnlyProperties.stream().map(JSONPointer::toString).collect(Collectors.toList());
}

public List<String> getCreateOnlyPropertiesAsStrings() throws ValidationException {
return this.createOnlyProperties.stream().map(JSONPointer::toString).collect(Collectors.toList());
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/schema/provider.definition.schema.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
"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": {
"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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ public void getProperties() {
assertThat(schema.getUnprocessedProperties()).isEmpty();
}

@Test
public void getConditionalCreateOnlyProperties() {
JSONObject o = loadJSON(TEST_SCHEMA_PATH);
final ResourceTypeSchema schema = ResourceTypeSchema.load(o);

List<String> result = schema.getConditionalCreateOnlyPropertiesAsStrings();

assertThat(result).containsExactly("/properties/propertyF");
}

@Test
public void getCreateOnlyProperties() {
JSONObject o = loadJSON(TEST_SCHEMA_PATH);
Expand Down Expand Up @@ -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.getConditionalCreateOnlyPropertiesAsStrings()).isEmpty();
assertThat(schema.getDeprecatedPropertiesAsStrings()).isEmpty();
assertThat(schema.getPrimaryIdentifierAsStrings()).containsExactly("/properties/PropertyA");
assertThat(schema.getAdditionalIdentifiersAsStrings()).isEmpty();
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/test-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
"type": "string"
}
}
},
"propertyF": {
"type": "string"
}
},
"propertyTransform": {
Expand All @@ -37,6 +40,9 @@
"required": [
"propertyB"
],
"conditionalCreateOnlyProperties": [
"/properties/propertyF"
],
"createOnlyProperties": [
"/properties/propertyA",
"/properties/propertyD"
Expand Down

0 comments on commit 7d82244

Please sign in to comment.