Basics
Start by generating or defining an OpenAPI specification (example petstore.yaml).
Then create a file orval.config.js at the root of your project:
Example of orval.config.js
import { defineConfig } from 'orval';export default defineConfig({'petstore-file-transformer': {output: {mode: 'single',target: './src/petstore.ts',schemas: './src/model',mock: true,},input: {target: './petstore.yaml',},},});
The output options configure how and where you want to write the generated code.
modespecifies how files are generated (default:single- only one file with everything)targetspecifies where the generated file(s) will be written by defaultschemasspecifies where the models will be written.mockgenerates mocks with the mocks generator (by default MSW). Mocks will be generated in the target file. Refer to the MSW documentation to set it up correctly in your project.
The input options configure the imported specification and any optional overrides.
targetspecifies the path to the OpenAPI specification fileoverridespecifies options to override the input specificationtransformeris used to transform the specification, such as adding a parameter to every request.
Consult the orval configuration reference to see all available options.
Was this page helpful?