feat(core): artifact groups with per-group entry-point barrels
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.tsexports the*.serviceand*.resourcefiles,schemas/index.tsexports only schema files (notindex.faker), andindex.msw.ts/index.faker.tsexport only mocks.tags-splitwrites the clientindex.tswheneverindexFilesis 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.tsand*.faker.tsall import schema types from the package specifier. Operation faker files import schema factories from<schemas.importPath>/index.faker, or fromschemasImportPathwhen set. cleanprunes 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
- MSW files import Faker through a relative path. With MSW and Faker in different directories,
msw/pets/pets.msw.tsimports 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-boundariesrejects and which breaks when the packages are built on their own. The Faker group had noimportPathto route through. - Schema factories land in the schemas directory. With
schemas: true,<schemas>/index.faker.tsis written next to the schemas even when the Faker generator has its ownpath. 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.schemasImportPathchanges how that file is imported, not where it is written. (Raised on #3707, never answered.) - 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) theget<Op>ResponseMockfactories from it instead of the relative path.splitandtags-splitonly, because those are the modes that write MSW and Faker to separate files. - New Faker generator option
schemasPath: output directory for theschemas: truefactories file. Defaults to the schemas directory, so existing output doesn't change. The relocated file imports schema types fromschemas.importPath, or through a relative path back into the schemas directory. Operation faker files import it relatively, or throughschemasImportPath, which now also works withoutschemas.importPathwhenschemasPathis set. Validation: requiresschemas: trueandoutput.schemas, and can't equal the FakerpathwhenindexMockFilesis on (both files are calledindex.faker.ts). WhenschemasPathsits inside the FakerpathandindexMockFilesis on, the Faker barrel re-exports the factories, so the Faker package's entry point exposesget<Schema>Mock. The export list is explicit and leaves out names an operation mock already exports (e.g. aListPetsResponseschema and thelistPetsoperation both producegetListPetsResponseMock), because a duplicate re-export fails with TS2308. - An
Artifact groupssection inoutput.mdxthat ties the options together.
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 factoriesOut 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, schemasindex.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.importPathandschemasImportPathwhen set. (Already true.) - MSW files import Faker factories through the Faker generator's
importPathwhen set. - The Faker generator's
schemasPathwrites 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/coreis never loaded. -
docs/content/docs/reference/configuration/output.mdxgets a section describing the group model that linksmock.path,mock.indexMockFiles,mock.inline,schemas.importPath,mock.generators[].schemasImportPath, and the newimportPathandschemasPath.
Source: orval-labs/orval