Repository navigation
fix(cli): keep [] and null in authored error examples - #24
Merged
Merged
Conversation
OpenAPI error-response and webhook examples are converted without a schema
by convertToFullExample. It dropped empty arrays and nulls, so an error
example such as
success: false
errors: [...]
messages: []
result: null
lost `messages` and `result`, and fern check failed with
`Example is missing required property "response.body.messages"`
(valid-example-error) on every such error declaration.
convertToFullExample now keeps `[]` and `null`. This also stops an explicit
`[]` on an unknown schema from being replaced with a generated placeholder.
The optional-container guard in ExampleTypeFactory now keeps an empty array
only when the example the array builder used was an authored `[]`. A
non-empty example whose items all fail to build is omitted, as before.
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation is consistent with its callers and has comprehensive regression coverage.
0 open findings
What changed in this PR
Fixes OpenAPI example conversion so authored empty arrays and nulls survive error/webhook processing and validation.
Changes:
- Preserve
[]andnullin schema-free example conversion. - Distinguish authored empty arrays from arrays emptied by failed item conversion.
- Add unit, parser snapshot, and CLI end-to-end regression coverage.
| File | Description |
|---|---|
packages/cli/ete-tests/src/tests/validate/validate.test.ts |
Registers the regression fixture. |
packages/cli/ete-tests/src/tests/validate/fixtures/error-examples-empty-arrays/fern/openapi.yml |
Defines end-to-end error examples. |
packages/cli/ete-tests/src/tests/validate/fixtures/error-examples-empty-arrays/fern/generators.yml |
Configures fixture input. |
packages/cli/ete-tests/src/tests/validate/fixtures/error-examples-empty-arrays/fern/fern.config.json |
Configures the fixture project. |
packages/cli/ete-tests/src/tests/validate/__snapshots__/validate.test.ts.snap |
Records successful validation. |
packages/cli/cli/changes/unreleased/fix-openapi-error-example-empty-arrays.yml |
Documents the CLI fix. |
packages/cli/api-importers/openapi/openapi-ir-to-fern-tests/src/__test__/fixtures/error-examples-empty-arrays/openapi.yml |
Adds importer regression input. |
packages/cli/api-importers/openapi/openapi-ir-to-fern-tests/src/__test__/fixtures/error-examples-empty-arrays/fern/generators.yml |
Configures importer fixture input. |
packages/cli/api-importers/openapi/openapi-ir-to-fern-tests/src/__test__/fixtures/error-examples-empty-arrays/fern/fern.config.json |
Configures the importer fixture. |
packages/cli/api-importers/openapi/openapi-ir-to-fern-tests/src/__test__/__snapshots__/openapi/error-examples-empty-arrays.json |
Captures generated Fern definitions. |
packages/cli/api-importers/openapi/openapi-ir-to-fern-tests/src/__test__/__snapshots__/openapi-ir/error-examples-empty-arrays.json |
Captures preserved IR values. |
packages/cli/api-importers/openapi/openapi-ir-parser/src/schema/examples/ExampleTypeFactory.ts |
Tightens explicit-empty-array detection. |
packages/cli/api-importers/openapi/openapi-ir-parser/src/schema/examples/convertToFullExample.ts |
Preserves empty arrays and nulls. |
packages/cli/api-importers/openapi/openapi-ir-parser/src/schema/examples/__tests__/ExampleTypeFactory.test.ts |
Tests array-generation edge cases. |
packages/cli/api-importers/openapi/openapi-ir-parser/src/schema/examples/__tests__/convertToFullExample.test.ts |
Tests schema-free conversion behavior. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
teamchong
approved these changes
Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to 9192cdd (the cherry-pick of fern-api/fern#17776). That commit fixed explicit
[]on the schema-aware path inExampleTypeFactory, which handles request and success-response examples. It didn't cover error responses.fern checkstill fails on specs that have an error envelope like this:Cause
Authored error examples (and webhook payload examples) are not built by
ExampleTypeFactory.generateIrpasses them toconvertToFullExample, which converts values without a schema. That function returnedundefinedfor[]and fornull, and the object branch drops any property whose value converts toundefined. As a result,messagesandresultwere both missing from the generated error declaration:Changes
convertToFullExamplenow keeps[]asFullExample.array([])andnullasFullExample.null({}). The validator already acceptsnullfor optional and nullable properties. This change also fixes theunknownschema case, where an explicit[]was being replaced with a generated{"key": "value"}placeholder.[]. Before, it kept any array example, so a non-empty example whose items all failed to build came out as[]. That case is omitted again, as raised in review on the upstream PR.Tests
convertToFullExample.test.ts: a nested[]andnullin an error body, a top-level[], and[null].ExampleTypeFactory.test.ts: a required array property set to[], an optional array with a schema-levelexample: [], and an optional array whose non-empty example has no buildable items.openapi-ir-to-fern-testsfixtureerror-examples-empty-arrays: the snapshot showsmessages: []andresult: nullon the generatedBadRequestErrorandServiceUnavailableErrorexamples.validatefixture with the same spec.fern checkreports "All checks passed". On the base branch it fails with the three errors shown above.Results:
openapi-ir-parser: all 106 tests pass, andtscis clean.openapi-ir-to-fern-tests: all 321 tests pass. The only snapshot changes are the new fixture.ir-generator-tests: all pass.Not in scope:
hasExampleignores a schema-levelexampleon arrays. WhenignoreOptionalsis set, an optional array with a schema-levelexample: []is still left out of generated request examples. Leaving it out is valid (it's optional), and changing it would also pull non-empty array examples into every generated request example.