Skip to content

Commit

Permalink
chore(spec2cdk): support local, temporary service files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mrgrain committed Oct 25, 2023
1 parent de7fb04 commit bd2fcf8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tools/@aws-cdk/spec2cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions tools/@aws-cdk/spec2cdk/lib/generate.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit bd2fcf8

Please sign in to comment.