Skip to content

test(core): add regression coverage for cross-file $ref schema exports (#1107) - #3381

Merged
melloware merged 2 commits into
orval-labs:masterfrom
wadakatu:test/issue-1107-cross-file-ref-exports
May 18, 2026
Merged

test(core): add regression coverage for cross-file $ref schema exports (#1107)#3381
melloware merged 2 commits into
orval-labs:masterfrom
wadakatu:test/issue-1107-cross-file-ref-exports

Conversation

@wadakatu

@wadakatu wadakatu commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds regression coverage for #1107 ("Type alias exports missing when using cross-file $ref").

Fix #1107 reported that a top-level components.schemas.X defined as a cross-file $ref (X → another file's X) generated a schema file containing the import but no export for the type — a dangling, unusable module.

I could not reproduce this on current master (v8.11.0): cross-file $ref schemas now resolve correctly and every referenced schema is emitted as a usable exported type. The issue appears to have been resolved as a side effect of the multi-file handling rework, but there was no test guarding the scenario, so a future change could silently reintroduce it.

This PR is test-only — it locks in the current correct behavior.

What's added

  • tests/specifications/issue-1107/ — a spec whose top-level components.schemas.{Pet,Pets,Error} are cross-file $refs into a second file, generated with split schemas (output.schemas).
  • issue-1107-cross-file-ref entry in tests/configs/default.config.ts, plus its generated snapshot.
  • A focused assertion in tests/api-generation.spec.ts verifying each referenced schema file emits its export (export interface Pet, export interface Error, and import type { Pet } + export type Pets = Pet[]), so a regression fails with a targeted message rather than only a full-file snapshot diff.

The focused test was confirmed to fail when the export line is removed from the generated output, so it genuinely guards the #1107 behavior.

Notes

Summary by CodeRabbit

  • Tests

    • Added tests validating correct handling and export of schemas referenced across files, including array type aliases and response types.
  • Chores

    • Added fixtures and configuration for cross-file reference validation and generated snapshots for models and endpoints to support the tests.

Review Change Stack

Copilot AI review requested due to automatic review settings May 18, 2026 15:12
@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 45a7e7aa-d297-409e-9134-206760e51b7a

📥 Commits

Reviewing files that changed from the base of the PR and between 97717e3 and 8cb7bf0.

📒 Files selected for processing (1)
  • tests/specifications/issue-1107/issue-1107.yaml

📝 Walkthrough

Walkthrough

Adds a test fixture and regression test for Issue 1107 to ensure Orval correctly exports interfaces and type aliases when OpenAPI schemas are referenced via cross-file external $ref. Includes OpenAPI specs, expected generated snapshots (models/endpoints), an Orval config entry, and a Vitest regression case.

Changes

Issue 1107 Cross-file $ref Test Fixture

Layer / File(s) Summary
OpenAPI test specifications with cross-file external references
tests/specifications/issue-1107/issue-1107.yaml, tests/specifications/issue-1107/issue-1107-petstore.yaml
Main OpenAPI spec defines /pets GET using $ref to Pets/Error in an external petstore YAML; petstore file defines Pet, Pets (array of Pet), and Error schemas.
Generated TypeScript model and endpoint snapshots
tests/__snapshots__/default/issue-1107-cross-file-ref/model/error.ts, tests/__snapshots__/default/issue-1107-cross-file-ref/model/pet.ts, tests/__snapshots__/default/issue-1107-cross-file-ref/model/pets.ts, tests/__snapshots__/default/issue-1107-cross-file-ref/model/index.ts, tests/__snapshots__/default/issue-1107-cross-file-ref/endpoints.ts
Adds expected generated outputs: Error and Pet interfaces; Pets exported as type Pets = Pet[]; model barrel re-exports; listPets endpoint calling axios.get('/pets') returning Promise<AxiosResponse<Pets>> and ListPetsResult type alias.
Test configuration and regression test
tests/configs/default.config.ts, tests/api-generation.spec.ts
Adds issue-1107-cross-file-ref Orval config entry and a Vitest case default issue-1107 that asserts generated model files export interfaces for object schemas and type aliases for array schemas referenced via cross-file $ref.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

openapi

Suggested reviewers

  • melloware
  • soartec-lab

Poem

🐰 Across the files, refs now dance with grace,
External schemas find their resting place,
Pet arrays alias, errors typed just right,
Cross-file exports gleam in snapshot light,
Issue 1107 tested — the fixtures sing tonight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding regression test coverage for cross-file $ref schema exports issue #1107.
Linked Issues check ✅ Passed The PR addresses issue #1107 by adding comprehensive regression test coverage including test fixtures, configuration, generated snapshots, and targeted assertions verifying that schema files export correct types when using cross-file $ref.
Out of Scope Changes check ✅ Passed All changes are directly scoped to adding test coverage for issue #1107: new test specs, config entries, snapshots, and test assertions. No unrelated code modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a regression test for issue #1107, ensuring that top-level components.schemas.X entries that are themselves cross-file $refs generate properly exported type aliases.

Changes:

  • New OpenAPI specs (issue-1107.yaml + external issue-1107-petstore.yaml) reproducing the cross-file $ref scenario.
  • New Orval config entry issue-1107-cross-file-ref plus a focused test asserting exports in generated model files.
  • Snapshot fixtures for the expected generated endpoints and model output.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/specifications/issue-1107/issue-1107.yaml Main spec referencing external schemas via $ref.
tests/specifications/issue-1107/issue-1107-petstore.yaml External spec defining Pet, Pets, Error.
tests/configs/default.config.ts Registers the new generation target.
tests/api-generation.spec.ts Adds regression test asserting exports for cross-file $ref aliases.
tests/snapshots/default/issue-1107-cross-file-ref/model/pets.ts Expected Pets alias output.
tests/snapshots/default/issue-1107-cross-file-ref/model/pet.ts Expected Pet interface output.
tests/snapshots/default/issue-1107-cross-file-ref/model/index.ts Expected model barrel.
tests/snapshots/default/issue-1107-cross-file-ref/model/error.ts Expected Error interface output.
tests/snapshots/default/issue-1107-cross-file-ref/endpoints.ts Expected endpoints output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +228 to +229
expect(await model('error.ts')).toContain('export interface Error {');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving as-is. export interface Error shadowing the global is pre-existing, generator-wide behavior — orval emits any schema named Error this way, independent of cross-file $ref. The original #1107 reproduction uses Error too, so keeping the name makes the fixture faithful to the issue. Renaming/suffixing to avoid global collisions is a separate generator concern, out of scope for this test-only PR.

expect(content).toContain('headers = unref(headers);');
});

test('default issue-1107 emits exports for schemas defined via cross-file $ref', async () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows the established pattern in this file. generated/ is produced by bun run generate-api before test:snapshots (see the npm scripts and CI), and every existing focused test here (issue-708/826/873/1026) reads from generated/ the same way — a per-test beforeAll would be inconsistent with the suite. The snapshots aren't unused either: describeApiGenerationSnapshots (test-utils/snapshot-testing.ts) scans generated/default/** and snapshot-compares every file, including issue-1107-cross-file-ref. The focused test is an additional targeted assertion on top of that.

Comment on lines +24 to +25
Pet:
$ref: './issue-1107-petstore.yaml#/components/schemas/Pet'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 8cb7bf0 — added a comment in issue-1107.yaml noting that Pet is intentionally reachable only transitively (via PetsPet[]), which is the referenced-but-not-path-used case #1107 is meant to exercise. YAML comments are stripped on parse, so generated output and snapshots are unchanged.

@melloware
melloware merged commit b978e04 into orval-labs:master May 18, 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.

Type alias exports missing when using cross-file $ref

3 participants