Skip to content

Commit 7c1c691

Browse files
authored
Merge pull request #52 from nicolas-chaulet/fix/remove-indent
fix(cli): remove indent option
2 parents dac0c3d + 8ed9357 commit 7c1c691

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1401
-2766
lines changed

.eslintrc.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"parser": "@typescript-eslint/parser",
3-
"extends": ["plugin:@typescript-eslint/recommended", "plugin:prettier/recommended", "prettier"],
3+
"extends": [
4+
"plugin:@typescript-eslint/recommended",
5+
"plugin:prettier/recommended",
6+
"prettier"
7+
],
48
"env": {
59
"es6": true,
610
"node": true,

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ junit.xml
66
.DS_Store
77
.tmp
88
.idea
9+
10+
# IDE config
911
.vscode
12+
1013
*.iml
1114
dist
1215
coverage
13-
test/generated
14-
test/e2e/generated
1516
samples/generated
1617
samples/swagger-codegen-cli-v2.jar
1718
samples/swagger-codegen-cli-v3.jar
1819
.env
20+
21+
# test files
22+
test/generated
23+
test/e2e/generated

.prettierignore

Whitespace-only changes.

README.md

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
1-
# Why The Fork?
1+
# OpenAPI TypeScript Codegen
22

3-
Mainly, it's because the original project maintainer [doesn't have time](https://github.com/ferdikoomen/openapi-typescript-codegen/issues/1276#issuecomment-1302392146) to support the project. We wanted to keep the development going since this library became incompatible with [FastAPI v0.99.0 release](https://fastapi.tiangolo.com/release-notes/#0990) that introduced support for OpenAPI v3.1. While that was the main objective, this fork also offers other features such as:
3+
> ✨ Turn your OpenAPI specification into a beautiful TypeScript client
44
5-
- correct handling of 204 response status codes
6-
- ability to select which services to export and naming strategies for generated methods
7-
- support for non-ASCII characters
8-
- support for x-body-name header (compatible with Connexion v3.x)
9-
- ability to autoformat output with Prettier
5+
## About
106

11-
# OpenAPI Typescript Codegen
7+
This is an opinionated fork of the [openapi-typescript-codegen](https://github.com/ferdikoomen/openapi-typescript-codegen) package. We created it after the original project became [unmaintained](https://github.com/ferdikoomen/openapi-typescript-codegen/issues/1276#issuecomment-1302392146) because we wanted to support OpenAPI v3.1 introduced in the FastAPI [v0.99.0](https://fastapi.tiangolo.com/release-notes/#0990) release. We plan to resolve the most pressing issues in the original project – open an issue if you'd like to prioritise your use case!
128

13-
> Node.js library that generates Typescript clients based on the OpenAPI specification.
9+
## Features
1410

15-
## Why?
16-
- Frontend ❤️ OpenAPI, but we do not want to use Java codegen in our builds
17-
- Quick, lightweight, robust and framework-agnostic 🚀
18-
- Supports generation of TypeScript clients
19-
- Supports generations of Fetch, Node-Fetch, Axios, Angular and XHR http clients
20-
- Supports OpenAPI specification v2.0 and v3.0 (v3.1 is partially supported)
21-
- Supports JSON and YAML files for input
22-
- Supports generation through CLI, Node.js and npx
23-
- Supports tsc and @babel/plugin-transform-typescript
24-
- Supports aborting of requests (cancelable promise pattern)
25-
- Supports external references using [json-schema-ref-parser](https://github.com/APIDevTools/json-schema-ref-parser/)
11+
- generate TypeScript clients from OpenAPI v2.0, v3.0, and v3.1 specifications
12+
- support JSON or YAML input files
13+
- handle external references using [JSON Schema $Ref Parser](https://github.com/APIDevTools/json-schema-ref-parser/)
14+
- generate Fetch, Node-Fetch, Axios, Angular, or XHR HTTP clients
15+
- can be used with CLI, Node.js, or npx
16+
- abortable requests through cancellable promise pattern
2617

2718
## Install
2819

@@ -33,7 +24,7 @@ npm install @nicolas-chaulet/openapi-typescript-codegen --save-dev
3324
or
3425

3526
```
36-
yarn add -D @nicolas-chaulet/openapi-typescript-codegen
27+
yarn add @nicolas-chaulet/openapi-typescript-codegen -D
3728
```
3829

3930
## Usage
@@ -55,7 +46,7 @@ $ openapi --help
5546
--exportModels <value> Write models to disk [true, false, regexp] (default: true)
5647
--exportSchemas <value> Write schemas to disk (default: false)
5748
--base <value> Manually set base in OpenAPI config instead of inferring from server value
58-
--indent <value> Indentation options [4, 2, tab] (default: "4")
49+
--no-autoformat Disable processing generated files with formatter
5950
--postfixServices Service name postfix (default: "Service")
6051
--postfixModels Model name postfix
6152
--request <value> Path to custom request file
@@ -68,8 +59,24 @@ $ openapi --help
6859
$ openapi --input ./spec.json --output ./generated --client xhr
6960
```
7061

71-
Documentation
72-
===
62+
## Formatting
63+
64+
If you use Prettier, your client will be automatically formatted according to your configuration. To disable automatic formatting, run
65+
66+
```sh
67+
openapi --input path/to/openapi.json --output src/client --no-autoformat
68+
```
69+
70+
To prevent your client from being processed by linters and similar tools, you should add your output path to the tool's ignore file (e.g. `.eslintignore`).
71+
72+
## Contributing
73+
74+
This section is WIP.
75+
76+
- recommend using VS Code
77+
- configure Prettier
78+
79+
## Documentation
7380

7481
The original documentation can be found in the [openapi-typescript-codegen/wiki](https://github.com/ferdikoomen/openapi-typescript-codegen/wiki)
7582

bin/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ const params = program
1515
.option('-c, --client <value>', 'HTTP client to generate [fetch, xhr, node, axios, angular]', 'fetch')
1616
.option('--name <value>', 'Custom client class name')
1717
.option('--useOptions [value]', 'Use options instead of arguments', false)
18-
.option('--autoformat', 'Process generated files with autoformatter', false)
1918
.option('--base [value]', 'Manually set base in OpenAPI config instead of inferring from server value')
19+
.option('--no-autoformat', 'Disable processing generated files with formatter')
2020
.option('--exportCore <value>', 'Write core files to disk', true)
2121
.option('--exportServices <value>', 'Write services to disk', true)
2222
.option('--exportModels <value>', 'Write models to disk', true)
2323
.option('--exportSchemas <value>', 'Write schemas to disk', false)
24-
.option('--indent <value>', 'Indentation options [4, 2, tab]', '4')
2524
.option('--postfixServices <value>', 'Service name postfix', 'Service')
2625
.option('--serviceResponse [value]', 'Define shape of returned value from service calls')
2726
.option('--useDateType <value>', 'Output Date instead of string for the format "date-time" in the models', false)
@@ -44,7 +43,6 @@ const parseBooleanOrString = value => {
4443
if (OpenAPI) {
4544
OpenAPI.generate({
4645
...params,
47-
autoformat: JSON.parse(params.autoformat) === true,
4846
clientName: params.name,
4947
exportCore: JSON.parse(params.exportCore) === true,
5048
exportModels: parseBooleanOrString(params.exportModels),

bin/index.spec.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ describe('bin', () => {
3131
'true',
3232
'--exportSchemas',
3333
'true',
34-
'--indent',
35-
'4',
3634
'--postfixServices',
3735
'Service',
3836
'--postfixModels',
@@ -65,7 +63,6 @@ describe('bin', () => {
6563
'./test/spec/v3.json',
6664
'--output',
6765
'./test/generated/bin',
68-
'--autoformat',
6966
]);
7067
expect(result.stdout.toString()).toBe('');
7168
expect(result.stderr.toString()).toBe('');

src/Indent.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/client/interfaces/Options.d.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { HttpClient } from '../../HttpClient';
2-
import { Indent } from '../../Indent';
32

43
export type ServiceResponse = 'body' | 'generics' | 'response';
54

65
export interface Options {
76
/**
8-
* Process generated files with autoformatter
7+
* Process generated files with formatter?
98
*/
109
autoformat?: boolean;
1110
/**
@@ -36,10 +35,6 @@ export interface Options {
3635
* The selected httpClient (fetch, xhr, node or axios)
3736
*/
3837
httpClient?: HttpClient;
39-
/**
40-
* Indentation options (4, 2 or tab)
41-
*/
42-
indent?: Indent;
4338
/**
4439
* The relative location of the OpenAPI spec
4540
*/

src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import type { Options } from './client/interfaces/Options';
22
import { HttpClient } from './HttpClient';
3-
import { Indent } from './Indent';
43
import { getOpenApiSpec } from './utils/getOpenApiSpec';
54
import { getOpenApiSpecParser } from './utils/getOpenApiSpecParser';
65
import { postProcessClient } from './utils/postProcessClient';
76
import { registerHandlebarTemplates } from './utils/registerHandlebarTemplates';
87
import { writeClient } from './utils/writeClient';
98

109
export { HttpClient } from './HttpClient';
11-
export { Indent } from './Indent';
1210

1311
/**
1412
* Generate the OpenAPI client. This method will read the OpenAPI specification and based on the
@@ -18,12 +16,12 @@ export { Indent } from './Indent';
1816
*/
1917
export const generate = async (options: Options): Promise<void> => {
2018
const {
19+
autoformat = true,
2120
exportCore = true,
2221
exportModels = true,
2322
exportSchemas = false,
2423
exportServices = true,
2524
httpClient = HttpClient.FETCH,
26-
indent = Indent.SPACE_4,
2725
postfixModels = '',
2826
postfixServices = 'Service',
2927
serviceResponse = 'body',
@@ -44,12 +42,12 @@ export const generate = async (options: Options): Promise<void> => {
4442
if (write) {
4543
await writeClient(clientFinal, templates, {
4644
...options,
45+
autoformat,
4746
exportCore,
4847
exportModels,
4948
exportSchemas,
5049
exportServices,
5150
httpClient,
52-
indent,
5351
postfixModels,
5452
postfixServices,
5553
serviceResponse,

src/templates/client.hbs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
{{>header}}
2-
31
{{#equals @root.httpClient 'angular'}}
42
import { NgModule} from '@angular/core';
53
import { HttpClientModule } from '@angular/common/http';

0 commit comments

Comments
 (0)