Skip to content

fix(cli): fix endpoint example generation for global headers, nullable params, and recursive types#12342

Merged
iamnamananand996 merged 7 commits intomainfrom
devin/1771015074-fix-global-header-example-failure
Feb 16, 2026
Merged

fix(cli): fix endpoint example generation for global headers, nullable params, and recursive types#12342
iamnamananand996 merged 7 commits intomainfrom
devin/1771015074-fix-global-header-example-failure

Conversation

@iamnamananand996
Copy link
Member

@iamnamananand996 iamnamananand996 commented Feb 13, 2026

Description

Refs: Devin session
Requested by: @iamnamananand996

Three related fixes for endpoint example generation in the OpenAPI importer and IR generator:

1. Global header example failure drops all endpoint examples
When a global header's schema cannot produce an example (e.g. literal<2025-09-18> without quotes), ExampleEndpointFactory.buildEndpointExample returned an empty array for every endpoint, causing all userSpecifiedExamples to be dropped from the IR. Reported via polytomic/polytomic-python#9 — regression introduced in CLI v0.64.23 (2194f78).

2. hasExample() ignores nullable/optional wrappers
ExampleTypeFactory.hasExample() did not recurse into nullable or optional wrappers, silently dropping params that had examples inside those wrappers.

3. Recursive types cause cascading example failures
When cycle detection triggered in generateTypeReferenceExample (v1), it returned failure, which cascaded up and killed the entire parent example. Now generates minimal stub examples with leaf (primitive/enum/literal) properties filled in, so parent examples survive.

Changes Made

  • ExampleEndpointFactory.ts: Removed the return [] early-exit when a global header example is null. The header is gracefully skipped instead — matching existing behavior for non-required regular headers.
  • ExampleTypeFactory.ts: Added nullable and optional cases to hasExample() that recurse into the wrapped schema.
  • generateTypeReferenceExample.ts: Replaced cycle-detection failure return with generateMinimalNamedExample() — a new function (~200 lines) that produces stub examples for objects (leaf properties only), enums (first value), aliases (resolve or empty object), and unions (first no-properties variant). Undiscriminated unions still return failure.
  • generateTypeReferenceExample.test.ts: Updated existing cycle tests to expect stubs instead of failures; added new BulkSchedule-like 3-way cycle test case.
  • Snapshots: Updated example-depth.json (stub left: {}, right: {} at cycle boundary) and simple-fhir.json (recursive FHIR types now produce stubs instead of empty examples).
  • versions.yml: Single consolidated changelog entry for CLI v3.78.1.
  • Updated README.md generator (if applicable) — N/A

Testing

  • All 346 turbo tasks pass (compile + test)
  • All seed test results pass (23 generators)
  • git diff --exit-code CI check passes (snapshots committed)
  • IR generator tests pass with updated snapshots (311 tests + 1 skipped)
  • Manual verification with polytomic OpenAPI spec confirmed endpoint examples restored
  • No dedicated test for the "unresolvable global header schema" path in ExampleEndpointFactory

Review Checklist

  • generateMinimalNamedExample edge cases: The new stub generator handles objects, enums, aliases, and unions. Verify the logic for each branch, especially:
    • isLeafTypeReference intentionally returns false for lists/maps/sets — recursive containers get skipped in stubs
    • undiscriminatedUnion returns failure (could still cascade in some schemas)
    • Hardcoded maxDepth: 3 and skipOptionalProperties: true for leaf property generation within stubs
  • Snapshot correctness: The simple-fhir.json diff is massive (~17M chars). Spot-check a few recursive types (e.g., Patient, Account, Script) to verify stubs look reasonable.
  • Silent skip vs. warning: Null global header examples are silently skipped. Consider adding this.logger.trace(...) for debuggability.

… endpoint examples

Co-Authored-By: naman.anand@buildwithfern.com <iamnamananand996@gmail.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@github-actions
Copy link
Contributor

🌱 Seed Test Selector

Select languages to run seed tests for:

  • Python
  • TypeScript
  • Java
  • Go
  • Ruby
  • C#
  • PHP
  • Swift
  • Rust
  • OpenAPI
  • Postman

How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR.

fern-support and others added 4 commits February 14, 2026 04:36
Traverse nullable/optional wrappers when checking for examples and generate minimal stub examples on recursive cycle detection. ExampleTypeFactory.hasExample now recurses into nullable/optional containers so examples (e.g. nullable query params) are not dropped during OpenAPI parsing. The v1 example generator (generateTypeReferenceExample) returns a minimal filled stub for named types when recursion is detected instead of failing, filling only leaf properties (primitives/enums/literals) to avoid cascade failures. Tests were updated/extended to reflect the new behavior (including a BulkSchedule-like 3-way cycle), and versions.yml was bumped with a changelog entry describing the fixes. Minor imports were adjusted to support the new helper functions.
Adjust formatting in packages/commons/ir-utils/src/examples/v1/generateTypeReferenceExample.ts: expand inline object literals into multi-line form for the alias shape and the failure return values in recursive union and undiscriminated union cases. This is a whitespace/formatting change only to improve readability; no logic was modified.
Refresh test snapshot to match new generated examples and shapes for the v3 SDK. Changes include an updated example id, expanded jsonExample values (adding left/right empty objects), and richer type/shape metadata for the TreeNode optional/container fields (including empty jsonExample placeholders and named type details). This is a snapshot-only update under packages/cli/api-importers/v3-importer-tests/src/__test__/__snapshots__/v3-sdks/example-depth.json.
Co-Authored-By: naman.anand@buildwithfern.com <iamnamananand996@gmail.com>
@devin-ai-integration devin-ai-integration bot changed the title fix(cli): skip global header example failures instead of dropping all endpoint examples fix(cli): fix endpoint example generation for global headers, nullable params, and recursive types Feb 14, 2026
devin-ai-integration bot and others added 2 commits February 16, 2026 16:23
…ailure

Co-Authored-By: naman.anand@buildwithfern.com <iamnamananand996@gmail.com>
Co-Authored-By: naman.anand@buildwithfern.com <iamnamananand996@gmail.com>
@iamnamananand996 iamnamananand996 enabled auto-merge (squash) February 16, 2026 16:27
@iamnamananand996 iamnamananand996 merged commit 3d9d1ac into main Feb 16, 2026
80 checks passed
@iamnamananand996 iamnamananand996 deleted the devin/1771015074-fix-global-header-example-failure branch February 16, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants