diff --git a/packages/@aws-cdk/cdk-cfnspec/.npmignore b/packages/@aws-cdk/cdk-cfnspec/.npmignore index ff4a25b8edcc2..bce5cfa662346 100644 --- a/packages/@aws-cdk/cdk-cfnspec/.npmignore +++ b/packages/@aws-cdk/cdk-cfnspec/.npmignore @@ -1,3 +1,3 @@ *.ts !*.d.ts -spec-input +spec-source diff --git a/packages/@aws-cdk/cdk-cfnspec/build-tools/build.ts b/packages/@aws-cdk/cdk-cfnspec/build-tools/build.ts index 78f807da1dbd7..b424974b12b58 100644 --- a/packages/@aws-cdk/cdk-cfnspec/build-tools/build.ts +++ b/packages/@aws-cdk/cdk-cfnspec/build-tools/build.ts @@ -1,3 +1,10 @@ +/* + * Invoked as part of the "build" script of this package, + * this script takes all specification fragments in the + * `spec-source` folder and generates a unified specification + * document at `spec/specification.json`. + */ + import { applyPatch } from 'fast-json-patch'; import * as fs from 'fs-extra'; import * as md5 from 'md5'; @@ -5,7 +12,7 @@ import * as path from 'path'; import { schema } from '../lib'; async function main() { - const inputDir = path.join(process.cwd(), 'spec-input'); + const inputDir = path.join(process.cwd(), 'spec-source'); const files = await fs.readdir(inputDir); const spec: schema.Specification = { PropertyTypes: {}, ResourceTypes: {}, Fingerprint: '' }; for (const file of files.filter(n => n.endsWith('.json')).sort()) { @@ -99,7 +106,6 @@ function normalize(spec: schema.Specification): schema.Specification { } main() - .then(() => process.exit(0)) .catch(e => { // tslint:disable-next-line:no-console console.error(e.stack); diff --git a/packages/@aws-cdk/cdk-cfnspec/build-tools/update.sh b/packages/@aws-cdk/cdk-cfnspec/build-tools/update.sh index 60cc73ab833c8..8f7c776e78a47 100644 --- a/packages/@aws-cdk/cdk-cfnspec/build-tools/update.sh +++ b/packages/@aws-cdk/cdk-cfnspec/build-tools/update.sh @@ -1,5 +1,12 @@ #!/bin/bash + +### +# Updates the AWS CloudFormation Resource Specification using the files published on the AWS Documentaiton. +# See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-resource-specification.html +### + set -euo pipefail +rm -f spec-source/000_CloudFormationResourceSpecification.json curl -L "https://d1uauaxba7bl26.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.json" \ - | gunzip - > spec-input/000_CloudFormationResourceSpecification.json + | gunzip - > spec-source/000_CloudFormationResourceSpecification.json diff --git a/packages/@aws-cdk/cdk-cfnspec/lib/schema/base-types.ts b/packages/@aws-cdk/cdk-cfnspec/lib/schema/base-types.ts index 0d213542ba330..505785317e98c 100644 --- a/packages/@aws-cdk/cdk-cfnspec/lib/schema/base-types.ts +++ b/packages/@aws-cdk/cdk-cfnspec/lib/schema/base-types.ts @@ -3,17 +3,25 @@ export interface Documented { Documentation: string; } -export type PrimitiveType = 'String' | 'Long' | 'Integer' | 'Double' | 'Boolean' | 'Timestamp' | 'Json'; +export enum PrimitiveType { + String = 'String', + Long = 'Long', + Integer = 'Integer', + Double = 'Double', + Boolean = 'Boolean', + Timestamp = 'Timestamp', + Json = 'Json' +} export function isPrimitiveType(str: string): str is PrimitiveType { switch (str) { - case 'String': - case 'Long': - case 'Integer': - case 'Double': - case 'Boolean': - case 'Timestamp': - case 'Json': + case PrimitiveType.String: + case PrimitiveType.Long: + case PrimitiveType.Integer: + case PrimitiveType.Double: + case PrimitiveType.Boolean: + case PrimitiveType.Timestamp: + case PrimitiveType.Json: return true; default: return false; diff --git a/packages/@aws-cdk/cdk-cfnspec/lib/schema/property.ts b/packages/@aws-cdk/cdk-cfnspec/lib/schema/property.ts index 52b51be5524ee..a4685738c69a7 100644 --- a/packages/@aws-cdk/cdk-cfnspec/lib/schema/property.ts +++ b/packages/@aws-cdk/cdk-cfnspec/lib/schema/property.ts @@ -86,13 +86,17 @@ export interface UnionProperty extends PropertyBase { ItemTypes?: string[]; } -type UpdateType = 'Conditional' | 'Immutable' | 'Mutable'; +export enum UpdateType { + Conditional = 'Conditional', + Immutable = 'Immutable', + Mutable = 'Mutable' +} export function isUpdateType(str: string): str is UpdateType { switch (str) { - case 'Conditional': - case 'Immutable': - case 'Mutable': + case UpdateType.Conditional: + case UpdateType.Immutable: + case UpdateType.Mutable: return true; default: return false; diff --git a/packages/@aws-cdk/cdk-cfnspec/spec-input/000_CloudFormationResourceSpecification.json b/packages/@aws-cdk/cdk-cfnspec/spec-source/000_CloudFormationResourceSpecification.json similarity index 100% rename from packages/@aws-cdk/cdk-cfnspec/spec-input/000_CloudFormationResourceSpecification.json rename to packages/@aws-cdk/cdk-cfnspec/spec-source/000_CloudFormationResourceSpecification.json diff --git a/packages/@aws-cdk/cdk-cfnspec/spec-input/000_sam.spec.json b/packages/@aws-cdk/cdk-cfnspec/spec-source/000_sam.spec.json similarity index 100% rename from packages/@aws-cdk/cdk-cfnspec/spec-input/000_sam.spec.json rename to packages/@aws-cdk/cdk-cfnspec/spec-source/000_sam.spec.json diff --git a/packages/@aws-cdk/cdk-cfnspec/spec-input/500_Cognity_IdentityPoolRoleAttachment_patches.json b/packages/@aws-cdk/cdk-cfnspec/spec-source/500_Cognity_IdentityPoolRoleAttachment_patches.json similarity index 100% rename from packages/@aws-cdk/cdk-cfnspec/spec-input/500_Cognity_IdentityPoolRoleAttachment_patches.json rename to packages/@aws-cdk/cdk-cfnspec/spec-source/500_Cognity_IdentityPoolRoleAttachment_patches.json diff --git a/packages/@aws-cdk/cdk-cfnspec/spec-input/500_SAM_Serverless_Function_S3Event_Events_patch.json b/packages/@aws-cdk/cdk-cfnspec/spec-source/500_SAM_Serverless_Function_S3Event_Events_patch.json similarity index 100% rename from packages/@aws-cdk/cdk-cfnspec/spec-input/500_SAM_Serverless_Function_S3Event_Events_patch.json rename to packages/@aws-cdk/cdk-cfnspec/spec-source/500_SAM_Serverless_Function_S3Event_Events_patch.json diff --git a/packages/@aws-cdk/cdk-cfnspec/spec-input/500_SAM_Serverless_Function_S3Location_Version_patch.json b/packages/@aws-cdk/cdk-cfnspec/spec-source/500_SAM_Serverless_Function_S3Location_Version_patch.json similarity index 100% rename from packages/@aws-cdk/cdk-cfnspec/spec-input/500_SAM_Serverless_Function_S3Location_Version_patch.json rename to packages/@aws-cdk/cdk-cfnspec/spec-source/500_SAM_Serverless_Function_S3Location_Version_patch.json diff --git a/packages/@aws-cdk/cdk-cfnspec/spec-input/500_SSM_AssociationName_patch.json b/packages/@aws-cdk/cdk-cfnspec/spec-source/500_SSM_AssociationName_patch.json similarity index 100% rename from packages/@aws-cdk/cdk-cfnspec/spec-input/500_SSM_AssociationName_patch.json rename to packages/@aws-cdk/cdk-cfnspec/spec-source/500_SSM_AssociationName_patch.json diff --git a/packages/@aws-cdk/cdk-cfnspec/spec-input/500_SSM_AssociationName_patch.md b/packages/@aws-cdk/cdk-cfnspec/spec-source/500_SSM_AssociationName_patch.md similarity index 100% rename from packages/@aws-cdk/cdk-cfnspec/spec-input/500_SSM_AssociationName_patch.md rename to packages/@aws-cdk/cdk-cfnspec/spec-source/500_SSM_AssociationName_patch.md diff --git a/packages/@aws-cdk/cdk-cfnspec/spec-input/510_ElasticSearch_Domain_patches.json b/packages/@aws-cdk/cdk-cfnspec/spec-source/510_ElasticSearch_Domain_patches.json similarity index 100% rename from packages/@aws-cdk/cdk-cfnspec/spec-input/510_ElasticSearch_Domain_patches.json rename to packages/@aws-cdk/cdk-cfnspec/spec-source/510_ElasticSearch_Domain_patches.json diff --git a/packages/@aws-cdk/cdk-cfnspec/test/spec-validators.ts b/packages/@aws-cdk/cdk-cfnspec/test/spec-validators.ts index 2b0fac24bb6df..f729f97c18c70 100644 --- a/packages/@aws-cdk/cdk-cfnspec/test/spec-validators.ts +++ b/packages/@aws-cdk/cdk-cfnspec/test/spec-validators.ts @@ -3,6 +3,11 @@ import * as schema from '../lib/schema'; import { Specification } from '../lib/schema'; export function validateSpecification(test: Test, specification: Specification) { + validateResourceTypes(test, specification); + validatePropertyTypes(test, specification); +} + +function validateResourceTypes(test: Test, specification: Specification) { for (const typeName of Object.keys(specification.ResourceTypes)) { test.ok(typeName, 'Resource type name is not empty'); const type = specification.ResourceTypes[typeName]; @@ -10,6 +15,9 @@ export function validateSpecification(test: Test, specification: Specification) if (type.Properties) { validateProperties(typeName, test, type.Properties, specification); } if (type.Attributes) { validateAttributes(typeName, test, type.Attributes, specification); } } +} + +function validatePropertyTypes(test: Test, specification: Specification) { for (const typeName of Object.keys(specification.PropertyTypes)) { test.ok(typeName, 'Property type name is not empty'); const type = specification.PropertyTypes[typeName];