diff --git a/README.md b/README.md index 971b949d0..f5e98714e 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,9 @@ yarn add @nicolas-chaulet/openapi-typescript-codegen -D ## Usage ``` -$ openapi --help +$ openapi-ts --help - Usage: openapi [options] + Usage: openapi-ts [options] Options: -V, --version output the version number @@ -64,10 +64,6 @@ $ openapi --help --request Path to custom request file --useDateType Output Date instead of string for the format "date-time" in the models (default: false) -h, --help display help for command - - Examples - $ openapi --input ./spec.json --output ./generated - $ openapi --input ./spec.json --output ./generated --client xhr ``` ## Formatting @@ -75,7 +71,7 @@ $ openapi --help By default, your client will be automatically formatted according to your configuration. To disable automatic formatting, run ```sh -openapi -i path/to/openapi.json -o src/client --no-autoformat +openapi-ts -i path/to/openapi.json -o src/client --no-autoformat ``` You can also prevent your client from being processed by formatters and linters by adding your output path to the tool's ignore file (e.g. `.eslintignore`, `.prettierignore`). @@ -85,7 +81,7 @@ You can also prevent your client from being processed by formatters and linters We do not generate TypeScript [enums](https://www.typescriptlang.org/docs/handbook/enums.html) because they are not standard JavaScript and pose [typing challenges](https://dev.to/ivanzm123/dont-use-enums-in-typescript-they-are-very-dangerous-57bh). If you want to iterate through possible field values without manually typing arrays, you can export enums by running ```sh -openapi -i path/to/openapi.json -o src/client --enums +openapi-ts -i path/to/openapi.json -o src/client --enums ``` This will export your enums as plain JavaScript objects. For example, `Foo` will generate the following diff --git a/bin/index.js b/bin/index.js index a49592530..216dac239 100755 --- a/bin/index.js +++ b/bin/index.js @@ -2,14 +2,14 @@ 'use strict'; -const path = require('path'); +const Path = require('path'); const { program } = require('commander'); -const pkg = require('../package.json'); +const json = require('../package.json'); const params = program - .name('openapi') + .name(Object.keys(json.bin)[0]) .usage('[options]') - .version(pkg.version) + .version(json.version) .requiredOption('-i, --input ', 'OpenAPI specification, can be a path, url or string content (required)') .requiredOption('-o, --output ', 'Output directory (required)') .option('-c, --client ', 'HTTP client to generate [fetch, xhr, node, axios, angular]', 'fetch') @@ -32,7 +32,7 @@ const params = program .parse(process.argv) .opts(); -const OpenAPI = require(path.resolve(__dirname, '../dist/index.js')); +const OpenAPI = require(Path.resolve(__dirname, '../dist/index.js')); const parseBooleanOrString = value => (value === true || value === 'true' ? true : value); diff --git a/bin/index.spec.js b/bin/index.spec.js index edf2063a1..935aca28c 100755 --- a/bin/index.spec.js +++ b/bin/index.spec.js @@ -94,7 +94,7 @@ describe('bin', () => { it('it should display help', async () => { const result = sync('node', ['./bin/index.js', '--help', '--no-write']); - expect(result.stdout.toString()).toContain(`Usage: openapi [options]`); + expect(result.stdout.toString()).toContain(`Usage: openapi-ts [options]`); expect(result.stdout.toString()).toContain(`-i, --input `); expect(result.stdout.toString()).toContain(`-o, --output `); expect(result.stderr.toString()).toBe(''); diff --git a/package-lock.json b/package-lock.json index 71f280798..208b62e55 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "node-fetch": "2.7.0" }, "bin": { - "openapi": "bin/index.js" + "openapi-ts": "bin/index.js" }, "devDependencies": { "@angular-devkit/build-angular": "17.0.9", diff --git a/package.json b/package.json index b111da19e..578918714 100644 --- a/package.json +++ b/package.json @@ -3,13 +3,13 @@ "version": "0.27.28", "description": "Library that generates Typescript clients based on the OpenAPI specification.", "author": "Ferdi Koomen", - "homepage": "https://github.com/CanoaPBC/openapi-typescript-codegen", + "homepage": "https://github.com/nicolas-chaulet/openapi-typescript-codegen/", "repository": { "type": "git", - "url": "git+https://github.com/CanoaPBC/openapi-typescript-codegen.git" + "url": "git+https://github.com/nicolas-chaulet/openapi-typescript-codegen.git" }, "bugs": { - "url": "https://github.com/ferdikoomen/openapi-typescript-codegen/issues" + "url": "https://github.com/nicolas-chaulet/openapi-typescript-codegen/issues" }, "license": "MIT", "keywords": [ @@ -34,7 +34,7 @@ "main": "dist/index.js", "types": "types/index.d.ts", "bin": { - "openapi": "bin/index.js" + "openapi-ts": "bin/index.js" }, "files": [ "bin/index.js", diff --git a/src/openApi/v3/interfaces/OpenApi.d.ts b/src/openApi/v3/interfaces/OpenApi.d.ts index b33d382a4..da75eeff3 100644 --- a/src/openApi/v3/interfaces/OpenApi.d.ts +++ b/src/openApi/v3/interfaces/OpenApi.d.ts @@ -10,12 +10,12 @@ import type { OpenApiTag } from './OpenApiTag'; * https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md */ export interface OpenApi { - openapi: string; + components?: OpenApiComponents; + externalDocs?: OpenApiExternalDocs; info: OpenApiInfo; - servers?: OpenApiServer[]; + openapi: string; paths: OpenApiPaths; - components?: OpenApiComponents; security?: OpenApiSecurityRequirement[]; + servers?: OpenApiServer[]; tags?: OpenApiTag[]; - externalDocs?: OpenApiExternalDocs; }