|
| 1 | +--- |
| 2 | +id: migration-v8 |
| 3 | +title: Migration Guide to v8 |
| 4 | +--- |
| 5 | + |
| 6 | +This guide explains the changes required to migrate from Orval v7 to v8. |
| 7 | + |
| 8 | +## 1. Converted to ESM (ECMAScript Modules) |
| 9 | + |
| 10 | +The project has been fully converted from CommonJS to ESM. This modernizes the codebase and aligns with the JavaScript ecosystem's direction. |
| 11 | + |
| 12 | +### Key Changes |
| 13 | + |
| 14 | +- All packages now use `"type": "module"` in package.json |
| 15 | +- Import/export syntax instead of require() |
| 16 | +- Node.js 22.18 or higher is required |
| 17 | +- Configuration files should use `.mjs` extension or set `"type": "module"` |
| 18 | + |
| 19 | +### How to migrate |
| 20 | + |
| 21 | +#### Update Node.js version |
| 22 | + |
| 23 | +Ensure you're using Node.js 22.18 or higher: |
| 24 | + |
| 25 | +```bash |
| 26 | +node --version # Should be >= 22.18.0 |
| 27 | +``` |
| 28 | + |
| 29 | +#### Update configuration files |
| 30 | + |
| 31 | +If you're using a JavaScript configuration file, either: |
| 32 | + |
| 33 | +1. Rename it to use `.mjs` extension: |
| 34 | + |
| 35 | +```bash |
| 36 | +mv orval.config.js orval.config.mjs |
| 37 | +``` |
| 38 | + |
| 39 | +2. Or add `"type": "module"` to your package.json: |
| 40 | + |
| 41 | +```diff:package.json |
| 42 | +{ |
| 43 | + "name": "your-project", |
| 44 | ++ "type": "module", |
| 45 | + ... |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +#### Update imports in your code |
| 50 | + |
| 51 | +If you were importing Orval programmatically: |
| 52 | + |
| 53 | +```diff:your-script.js |
| 54 | +- const { generate } = require('orval'); |
| 55 | ++ import { generate } from 'orval'; |
| 56 | +``` |
| 57 | + |
| 58 | +#### Update dynamic imports |
| 59 | + |
| 60 | +If you were using dynamic imports: |
| 61 | + |
| 62 | +```diff:your-script.js |
| 63 | +- const config = require('./orval.config.js'); |
| 64 | ++ const config = await import('./orval.config.js'); |
| 65 | +``` |
| 66 | + |
| 67 | +### Benefits of ESM |
| 68 | + |
| 69 | +- **Better tree-shaking**: Unused code is more easily eliminated |
| 70 | +- **Native browser support**: ESM works directly in modern browsers |
| 71 | +- **Async module loading**: Improved performance with lazy loading |
| 72 | +- **Future-proof**: Aligns with JavaScript ecosystem standards |
| 73 | +- **Stricter module boundaries**: Better encapsulation and type safety |
| 74 | + |
| 75 | +## 2. Changed default value of httpClient from `axios` to `fetch` |
| 76 | + |
| 77 | +We changed the default httpClient from `axios` to `fetch` to reduce bundle size and eliminate the need for additional dependencies. |
| 78 | + |
| 79 | +### How to maintain compatibility |
| 80 | + |
| 81 | +If you want to keep using axios, configure it as follows: |
| 82 | + |
| 83 | +```diff:orval.config.ts |
| 84 | +export default { |
| 85 | + petstore: { |
| 86 | + output: { |
| 87 | ++ httpClient: 'axios', // Explicitly specify |
| 88 | + target: './src/api', |
| 89 | + }, |
| 90 | + input: { |
| 91 | + target: './petstore.yaml', |
| 92 | + }, |
| 93 | + }, |
| 94 | +}; |
| 95 | +``` |
| 96 | + |
| 97 | +## 3. Removed `override.fetch.explode` option |
| 98 | + |
| 99 | +This parameter was kept only for compatibility. Since compatibility maintenance is no longer needed in major versions, it has been removed. |
| 100 | + |
| 101 | +### How to maintain compatibility |
| 102 | + |
| 103 | +Specify `explode` directly in the OpenAPI specification file. |
| 104 | + |
| 105 | +```diff:petstore.yaml |
| 106 | +paths: |
| 107 | + /pets: |
| 108 | + get: |
| 109 | + parameters: |
| 110 | + - name: tags |
| 111 | + in: query |
| 112 | ++ explode: true |
| 113 | + schema: |
| 114 | + type: array |
| 115 | +``` |
| 116 | + |
| 117 | +## 4. Changed default value of `override.mock.delay` from `1000` to `false` |
| 118 | + |
| 119 | +We disabled the default delay as it creates noise. |
| 120 | + |
| 121 | +### How to maintain compatibility |
| 122 | + |
| 123 | +If you want to explicitly set a delay, specify it in milliseconds. |
| 124 | + |
| 125 | +```diff:orval.config.ts |
| 126 | +export default { |
| 127 | + petstore: { |
| 128 | + output: { |
| 129 | + mock: { |
| 130 | ++ delay: 1000, // In milliseconds |
| 131 | + }, |
| 132 | + }, |
| 133 | + }, |
| 134 | +}; |
| 135 | +``` |
| 136 | + |
| 137 | +## 5. Removed `override.coerceTypes` |
| 138 | + |
| 139 | +This was removed as it has been replaced by the more flexible and explicit `override.zod.coerce`. |
| 140 | + |
| 141 | +### How to maintain compatibility |
| 142 | + |
| 143 | +Use `override.zod.coerce`. |
| 144 | + |
| 145 | +```diff:orval.config.ts |
| 146 | +export default { |
| 147 | + petstore: { |
| 148 | + output: { |
| 149 | + override: { |
| 150 | +- coerceTypes: true |
| 151 | ++ zod: { |
| 152 | ++ coerce: { |
| 153 | ++ param: true, |
| 154 | ++ query: true, |
| 155 | ++ header: true, |
| 156 | ++ body: true, |
| 157 | ++ response: true |
| 158 | ++ } |
| 159 | ++ } |
| 160 | + }, |
| 161 | + }, |
| 162 | + }, |
| 163 | +}; |
| 164 | +``` |
| 165 | + |
| 166 | +## 6. Removed `override.useNativeEnums` |
| 167 | + |
| 168 | +This was removed as it has been integrated into `enumGenerationType`. |
| 169 | + |
| 170 | +### How to maintain compatibility |
| 171 | + |
| 172 | +Use `enumGenerationType`. |
| 173 | + |
| 174 | +```diff:orval.config.ts |
| 175 | +export default { |
| 176 | + petstore: { |
| 177 | + output: { |
| 178 | + override: { |
| 179 | +- useNativeEnums: true |
| 180 | ++ enumGenerationType: 'enum' |
| 181 | + }, |
| 182 | + }, |
| 183 | + }, |
| 184 | +}; |
| 185 | +``` |
| 186 | + |
| 187 | +## 7. Removed TanStack Query v3 support |
| 188 | + |
| 189 | +Support for TanStack Query v3 (react-query, vue-query, svelte-query) has been removed. TanStack Query v3 is no longer maintained, and v4/v5 provide significant API improvements. |
| 190 | + |
| 191 | +### How to migrate |
| 192 | + |
| 193 | +#### React Query |
| 194 | + |
| 195 | +Upgrade from `react-query` to `@tanstack/react-query`: |
| 196 | + |
| 197 | +```bash |
| 198 | +npm uninstall react-query |
| 199 | +npm install @tanstack/react-query@latest |
| 200 | +``` |
| 201 | + |
| 202 | +#### Vue Query |
| 203 | + |
| 204 | +Upgrade from `vue-query` to `@tanstack/vue-query`: |
| 205 | + |
| 206 | +```bash |
| 207 | +npm uninstall vue-query |
| 208 | +npm install @tanstack/vue-query@latest |
| 209 | +``` |
| 210 | + |
| 211 | +#### Svelte Query |
| 212 | + |
| 213 | +Upgrade from `@sveltestack/svelte-query` to `@tanstack/svelte-query`: |
| 214 | + |
| 215 | +```bash |
| 216 | +npm uninstall @sveltestack/svelte-query |
| 217 | +npm install @tanstack/svelte-query@latest |
| 218 | +``` |
| 219 | + |
| 220 | +### Official migration guides |
| 221 | + |
| 222 | +- [TanStack Query v4 Migration Guide](https://tanstack.com/query/v4/docs/react/guides/migrating-to-react-query-4) |
| 223 | +- [TanStack Query v5 Migration Guide](https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5) |
0 commit comments