naming
Type: NamingOptions | undefined | Default: undefined (current names)
Decorates the identifiers of generated classes and types with a prefix and/or suffix, so generated API classes can't collide with your own (e.g. your hand-written RoleService vs the generated ApiRoleService). Services, httpResource classes, and models are configured independently:
typescript
interface NamingOptions {
services?: { prefix?: string; suffix?: string };
resources?: { prefix?: string; suffix?: string };
models?: { prefix?: string; suffix?: string };
}1
2
3
4
5
2
3
4
5
- A prefix is prepended verbatim and must start a valid identifier (letters, digits,
_). - For services and resources, a suffix replaces the default
Service/Resourcesuffix —suffix: 'ApiService'yieldsRoleApiService, and an empty string''drops the suffix entirely. - For models, the suffix is plainly appended (models have no default suffix).
- File names are unaffected —
role.service.tskeeps its name; only the exported identifiers change. Import through the generated barrels as usual.
Usage
typescript
// openapi.config.ts
import { GeneratorConfig } from 'ng-openapi';
const config: GeneratorConfig = {
options: {
naming: {
services: { prefix: 'Api' },
models: { suffix: 'Dto' }
}
},
... // other configurations
};
export default config;1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
Example
typescript
// default
export class RoleService { ... }
export interface User { ... }
roleService.getUser(): Observable<User>
// naming: { services: { prefix: 'Api' }, models: { suffix: 'Dto' } }
export class ApiRoleService { ... }
export interface UserDto { ... }
apiRoleService.getUser(): Observable<UserDto>1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
Notes
- Model decoration applies to schema-derived types only (interfaces, enums and aliases generated from spec schemas). Operation-derived names are untouched: request-params interfaces (
GetPetByIdParams), zod schemas, and SDK types likeRequestOptionskeep their names - Method parameter names derived from a body type follow the decorated name (e.g. a
Userbody parameter nameduserbecomesuserDtowithmodels: { suffix: 'Dto' }) - The
resourcesgroup only takes effect with the HTTP Resource plugin - Prefixes/suffixes are validated as identifier fragments; anything else fails config validation