#3832·orval

feat(core): artifact groups with per-group entry-point barrels

Author: the-ultCreated Aug 7, 2026Updated Sep 23, 2026
Labelsenhancement

This was generated by AI during triage.

Split out of #3704, which is closed. Part A (de-inlined mocks, tags-split client barrel) shipped in #3928. This issue tracks Part B: artifact groups with per-group barrels.

What this is about

One OpenAPI document can produce artifacts for three runtimes: schemas and types (universal), HTTP clients (browser), and MSW handlers plus Faker factories (Node test runners, Storybook). Each should be importable on its own, so a Node test that loads MSW handlers never evaluates @angular/core, and the app never loads msw or @faker-js/faker. In a monorepo the groups often become separate packages, so generated files must not reach across groups with deep relative paths either.

No new top-level key. The group model falls out of the existing options: output.target (client), output.schemas (schemas), and the MSW and Faker generator paths, with indexFiles / mock.indexMockFiles producing the barrels.

Already working on master (re-verified 2026-09-22 @ 5dd8f703b)

Checked by generating the config below against samples/angular-app/petstore.yaml, both with TypeScript schemas and with type: 'zod' plus retrievalClient: 'both'.

  • Each group barrel re-exports only its own group. angular/index.ts exports the *.service and *.resource files, schemas/index.ts exports only schema files (not index.faker), and index.msw.ts / index.faker.ts export only mocks. tags-split writes the client index.ts whenever indexFiles is true (#3928), and it re-exports *.resource.ts (#3815).
  • Mock and client files honor schemas.importPath. Services, *.resource.ts (#3965, which covered what #3813 set out to do), *.msw.ts and *.faker.ts all import schema types from the package specifier. Operation faker files import schema factories from <schemas.importPath>/index.faker, or from schemasImportPath when set.
  • clean prunes configured mock directories (#3814).
  • Names and overrides can't drift apart: every group comes from one config run.

So two of the original acceptance items ("barrels only export their own group", "mock and faker files honor schemas.importPath / schemasImportPath") were already met, and needed tests rather than code.

What was still missing, and why

  1. MSW files import Faker through a relative path. With MSW and Faker in different directories, msw/pets/pets.msw.ts imports and re-exports its response factories from '../../faker/pets/pets.faker'. Once the two groups are separate packages, that path crosses a package boundary, which @nx/enforce-module-boundaries rejects and which breaks when the packages are built on their own. The Faker group had no importPath to route through.
  2. Schema factories land in the schemas directory. With schemas: true, <schemas>/index.faker.ts is written next to the schemas even when the Faker generator has its own path. The schemas barrel doesn't re-export it, so nothing leaks at runtime, but the schemas package's source now imports @faker-js/faker, which dependency-check lint rules flag. schemasImportPath changes how that file is imported, not where it is written. (Raised on #3707, never answered.)
  3. No sample, no Node-side test, no docs describing the options as one model.

Proposed change

  • New Faker generator option importPath: package specifier for the Faker group barrel. MSW files import (and re-export) the get<Op>ResponseMock factories from it instead of the relative path. split and tags-split only, because those are the modes that write MSW and Faker to separate files.
  • New Faker generator option schemasPath: output directory for the schemas: true factories file. Defaults to the schemas directory, so existing output doesn't change. The relocated file imports schema types from schemas.importPath, or through a relative path back into the schemas directory. Operation faker files import it relatively, or through schemasImportPath, which now also works without schemas.importPath when schemasPath is set. Validation: requires schemas: true and output.schemas, and can't equal the Faker path when indexMockFiles is on (both files are called index.faker.ts). When schemasPath sits inside the Faker path and indexMockFiles is on, the Faker barrel re-exports the factories, so the Faker package's entry point exposes get<Schema>Mock. The export list is explicit and leaves out names an operation mock already exports (e.g. a ListPetsResponse schema and the listPets operation both produce getListPetsResponseMock), because a duplicate re-export fails with TS2308.
  • An Artifact groups section in output.mdx that ties the options together.
typescript
export default defineConfig({
  referenceApi: {
    input: { target: './openapi.yaml' },
    output: {
      mode: 'tags-split',
      client: 'angular',
      target: './src/generated/angular', // client group
      indexFiles: true, // -> angular/index.ts
      schemas: {
        path: './src/generated/schemas',
        importPath: '@acme/reference-models',
      },
      mock: {
        indexMockFiles: true, // -> index.msw.ts, index.faker.ts
        generators: [
          { type: 'msw', path: './src/generated/msw' },
          {
            type: 'faker',
            path: './src/generated/faker',
            importPath: '@acme/reference-mocks/faker', // new
            schemas: true,
            schemasPath: './src/generated/faker/schemas', // new
          },
        ],
      },
    },
  },
});
src/generated/
├── angular/  index.ts         client, imports @angular/*
├── schemas/  index.ts         types, no runtime imports
├── msw/      index.msw.ts     handlers, imports msw and @acme/reference-mocks/faker
└── faker/    index.faker.ts   factories, imports @faker-js/faker
    └── schemas/index.faker.ts get<Schema>Mock factories

Out of scope

Orval doesn't generate Nx project config, ng-package.json or package.json exports maps. Those stay with the host project.

Acceptance

  • Every group barrel (index.ts, index.msw.ts, index.faker.ts, schemas index.ts) re-exports only files from its own group, covered by a test that uses distinct directories per group. (Already true; needs the test.)
  • Generated cross-group imports in mock and faker files honor schemas.importPath and schemasImportPath when set. (Already true.)
  • MSW files import Faker factories through the Faker generator's importPath when set.
  • The Faker generator's schemasPath writes the schema factories outside the schemas directory, and every import of them resolves.
  • Relocated schema factories inside the Faker directory are reachable through the Faker barrel, without duplicate-name re-exports.
  • Operation names, type names and overrides stay identical across groups from one config run. (True by construction.)
  • Existing configs generate byte-identical output.
  • A sample under samples/ builds all four groups from one config, with a Node-side test that imports only the MSW barrel and asserts @angular/core is never loaded.
  • docs/content/docs/reference/configuration/output.mdx gets a section describing the group model that links mock.path, mock.indexMockFiles, mock.inline, schemas.importPath, mock.generators[].schemasImportPath, and the new importPath and schemasPath.