Skip to content

Commit

Permalink
Follow-ups after #259
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainMuller committed Jul 10, 2018
1 parent aa404a0 commit c868ea6
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/cdk-cfnspec/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.ts
!*.d.ts
spec-input
spec-source
10 changes: 8 additions & 2 deletions packages/@aws-cdk/cdk-cfnspec/build-tools/build.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
/*
* 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';
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()) {
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion packages/@aws-cdk/cdk-cfnspec/build-tools/update.sh
Original file line number Diff line number Diff line change
@@ -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
24 changes: 16 additions & 8 deletions packages/@aws-cdk/cdk-cfnspec/lib/schema/base-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions packages/@aws-cdk/cdk-cfnspec/lib/schema/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/cdk-cfnspec/test/spec-validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ 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];
test.notEqual(type.Documentation, null, `${typeName} is documented`);
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];
Expand Down

0 comments on commit c868ea6

Please sign in to comment.