diff --git a/packages/@aws-cdk/cfnspec/build-tools/build.ts b/packages/@aws-cdk/cfnspec/build-tools/build.ts index 7df5f5a9fa9c2..5b2910f12d7c4 100644 --- a/packages/@aws-cdk/cfnspec/build-tools/build.ts +++ b/packages/@aws-cdk/cfnspec/build-tools/build.ts @@ -26,9 +26,7 @@ async function main() { } } - detectScrutinyTypes(spec); - replaceIncompleteTypes(spec); - dropTypelessAttributes(spec); + massageSpec(spec); spec.Fingerprint = md5(JSON.stringify(normalize(spec))); @@ -37,6 +35,12 @@ async function main() { await fs.writeJson(path.join(outDir, 'specification.json'), spec, { spaces: 2 }); } +export function massageSpec(spec: schema.Specification) { + detectScrutinyTypes(spec); + replaceIncompleteTypes(spec); + dropTypelessAttributes(spec); +} + function forEachSection(spec: schema.Specification, data: any, cb: (spec: any, fragment: any, path: string[]) => void) { cb(spec.PropertyTypes, data.PropertyTypes, ['PropertyTypes']); cb(spec.ResourceTypes, data.ResourceTypes, ['ResourceTypes']); diff --git a/packages/@aws-cdk/cfnspec/test/test.build.ts b/packages/@aws-cdk/cfnspec/test/test.build.ts new file mode 100644 index 0000000000000..ba7364b7075d8 --- /dev/null +++ b/packages/@aws-cdk/cfnspec/test/test.build.ts @@ -0,0 +1,68 @@ +import { Test } from 'nodeunit'; +import { massageSpec } from '../build-tools/build'; +import { schema } from '../lib'; + +export = { + 'dropTypelessAttributes works correctly'(test: Test) { + const spec: schema.Specification = { + Fingerprint: 'some-fingerprint', + PropertyTypes: { + 'CDK::Test::Property': { + Properties: { + Type: ({ + PrimitiveType: "String", + } as schema.ScalarProperty), // ts is being weird and doesn't correctly match the type + }, + } + }, + ResourceTypes: { + 'CDK::Test::Resource': { + Attributes: { + Attribute1: ({ + PrimitiveType: 'String' + } as schema.PrimitiveAttribute), // ts is being weird and doesn't correctly match the type + Attribute2: ({} as schema.PrimitiveAttribute), + }, + Documentation: "https://documentation-url/cdk/test/resource", + Properties: { + ResourceArn: ({ + PrimitiveType: "String", + } as schema.PrimitiveProperty), // ts is being weird and doesn't correctly match the type + } + } + } + }; + + massageSpec(spec); + + test.deepEqual(spec, { + Fingerprint: 'some-fingerprint', + PropertyTypes: { + 'CDK::Test::Property': { + Properties: { + Type: ({ + PrimitiveType: "String", + } as schema.ScalarProperty), // ts is being weird and doesn't correctly match the type + }, + } + }, + ResourceTypes: { + 'CDK::Test::Resource': { + Attributes: { + Attribute1: ({ + PrimitiveType: 'String' + }), + }, + Documentation: "https://documentation-url/cdk/test/resource", + Properties: { + ResourceArn: { + PrimitiveType: "String", + }, + } + } + } + }); + + test.done(); + } +};