Skip to content

feat(aws): a curated enum overlay, so the highest-traffic properties stop being bare strings (#1497) - #2209

Merged
lex00 merged 4 commits into
mainfrom
feat/1497-aws-enum-overlay
Sep 7, 2026
Merged

lex00 merged 4 commits into
mainfrom
feat/1497-aws-enum-overlay

Conversation

@lex00

@lex00 lex00 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Closes #1497. Follow-up for the any half: #2205.

The problem

The generator emits literal unions only where the CFN spec declares AllowedValues, so InstanceType on EC2 is a bare string while the same property is a union on another resource in the same file, and a wrong enum fails at deploy rather than at tsc.

What this lands

A curated enum overlay, checked in at lexicons/aws/src/codegen/enum-overlay.json and merged over the spec at codegen time, so npm run generate needs no network. Eighteen entries, chosen by counting property usage across the examples, docs, skills, lint rules and composites and intersecting with what is bare today. The top of the list by traffic: Lambda Runtime, ELBv2 Protocol, AppAutoScaling ServiceNamespace and ScalableDimension, EC2 InstanceType, the five DynamoDB enums, RDS Engine, ELBv2 Scheme and TargetType, SNS Protocol. Three entries the issue names by hand have no corpus use but are included because the spec already types the identical property as a union elsewhere.

Each entry records its source and date: botocore service, apiVersion and shape, or a docs URL. A manual refresh script under lexicons/aws/scripts, wired as just refresh-enum-overlay, diffs the overlay against botocore's public JSON. It is not in package.json scripts, so no build step can reach it.

Precedence: the overlay only fills gaps and the spec wins. An entry whose property already declares an enum leaves the schema untouched and emits a warning naming it for retirement. An entry matching nothing is a hard error. Twenty codegen tests, including one asserting every literal the corpus writes is a member of its union.

Deliberately excluded, with reasons in the module doc: IpProtocol, which accepts any IANA protocol number; DBInstanceClass and EngineVersion, which are open fast-moving sets; and Type, which is polysemous across hundreds of declarations.

Version

Narrowing is breaking. The branch originally bumped the aws lexicon to 0.58.0, but chant-v0.58.0 was cut in lockstep before this merged, so that bump was dropped and the narrowing ships in the next lockstep release. The surface snapshot records names and required flags, not types, so surface-diff will not flag it; the release notes need a line.

For the reviewer

lexicons/aws/src/generated/ is gitignored, so the narrowed types are not in the diff. Run npm run generate in lexicons/aws and look at src/generated/index.d.ts; expect 18 overlay entries applied and 1626 enums, up from 1608.

Two adjacent findings, written up in the follow-up issue: cfn-lint's boto.json patch is fetched and never applied, and the narrowed declarations ship only behind the ./types export that nothing imports.

Gates

Run by the orchestrator on the rebased head after the agent's own run.

npm run generate (lexicons/aws)        Applied 18 curated enum overlay entries, 1626 enums
npx vitest run packages/core lexicons/aws   524 files, 8016 passed, 2 skipped
npx tsc --noEmit                       clean
npx tsx scripts/typecheck.ts           37 known failure(s), no regressions (37 baselined)
npx tsx scripts/check-lexicons.ts      every lexicon 23/23 tier-1, no untracked failures
chant dev check-lexicon lexicons/aws   23/23 tier 1
npx vitest run examples/fold-differential.test.ts   112 passed

🤖 Generated with Claude Code

https://claude.ai/code/session_01FoXyD9UvKQ5ZdhiR9JT1yB

lex00 and others added 4 commits September 7, 2026 09:57
…stop being bare strings (#1497)

The CloudFormation Registry spec declares AllowedValues on some properties
and not on others, and the split does not follow how often a property is
written: AWS::SageMaker::NotebookInstance.InstanceType was a union while
AWS::EC2::Instance.InstanceType was a bare string. Where the spec is silent
the generated type stops teaching the API, and a wrong value survives tsc
and chant build to fail at deploy, the most expensive tier there is.

src/codegen/enum-overlay.json is a checked-in list of (CFN type, JSON
pointer, values) entries merged into the raw schema before parsing, so a
curated enum reaches the .d.ts and the lexicon registry by exactly the path
a spec enum reaches them. It mints a named definition and points the
property at it, so the union is also an exported type a composite can name.
Nothing is fetched at build time.

The overlay runs in parseSchema rather than augmentSchemas because
augmentSchemas is skipped for a caller-supplied schema set, and the overlay
fetches nothing, so a fixture run and a real run stay on one code path.

The first set is chosen by counting property occurrences across examples/,
docs/src/content/docs, lexicons/aws/examples, src/skills, src/lint and
src/composites: Lambda Runtime (32), ELBv2 TargetGroup Protocol (28),
ApplicationAutoScaling ServiceNamespace (13) and ScalableDimension (12),
EC2 InstanceType (12), DynamoDB KeyType (9) and its four siblings, RDS
Engine (7), ELBv2 TargetType and Scheme (3 each), SNS Subscription
Protocol, plus EC2 Tenancy and VolumeType, which #1497 names and which the
spec already types as unions on other resources.

Precedence: the overlay only fills gaps. An entry whose property already
declares enum leaves the spec alone and warns that it is redundant, because
upstream is refreshed on every generate and a hand list allowed to win
would rot invisibly. An entry that matches nothing fails the generate.

Narrowing is breaking for anyone passing a value the union omits, so this
ships in the next lockstep release rather than carrying its own bump.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FoXyD9UvKQ5ZdhiR9JT1yB
…nst botocore (#1497)

Each overlay entry records the botocore service model or AWS documentation
page its values came from and the date they were read. This script reads
that back: it fetches the named service-2.json from botocore's develop
branch, diffs the enum shape against the checked-in values, and with
--write applies the difference and restamps the reviewed date. Entries
sourced from a documentation page are printed with their URL, since no
machine-readable form of those lists exists.

It reaches the network, so it is deliberately not a package script and
nothing in generate, bundle, validate or build calls it. `just
refresh-enum-overlay` is the only wiring.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FoXyD9UvKQ5ZdhiR9JT1yB
… overlay does (#1497)

The CloudFormation Concepts page said only "browse the generated TypeScript
types". It now says where a union comes from when the Registry schema has
one, the two things that add unions the Registry lacks (the cfn-lint patch
set and the curated overlay), the two rules the overlay follows, and that
narrowing a property is breaking and ships with a release of the lexicon.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FoXyD9UvKQ5ZdhiR9JT1yB
`test/no-egress.test.ts` closes the set of modules that call a network
primitive from both sides, so adding a `fetch` without a row fails CI. The
overlay refresh script fetches botocore service models and had no row, which
is the check working as designed.

Filed under codegen rather than maintenance: it sits with
`lexicons/cpln/src/spec/snapshot-cli.ts` and
`lexicons/azure/scripts/fetch-quickstart-templates.ts`, maintainer commands
that refresh a committed input to generation on a networked machine, so that
everything downstream reads the committed file. The maintenance phase is
this repository's own CI freshness checks against `api.github.com`, and this
runs in neither.

The generated docs twin is `npm run generate:egress-catalogue` output: one
table row and the module count moving 31 to 32.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FoXyD9UvKQ5ZdhiR9JT1yB
@lex00
lex00 merged commit 908764b into main Sep 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated AWS types fall back to string where the CFN spec omits AllowedValues, so the compiler stops teaching the API

1 participant