From 218af103c9eb12ad13ee12e49c20c14099ea5e91 Mon Sep 17 00:00:00 2001 From: Momo Kornher Date: Wed, 25 Oct 2023 14:28:47 +0100 Subject: [PATCH] chore(spec2cdk): support local, temporary service files To work with new features that are not released on CFN yet, we need the ability to provide local schema overrides. This changes adds support for this, by importing additional schema files into the model database before codegen. --- tools/@aws-cdk/spec2cdk/README.md | 5 +++++ tools/@aws-cdk/spec2cdk/lib/generate.ts | 7 +++++++ tools/@aws-cdk/spec2cdk/package.json | 1 + tools/@aws-cdk/spec2cdk/temporary-schemas/us-east-1/.keep | 0 4 files changed, 13 insertions(+) create mode 100644 tools/@aws-cdk/spec2cdk/temporary-schemas/us-east-1/.keep diff --git a/tools/@aws-cdk/spec2cdk/README.md b/tools/@aws-cdk/spec2cdk/README.md index 8e03fca518598..deeb57fdfec12 100644 --- a/tools/@aws-cdk/spec2cdk/README.md +++ b/tools/@aws-cdk/spec2cdk/README.md @@ -37,6 +37,11 @@ Path patterns can use the following variables: ``` +## Temporary Schemas + +You can import additional, temporary CloudFormation Registry Schemas to test new functionality that is not yet published in `@aws-cdk/aws-service-spec`. +To do this, drop the schema file into `temporary-schemas/us-east-1` and it will be imported on top of the default model. + ## Use as @aws-cdk/cfn2ts replacement You can use the `cfn2ts` binary as a drop-in replacement for the existing `@aws-cdk/cfn2ts` command. diff --git a/tools/@aws-cdk/spec2cdk/lib/generate.ts b/tools/@aws-cdk/spec2cdk/lib/generate.ts index 9499e9329f3be..d52d3b4f9e601 100644 --- a/tools/@aws-cdk/spec2cdk/lib/generate.ts +++ b/tools/@aws-cdk/spec2cdk/lib/generate.ts @@ -1,5 +1,6 @@ import * as path from 'path'; import { loadAwsServiceSpec } from '@aws-cdk/aws-service-spec'; +import { DatabaseBuilder } from '@aws-cdk/service-spec-importers'; import { SpecDatabase } from '@aws-cdk/service-spec-types'; import { TypeScriptRenderer } from '@cdklabs/typewriter'; import * as fs from 'fs-extra'; @@ -118,6 +119,12 @@ export interface GenerateOutput { export async function generate(modules: GenerateModuleMap, options: GenerateOptions) { enableDebug(options); const db = await loadAwsServiceSpec(); + + // Load additional schema files + await new DatabaseBuilder(db as any, { validate: false }) + .importCloudFormationRegistryResources(path.join(__dirname, '..', 'temporary-schemas')) + .build(); + return generator(db, modules, options); } diff --git a/tools/@aws-cdk/spec2cdk/package.json b/tools/@aws-cdk/spec2cdk/package.json index 0e8a70549ec93..d798368eaed32 100644 --- a/tools/@aws-cdk/spec2cdk/package.json +++ b/tools/@aws-cdk/spec2cdk/package.json @@ -33,6 +33,7 @@ "license": "Apache-2.0", "dependencies": { "@aws-cdk/aws-service-spec": "^0.0.23", + "@aws-cdk/service-spec-importers": "^0.0.1", "@aws-cdk/service-spec-types": "^0.0.23", "@cdklabs/tskb": "^0.0.1", "@cdklabs/typewriter": "^0.0.2", diff --git a/tools/@aws-cdk/spec2cdk/temporary-schemas/us-east-1/.keep b/tools/@aws-cdk/spec2cdk/temporary-schemas/us-east-1/.keep new file mode 100644 index 0000000000000..e69de29bb2d1d