Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ function getDependentExcludedMap() {
HealthCheckCustomConfig: ['HealthCheckConfig'],
});

dependentExcludedMap.set('AWS::WAFv2::WebACL', {
SearchString: ['SearchStringBase64'],
SearchStringBase64: ['SearchString'],
});

return dependentExcludedMap as ReadonlyMap<string, DependentExcluded>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,15 @@ export class RemoveMutuallyExclusivePropertiesTransformer implements ResourceTem
return;
}
visited.add(resourceProperty);
// Schema refs are already resolved by ResourceSchema
const resolvedSchema = rawSchema;

// Resolve $ref if present
let resolvedSchema = rawSchema;
if (rawSchema.$ref && resourceSchema) {
const resolved = resourceSchema.resolveRef(rawSchema.$ref);
if (resolved) {
resolvedSchema = resolved;
}
}

// If this object has mutually exclusive properties, remove keys in current object
const meResources = this.getMEResources(resolvedSchema, resourceSchema);
Expand Down Expand Up @@ -92,7 +99,7 @@ export class RemoveMutuallyExclusivePropertiesTransformer implements ResourceTem
const staticKeyList = Object.keys(resourceProperty);
for (const key of staticKeyList) {
const newPath = `${path}${this.PATH_SEPARATOR}${key}`;
const subschema = this.getSubSchema(resolvedSchema, key, newPath);
const subschema = this.getSubSchema(resolvedSchema, key, newPath, resourceSchema);

if (subschema && resourceProperty[key] !== undefined) {
const value = resourceProperty[key];
Expand All @@ -102,7 +109,7 @@ export class RemoveMutuallyExclusivePropertiesTransformer implements ResourceTem
value,
subschema,
newPath,
undefined,
resourceSchema,
depth + 1,
visited,
);
Expand All @@ -116,13 +123,18 @@ export class RemoveMutuallyExclusivePropertiesTransformer implements ResourceTem
const itemPath = `${newPath}${this.PATH_SEPARATOR}${i}`;

if (this.isObject(item)) {
const arraySchemaItem = this.getSubSchema(arraySubschema, this.UNINDEXED_PATH, itemPath);
const arraySchemaItem = this.getSubSchema(
arraySubschema,
this.UNINDEXED_PATH,
itemPath,
resourceSchema,
);
if (arraySchemaItem) {
this.traverseResourcePropertiesAndRemoveMutuallyExclusiveProperties(
item,
arraySchemaItem,
itemPath,
undefined,
resourceSchema,
depth + 1,
visited,
);
Expand Down Expand Up @@ -232,16 +244,30 @@ export class RemoveMutuallyExclusivePropertiesTransformer implements ResourceTem
return arraySchema ?? schema;
}

private getSubSchema(schema: PropertyType, id: string, path: string): PropertyType | undefined {
private getSubSchema(
schema: PropertyType,
id: string,
path: string,
resourceSchema?: ResourceSchema,
): PropertyType | undefined {
try {
// Simplified implementation - in a real scenario, this would use a schema helper
let result: PropertyType | undefined;

if (schema.properties?.[id]) {
return schema.properties[id];
result = schema.properties[id];
} else if (schema.items && id === this.UNINDEXED_PATH) {
result = schema.items;
}
if (schema.items && id === this.UNINDEXED_PATH) {
return schema.items;

// Resolve $ref if present
if (result?.$ref && resourceSchema) {
const resolved = resourceSchema.resolveRef(result.$ref);
if (resolved) {
return resolved;
}
}
return;

return result;
} catch {
if (id !== this.REF_ID && id !== this.GETATT_ID) {
logger.info(`Unable to find schema at path ${path}`);
Expand Down
Loading
Loading