feat(codegen/cloudflare): add lookup and adopt methods to all models (#1142) #111
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/cloudflare-lookup-adopt-1142"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
extensionModelGenerator.ts)Codegen changes
codegen/cloudflare/extensionModelGenerator.tslistAllimport,collectFilterableFieldshelpercodegen/cloudflare/extensionModelGenerator_test.tscodegen/shared/readmeGenerator.tscodegen/designs/cloudflare.mdGenerated output
186 model files across 76 services regenerated with:
lookupandadoptmethodsVerification
deno check,deno lint,deno fmtcleanTest plan
swamp extension source add+ method runCloses swamp-club/lab#1142
🤖 Generated with Claude Code
Code Review
Blocking Issues
None.
Suggestions
Misleading test name (
codegen/cloudflare/extensionModelGenerator_test.ts, line 577): The test is named"adopt - uses cursor pagination style in lookup for cursor-paginated resources"but it exercises thelookupmethod (by asserting onlistAll), notadopt. Theadoptmethod callsreaddirectly and never toucheslistAll. Renaming to"lookup - uses cursor pagination style for cursor-paginated resources"would match the assertion.Lookup can be vacuously unfilterable (
codegen/cloudflare/extensionModelGenerator.ts,collectFilterableFields): If a resource has only non-scalar properties (arrays, objects),filterFieldsis empty and the generatedlookupmethod unconditionally throws "At least one global argument must be set to filter by" — even with all GlobalArgs populated. The design doc acknowledges this is intentional for now, but it may surprise users of such resources. Consider a generator-time warning when a resource produces an unfilterablelookup.collectFilterableFieldsmerge order (extensionModelGenerator.ts, line 697): The function mergesupdatePropertiesfirst, thencreateProperties(so create wins on collision). This is consistent withbuildGlobalArgsProperties, but the opposite of the natural expectation (update fields refine create fields). A comment explaining the intentional ordering would help future maintainers.Adversarial Review
Reviewed files (skipping all
model/auto-generated files per CLAUDE.md):codegen/cloudflare/extensionModelGenerator.tscodegen/cloudflare/extensionModelGenerator_test.tscodegen/cloudflare/__snapshots__/extensionModelGenerator_test.ts.snapcodegen/designs/cloudflare.mdcodegen/shared/readmeGenerator.tsMedium
Update method lacks
identifyingFieldguard —extensionModelGenerator.ts:381-431The
syncmethod generates a guard before using the stored identifying field:The
updatemethod does NOT generate this guard. If stored state is corrupted (e.g., the create response lacked the field, or state was manually edited), the update method will passundefinedas the resource ID to theupdate()function, constructing a request toendpoint/undefined. Depending on the Cloudflare API, this could:Breaking example: User creates a resource, then manually edits the stored JSON and removes the
idfield. Runningupdatewould callupdate(endpoint, undefined, body, "PATCH", auth), producing a PATCH tohttps://api.cloudflare.com/client/v4/zones/{zone_id}/dns_records/undefined.Suggested fix: Add the same guard as sync before line 424:
Design doc
listAllsignature doesn't match generated code —codegen/designs/cloudflare.mdsection 10 (line ~715)The design doc shows
listAllwith 3 parameters:But the generated code passes 4 arguments (e.g., snapshot line 120):
The 4th argument (auth overrides) is missing from the documented signature. Anyone reading the design doc to understand the shared lib contract will be misled.
Suggested fix: Update the
listAllandtryFindByFieldsignatures in section 10 to include the auth parameter.Low
Grammar: "a" instead of "an" before vowel-starting display names —
extensionModelGenerator.ts:207,239,283,350,357The generated description uses a hardcoded article:
"Create a ${singular}". For display names starting with a vowel sound (e.g., "Address Map", "OAuth Client"), this produces "Create a Address Map" instead of "Create an Address Map". This appears in thecreate,get,lookup,adopt,delete, andsyncmethod descriptions. Visible in the snapshot at line 747:"Create a Address Map".Suggested fix: Add a helper like:
paginationStyle: "none"could produce invalid generated code —extensionModelGenerator.ts:307The
CloudflareResource.paginationStyletype (defined inpipeline.ts) allows"page" | "cursor" | "none". Thelookupmethod generator interpolates it directly:listAll(endpoint, "${resource.paginationStyle}", ...). If a resource withpaginationStyle: "none"reaches the generator, the generated code would calllistAll(endpoint, "none", ...)— a value the shared lib doesn't handle. The pipeline likely prevents this, but the generator itself doesn't validate.Verdict
PASS — The code is well-structured, follows existing patterns from other providers, has good test coverage (5 snapshot tests + 5 behavioral tests), and the design doc is thorough. The update-method guard gap (Medium #1) is a real inconsistency with the sync method but has low probability of triggering in practice since state is always written by methods that include the identifying field. The design doc signature mismatch (Medium #2) is a documentation accuracy issue. Neither is blocking.