@@ -20,6 +20,7 @@ Main features are:
2020- Automatically convert ` format: 'date-time' ` to JS ` Date `
2121- Handle ** API Key** , ** HTTP Config** , ** OAuth2** <sup >1</sup > and ** OIDC** <sup >1</sup > auth security schemes
2222- JSDoc for schemas and operations
23+ - Override system for generated types
2324- Uses ` fetch ` api (can be customized)
2425- Non JSON content type support
2526- Small bundle size
@@ -49,6 +50,7 @@ The project is split into 4 packages:
4950 - [ Using with React Query] ( #using-with-react-query )
5051- [ Examples] ( #examples )
5152- [ Notes] ( #notes )
53+ - [ Overrides] ( #overrides )
5254 - [ External references] ( #external-references )
5355 - [ Parameters serialization] ( #parameters-serialization )
5456 - [ Migrating from v1 to v2] ( #migrating-from-v1-to-v2 )
@@ -85,6 +87,8 @@ Here is a short list of supported command line options:
8587 --wrap-lines-at Define a maximum width for JS Doc comments, 0 to disable (default: 120)
8688 --only-types Use it to only generate types in #components/schemas/
8789 --no-fetcher-options Use it to disable the additional param added to every operations
90+ --override You can define a list of types that will be imported from a custom file instead of being generated. Must be used with --override-import
91+ --override-import Path to the file that will be imported to resolve overrides
8892 --version Output the version number
8993 -h, --help Display help for command
9094```
@@ -280,6 +284,38 @@ You can find examples in the [`examples`](./examples) folder.
280284
281285Here is some notes on some known issues.
282286
287+ ### Overrides
288+
289+ Sometimes you may want to override some of the generated types.
290+ For example, Typoas will not generate Template Literal Types or Generics as it's hard to be defined in an OpenAPI spec.
291+
292+ This works by listing the types you want to override and giving the import path you want to use.
293+
294+ For example, if you want to override the PetStore ` Category ` type of your spec:
295+
296+ ``` typescript
297+ // my-overrides.ts
298+ export type Category = {
299+ id? : number ;
300+ name? : string ;
301+ description? : string ;
302+ };
303+ ```
304+
305+ When you generate the client, you can pass the ` --overrides ` option:
306+
307+ ``` bash
308+ yarn dlx @typoas/cli generate -i my-spec.json -o src/client.ts --override-import my-overrides.ts --override Category
309+ ```
310+
311+ This will not generate the ` Category ` type but import it from the ` my-overrides.ts ` file. This allows easy customization of generated types.
312+
313+ There are a couple of things to note:
314+
315+ - The override name is the ** sanitized** name of the type. You can first generate the client and see the generated types to know the name.
316+ - _ Typoas_ will not check the override file. If the file isn't there or the type isn't exported, it will throw a TypeScript error.
317+ - You will have to export the type yourself, _ Typoas_ will not do it for you (contrary to the generated types).
318+
283319### External references
284320
285321External references are not supported. Every ` $ref ` must be in the spec.
0 commit comments