|
| 1 | +# Basic usage |
| 2 | + |
| 3 | +``` |
| 4 | +$ openapi --help |
| 5 | +
|
| 6 | + Usage: openapi [options] |
| 7 | +
|
| 8 | + Options: |
| 9 | + -V, --version output the version number |
| 10 | + -i, --input <value> OpenAPI specification, can be a path, url or string content (required) |
| 11 | + -o, --output <value> Output directory (required) |
| 12 | + -c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch") |
| 13 | + --name <value> Custom client class name |
| 14 | + --useOptions Use options instead of arguments |
| 15 | + --useUnionTypes Use union types instead of enums |
| 16 | + --exportCore <value> Write core files to disk (default: true) |
| 17 | + --exportServices <value> Write services to disk (default: true) |
| 18 | + --exportModels <value> Write models to disk (default: true) |
| 19 | + --exportSchemas <value> Write schemas to disk (default: false) |
| 20 | + --indent <value> Indentation options [4, 2, tab] (default: "5") |
| 21 | + --postfix <value> Service name postfix (default: "Service") |
| 22 | + --request <value> Path to custom request file |
| 23 | + -h, --help display help for command |
| 24 | +
|
| 25 | + Examples |
| 26 | + $ openapi --input ./spec.json --output ./generated |
| 27 | +``` |
| 28 | + |
| 29 | + |
| 30 | +## Example |
| 31 | + |
| 32 | +**package.json** |
| 33 | +```json |
| 34 | +{ |
| 35 | + "scripts": { |
| 36 | + "generate": "openapi --input ./spec.json --output ./generated" |
| 37 | + } |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +**NPX** |
| 42 | + |
| 43 | +``` |
| 44 | +npx openapi-typescript-codegen --input ./spec.json --output ./generated |
| 45 | +``` |
| 46 | + |
| 47 | +**Node.js** |
| 48 | + |
| 49 | +```javascript |
| 50 | +const OpenAPI = require('openapi-typescript-codegen'); |
| 51 | + |
| 52 | +OpenAPI.generate({ |
| 53 | + input: './spec.json', |
| 54 | + output: './generated', |
| 55 | +}); |
| 56 | + |
| 57 | +// Or by providing the content of the spec directly 🚀 |
| 58 | +OpenAPI.generate({ |
| 59 | + input: require('./spec.json'), |
| 60 | + output: './generated', |
| 61 | +}); |
| 62 | +``` |
0 commit comments