Skip to content

modelFileStructure โ€‹

Type: 'single' | 'per-type' | undefined | Default: 'single'

Controls how the generated model declarations are laid out under models/. The default ('single') keeps every interface, enum and type alias in one models/index.ts. With 'per-type', each schema gets its own file โ€” easier to navigate for humans, and much friendlier to AI tooling that struggles with one huge file.

Usage โ€‹

typescript
// openapi.config.ts
import { GeneratorConfig } from 'ng-openapi';

const config: GeneratorConfig = {
  options: {
    modelFileStructure: 'per-type'
  },
  ... // other configurations
};

export default config;

Example โ€‹

With 'per-type', a spec with Order, OrderStatus and User schemas produces:

models/
โ”œโ”€โ”€ index.ts             # Barrel: export * from "./order"; โ€ฆ
โ”œโ”€โ”€ order.ts             # export interface Order { โ€ฆ }
โ”œโ”€โ”€ order-status.ts      # export type OrderStatus = โ€ฆ
โ”œโ”€โ”€ user.ts              # export interface User { โ€ฆ }
โ””โ”€โ”€ request-options.ts   # The RequestOptions SDK interface

File names are the kebab-cased raw schema names. Models referencing other models import them directly from the sibling file:

typescript
// models/order.ts
import { OrderStatus } from "./order-status";

export interface Order {
    status: OrderStatus;
    ...
}

models/index.ts becomes a pure barrel, so consuming code is unaffected either way โ€” generated services keep importing from ../models, and everything is still re-exported from the client's main index.ts.

Notes โ€‹

  • File names derive from the undecorated schema name: naming.models prefixes/suffixes decorate identifiers only, consistent with service file naming
  • Two schemas whose names kebab-case to the same file name (e.g. UserProfile and user_profile) are disambiguated with a numeric suffix (user-profile-2.ts) and reported as a warning. The fixed file names index, request-options and request-params are reserved, so schemas named like them (e.g. Index) get a suffixed file too
  • Schemas whose (decorated) type names collide โ€” with each other, or with the built-in RequestOptions โ€” produce TypeScript code that does not compile, in either file structure. Rename the schema or use naming.models to move the generated identifiers out of the way
  • With useSingleRequestParameter, models/request-params.ts is generated and re-exported through the barrel exactly as in single-file mode

Released under the MIT License.
This site is powered by Netlify
About ยท Impressum