Skip to content

Commit

Permalink
fix: deprecated properties not recorded (#655)
Browse files Browse the repository at this point in the history
In #646 we made a hotpatch to survive incorrectly specified deprecated
properties, but made a mistake which removed all deprecation information
from the DB.

Fix that.
  • Loading branch information
rix0rrr authored Oct 31, 2023
1 parent a8cf902 commit 6c20bcc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export function importCloudFormationRegistryResource(options: LoadCloudFormation
// AWS::CloudFront::ContinuousDeploymentPolicy recently introduced a change where they're marking deprecatedProperties
// as `/definitions/<Type>/properties/<Prop>` instead of `/properties/<Prop1>/<Prop2>/<Prop3>`. Ignore those, as it's
// out-of-spec
const deprecatedProperties = (resource.deprecatedProperties ?? []).filter((p) => p.startsWith('/properties/'));
const deprecatedProperties = (resource.deprecatedProperties ?? [])
.filter((p) => p.startsWith('/properties/'))
.map(simplePropNameFromJsonPtr);
resourceBuilder.markDeprecatedProperties(...deprecatedProperties);

// Mark everything 'readOnlyProperties` as attributes. However, in the old spec it is possible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,51 @@ test('include primaryIdentifier in database', () => {
const primaryIdentifier = db.lookup('resource', 'cloudFormationType', 'equals', 'AWS::Some::Type')[0]?.primaryIdentifier;
expect(primaryIdentifier).toEqual(['id', 'secondId']);
});

test('deprecated properties', () => {
importCloudFormationRegistryResource({
db,
report,
resource: {
typeName: 'AWS::Some::Type',
description: 'resource with PrimaryIdentifier',
properties: {
id: {
type: 'string',
},
},
deprecatedProperties: ['/properties/id'],
},
});

// eslint-disable-next-line prettier/prettier
const resource = db.lookup('resource', 'cloudFormationType', 'equals', 'AWS::Some::Type').only();
expect(resource.properties.id.deprecated).toBeDefined();
});

test('type definitions in deprecated properties do not fail', () => {
importCloudFormationRegistryResource({
db,
report,
resource: {
typeName: 'AWS::Some::Type',
description: 'resource with PrimaryIdentifier',
properties: {
id: { $ref: '#/definitions/Type' },
},
definitions: {
Type: {
type: 'object',
properties: {
id: {
type: 'string',
},
},
},
},
deprecatedProperties: ['/definitions/Type/properties/id'],
},
});

// THEN: no failure
});

0 comments on commit 6c20bcc

Please sign in to comment.