This directory contains sample projects demonstrating orval with various frameworks and configurations. Each sample is a standalone project within the monorepo workspace.
Create a directory under samples/ with the four files described below, then run bun install to link orval@workspace. The sample does not need to be directly under samples/ and can be under samples/<GROUP NAME>/.
samples/
└── <sample-name>/
├── package.json
├── orval.config.ts
├── vitest.snapshots.ts
└── api-generation.spec.ts
Update <ORVAL OUTPUT DIR>
Important
Remember to run bun install to link orval@workspace.
Update paths.
import { defineConfig } from 'orval';
export default defineConfig({
<PROJECT_NAME>: {
input: './<OPENAPI SPEC FILE>',
output: {
// DO NOT PUT OTHER FILES IN THE OUTPUT DIR
target: './<OUTPUT DIR>',
// keep these
formatter: 'prettier',
clean: true,
},
},
});No changes needed.
import { defineConfig } from 'vitest/config';
import pkg from './package.json' with { type: 'json' };
export default defineConfig({
test: {
name: { label: pkg.name },
include: ['api-generation.spec.ts'],
silent: 'passed-only',
},
});Update the paths.
- import path to snapshot-testing
dirsto point to<ORVAL OUTPUT DIR>rootDirto point repo root
import path from 'node:path';
import { describeApiGenerationSnapshots } from '../../test-utils/snapshot-testing';
await describeApiGenerationSnapshots({
dirs: [path.resolve(import.meta.dirname, '<PATH>', '<TO>', '<OUTPUT>')],
snapshotsDir: path.resolve(import.meta.dirname, '__snapshots__'),
rootDir: path.resolve(import.meta.dirname, '..', '..'), // should match the `..` in the import above
});
{ // other props omitted... "scripts": { "generate-api": "orval", "test:snapshots": "vitest run --config vitest.snapshots.ts", "test:snapshots:update": "bun run test:snapshots --update", "clean": "rimraf .turbo dist <ORVAL OUTPUT DIR>", "nuke": "rimraf .turbo dist node_modules <ORVAL OUTPUT DIR>", }, "devDependencies": { "orval": "workspace:*", "rimraf": "catalog:", "vitest": "catalog:", }, }