Skip to content

CLI

Generate Angular services and TypeScript types from OpenAPI specifications using the command line interface.

Usage

bash
ng-openapi [command] [options]

Commands

Direct Generation

bash
ng-openapi -i swagger.json -o ./src/api

Configuration File

bash
ng-openapi -c openapi.config.ts

Generate Subcommand

bash
ng-openapi generate -i swagger.json -o ./src/api
ng-openapi gen -c openapi.config.ts  # Short alias

Options

Required Options

OptionAliasDescriptionExample
--config-cPath to configuration file-c openapi.config.ts
--input-iPath to OpenAPI specification-i swagger.json

Output Options

OptionAliasDescriptionDefaultExample
--output-oOutput directory./src/generated-o ./src/api

Generation Options

OptionDescriptionDefaultExample
--types-onlyGenerate only TypeScript interfacesfalse--types-only
--date-typeDate type to useDate--date-type string

Help and Version

OptionDescription
--helpShow help information
--versionShow version number

Examples

bash
# Generate from local file
ng-openapi -i ./swagger.json -o ./src/api

# Generate only types
ng-openapi -i swagger.json -o ./src/api --types-only

# Use string for dates
ng-openapi -i swagger.json -o ./src/api --date-type string

# Use configuration file
ng-openapi -c openapi.config.ts

# Generate with subcommand
ng-openapi generate -i swagger.json -o ./src/api

Released under the MIT License.
This site is powered by Netlify