Skip to content

fix(bin): rename openapi command to openapi-ts #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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,18 +64,14 @@ $ openapi --help
--request <value> Path to custom request file
--useDateType <value> 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

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
10 changes: 5 additions & 5 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -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 <value>', 'OpenAPI specification, can be a path, url or string content (required)')
.requiredOption('-o, --output <value>', 'Output directory (required)')
.option('-c, --client <value>', '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);

2 changes: 1 addition & 1 deletion bin/index.spec.js
Original file line number Diff line number Diff line change
@@ -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 <value>`);
expect(result.stdout.toString()).toContain(`-o, --output <value>`);
expect(result.stderr.toString()).toBe('');
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
8 changes: 4 additions & 4 deletions src/openApi/v3/interfaces/OpenApi.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}