Skip to content

Commit b7eb86d

Browse files
committed
feat: add new README
1 parent 8fc10ec commit b7eb86d

File tree

6 files changed

+169
-95
lines changed

6 files changed

+169
-95
lines changed

README.md

Lines changed: 57 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,75 @@
1-
# OpenAPI Typescript Codegen
2-
3-
[![NPM][npm-image]][npm-url]
4-
[![License][license-image]][license-url]
5-
[![Coverage][coverage-image]][coverage-url]
6-
[![Quality][quality-image]][quality-url]
7-
[![Code Climate][climate-image]][climate-url]
8-
[![Downloads][downloads-image]][downloads-url]
9-
[![Build][build-image]][build-url]
10-
11-
> Node.js library that generates Typescript clients based on the OpenAPI specification.
12-
13-
## Why?
14-
- Frontend ❤️ OpenAPI, but we do not want to use JAVA codegen in our builds
15-
- Quick, lightweight, robust and framework-agnostic 🚀
16-
- Supports generation of TypeScript clients
17-
- Supports generations of Fetch, [Node-Fetch](#node-fetch-support), [Axios](#axios-support), [Angular](#angular-support) and XHR http clients
18-
- Supports OpenAPI specification v2.0 and v3.0
19-
- Supports JSON and YAML files for input
20-
- Supports generation through CLI, Node.js and NPX
21-
- Supports tsc and @babel/plugin-transform-typescript
22-
- Supports aborting of requests (cancelable promise pattern)
23-
- Supports external references using [json-schema-ref-parser](https://github.com/APIDevTools/json-schema-ref-parser/)
1+
# Custom Saddleback OpenAPI Typescript Codegen
2+
3+
> For original usage read - [original README](docs/original-readme.md)
244
255
## Install
266

277
```
28-
npm install openapi-typescript-codegen --save-dev
8+
npm install [gitUrl] --save-dev
299
```
3010

3111
## Usage
3212

3313
```
34-
$ openapi --help
14+
$ saddlebackOpenapi --help
3515
36-
Usage: openapi [options]
16+
Usage: saddlebackOpenapi [options]
3717
3818
Options:
3919
-V, --version output the version number
40-
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
41-
-o, --output <value> Output directory (required)
42-
-c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch")
43-
--name <value> Custom client class name
44-
--useOptions Use options instead of arguments
45-
--useUnionTypes Use union types instead of enums
46-
--exportCore <value> Write core files to disk (default: true)
47-
--exportServices <value> Write services to disk (default: true)
48-
--exportModels <value> Write models to disk (default: true)
49-
--exportSchemas <value> Write schemas to disk (default: false)
50-
--indent <value> Indentation options [4, 2, tab] (default: "4")
51-
--postfix <value> Service name postfix (default: "Service")
52-
--request <value> Path to custom request file
20+
-i, --input <value> OpenAPI specification, can be a path, url or string content
21+
-o, --output <value> Output directory
22+
-c, --config <value> Path to the config file
5323
-h, --help display help for command
5424
5525
Examples
56-
$ openapi --input ./spec.json --output ./generated
57-
$ openapi --input ./spec.json --output ./generated --client xhr
26+
$ saddlebackOpenapi --input ./spec.json --output ./generated
27+
$ saddlebackOpenapi --config ./openapi.config.json
28+
```
29+
30+
## Config file
31+
*extends original OPTIONS*
32+
```
33+
input required in the config or cmd arguments
34+
output required in the config or cmd arguments
35+
36+
additionalModelFileExtension optional
37+
additionalServiceFileExtension optional
38+
removeLodashPrefixes optional
5839
```
40+
### Settings:
41+
### `input`
42+
- Default: `undefined`
43+
- Type: `string`
44+
45+
OpenAPI specification, can be a path, url or string content (required in the config or cmd arguments)
46+
47+
### `output`
48+
- Default: `undefined`
49+
- Type: `string`
50+
51+
Output directory (required in the config or cmd arguments)
52+
53+
### `additionalModelFileExtension`
54+
- Default: `true`
55+
- Type: `boolean`
56+
57+
Apply `*.models.*` extension to model files.
58+
59+
For example (myModel.ts -> myModel.models.ts)
60+
61+
### `additionalServiceFileExtension`
62+
- Default: `true`
63+
- Type: `boolean`
64+
65+
Apply `*.service.*` extension to service files.
66+
67+
For example (myService.ts -> myService.service.ts)
68+
69+
### `removeLodashPrefixes`
70+
- Default: `true`
71+
- Type: `boolean`
72+
73+
Remove special prefixes that are separated by `_` at the start of names.
5974

60-
Documentation
61-
===
62-
- [Basic usage](docs/basic-usage.md)
63-
- [OpenAPI object](docs/openapi-object.md)
64-
- [Client instances](docs/client-instances.md) `--name`
65-
- [Argument vs. Object style](docs/arguments-vs-object-style.md) `--useOptions`
66-
- [Enums vs. Union types](docs/enum-vs-union-types.md) `--useUnionTypes`
67-
- [Runtime schemas](docs/runtime-schemas.md) `--exportSchemas`
68-
- [Enum with custom names and descriptions](docs/custom-enums.md)
69-
- [Nullable props (OpenAPI v2)](docs/nullable-props.md)
70-
- [Authorization](docs/authorization.md)
71-
- [External references](docs/external-references.md)
72-
- [Canceling requests](docs/canceling-requests.md)
73-
- [Custom request file](docs/custom-request-file.md)
74-
75-
Support
76-
===
77-
- [Babel support](docs/babel-support.md)
78-
- [Axios support](docs/axios-support.md)
79-
- [Angular support](docs/angular-support.md)
80-
- [Node-Fetch support](docs/node-fetch-support.md)
81-
82-
[npm-url]: https://npmjs.org/package/openapi-typescript-codegen
83-
[npm-image]: https://img.shields.io/npm/v/openapi-typescript-codegen.svg
84-
[license-url]: LICENSE
85-
[license-image]: http://img.shields.io/npm/l/openapi-typescript-codegen.svg
86-
[coverage-url]: https://codecov.io/gh/ferdikoomen/openapi-typescript-codegen
87-
[coverage-image]: https://img.shields.io/codecov/c/github/ferdikoomen/openapi-typescript-codegen.svg
88-
[quality-url]: https://lgtm.com/projects/g/ferdikoomen/openapi-typescript-codegen
89-
[quality-image]: https://img.shields.io/lgtm/grade/javascript/g/ferdikoomen/openapi-typescript-codegen.svg
90-
[climate-url]: https://codeclimate.com/github/ferdikoomen/openapi-typescript-codegen
91-
[climate-image]: https://img.shields.io/codeclimate/maintainability/ferdikoomen/openapi-typescript-codegen.svg
92-
[downloads-url]: http://npm-stat.com/charts.html?package=openapi-typescript-codegen
93-
[downloads-image]: http://img.shields.io/npm/dm/openapi-typescript-codegen.svg
94-
[build-url]: https://circleci.com/gh/ferdikoomen/openapi-typescript-codegen/tree/master
95-
[build-image]: https://circleci.com/gh/ferdikoomen/openapi-typescript-codegen/tree/master.svg?style=svg
75+
For example (Custom_Prefix_Name -> Name)

bin/saddleback.cli.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,24 @@ const params = program
1818

1919
const OpenAPI = require(path.resolve(__dirname, '../dist/index.js'));
2020
const config = require(path.resolve(params.config || `./openapi.config.json`));
21-
const generateSaddlebackSpec = require('../src/generateSaddlebackSpec');
2221

2322
if (OpenAPI) {
2423
OpenAPI.generateSaddlebackSpec({
24+
httpClient: 'saddleback',
25+
clientName: '',
26+
useOptions: true,
27+
useUnionTypes: false,
28+
exportCore: false,
29+
exportServices: true,
30+
exportModels: true,
31+
exportSchemas: false,
32+
indent: '4',
33+
postfix: '',
34+
request: '',
35+
write: true,
36+
additionalModelFileExtension: true,
37+
additionalServiceFileExtension: true,
38+
removeLodashPrefixes: true,
2539
...config,
2640
input: params.input,
2741
output: params.output,

docs/basic-usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Basic usage
1+
# Basic usage
22

33
```
44
$ openapi --help

docs/original-readme.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# OpenAPI Typescript Codegen
2+
3+
[![NPM][npm-image]][npm-url]
4+
[![License][license-image]][license-url]
5+
[![Coverage][coverage-image]][coverage-url]
6+
[![Quality][quality-image]][quality-url]
7+
[![Code Climate][climate-image]][climate-url]
8+
[![Downloads][downloads-image]][downloads-url]
9+
[![Build][build-image]][build-url]
10+
11+
> Node.js library that generates Typescript clients based on the OpenAPI specification.
12+
13+
## Why?
14+
- Frontend ❤️ OpenAPI, but we do not want to use JAVA codegen in our builds
15+
- Quick, lightweight, robust and framework-agnostic 🚀
16+
- Supports generation of TypeScript clients
17+
- Supports generations of Fetch, [Node-Fetch](#node-fetch-support), [Axios](#axios-support), [Angular](#angular-support) and XHR http clients
18+
- Supports OpenAPI specification v2.0 and v3.0
19+
- Supports JSON and YAML files for input
20+
- Supports generation through CLI, Node.js and NPX
21+
- Supports tsc and @babel/plugin-transform-typescript
22+
- Supports aborting of requests (cancelable promise pattern)
23+
- Supports external references using [json-schema-ref-parser](https://github.com/APIDevTools/json-schema-ref-parser/)
24+
25+
## Install
26+
27+
```
28+
npm install openapi-typescript-codegen --save-dev
29+
```
30+
31+
## Usage
32+
33+
```
34+
$ openapi --help
35+
36+
Usage: openapi [options]
37+
38+
Options:
39+
-V, --version output the version number
40+
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
41+
-o, --output <value> Output directory (required)
42+
-c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch")
43+
--name <value> Custom client class name
44+
--useOptions Use options instead of arguments
45+
--useUnionTypes Use union types instead of enums
46+
--exportCore <value> Write core files to disk (default: true)
47+
--exportServices <value> Write services to disk (default: true)
48+
--exportModels <value> Write models to disk (default: true)
49+
--exportSchemas <value> Write schemas to disk (default: false)
50+
--indent <value> Indentation options [4, 2, tab] (default: "4")
51+
--postfix <value> Service name postfix (default: "Service")
52+
--request <value> Path to custom request file
53+
-h, --help display help for command
54+
55+
Examples
56+
$ openapi --input ./spec.json --output ./generated
57+
$ openapi --input ./spec.json --output ./generated --client xhr
58+
```
59+
60+
Documentation
61+
===
62+
- [Basic usage](basic-usage.md)
63+
- [OpenAPI object](openapi-object.md)
64+
- [Client instances](client-instances.md) `--name`
65+
- [Argument vs. Object style](arguments-vs-object-style.md) `--useOptions`
66+
- [Enums vs. Union types](enum-vs-union-types.md) `--useUnionTypes`
67+
- [Runtime schemas](runtime-schemas.md) `--exportSchemas`
68+
- [Enum with custom names and descriptions](custom-enums.md)
69+
- [Nullable props (OpenAPI v2)](nullable-props.md)
70+
- [Authorization](authorization.md)
71+
- [External references](external-references.md)
72+
- [Canceling requests](canceling-requests.md)
73+
- [Custom request file](custom-request-file.md)
74+
75+
Support
76+
===
77+
- [Babel support](babel-support.md)
78+
- [Axios support](axios-support.md)
79+
- [Angular support](angular-support.md)
80+
- [Node-Fetch support](node-fetch-support.md)
81+
82+
[npm-url]: https://npmjs.org/package/openapi-typescript-codegen
83+
[npm-image]: https://img.shields.io/npm/v/openapi-typescript-codegen.svg
84+
[license-url]: ../LICENSE
85+
[license-image]: http://img.shields.io/npm/l/openapi-typescript-codegen.svg
86+
[coverage-url]: https://codecov.io/gh/ferdikoomen/openapi-typescript-codegen
87+
[coverage-image]: https://img.shields.io/codecov/c/github/ferdikoomen/openapi-typescript-codegen.svg
88+
[quality-url]: https://lgtm.com/projects/g/ferdikoomen/openapi-typescript-codegen
89+
[quality-image]: https://img.shields.io/lgtm/grade/javascript/g/ferdikoomen/openapi-typescript-codegen.svg
90+
[climate-url]: https://codeclimate.com/github/ferdikoomen/openapi-typescript-codegen
91+
[climate-image]: https://img.shields.io/codeclimate/maintainability/ferdikoomen/openapi-typescript-codegen.svg
92+
[downloads-url]: http://npm-stat.com/charts.html?package=openapi-typescript-codegen
93+
[downloads-image]: http://img.shields.io/npm/dm/openapi-typescript-codegen.svg
94+
[build-url]: https://circleci.com/gh/ferdikoomen/openapi-typescript-codegen/tree/master
95+
[build-image]: https://circleci.com/gh/ferdikoomen/openapi-typescript-codegen/tree/master.svg?style=svg

src/generateSaddlebackSpec.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { OpenApiSchema } from './openApi/v3/interfaces/OpenApiSchema';
77
import { removeLodashPrefix } from './utils/removeLodashPrefix';
88
import { mapSwaggerRef } from './utils/mapSwaggerRef';
99
import { removeLodashPrefixFromRef } from './utils/removeLodashPrefixFromRef';
10-
import RefParser from 'json-schema-ref-parser';
1110

1211
type Config = Options & {
1312
useSaddlebackServices?: boolean;
@@ -17,20 +16,7 @@ type Config = Options & {
1716
};
1817

1918
export const generateSaddlebackSpec = async (config: Config) => {
20-
const url = 'https://hc-eventservice-dev.azurewebsites.net/api-doc/all/swagger.json';
21-
const test = await RefParser.bundle(url, url, {
22-
resolve: {
23-
http: {
24-
withCredentials: true,
25-
headers: {
26-
'Cookie': 'ARRAffinity=7d18d5957d129d3dc3a25d7a2c85147ef57f1a6b93910c50eb850417ab59dc56; ARRAffin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I5_jRFf9rYXbT0lhH4KwSIZzMFOS19Wd8txa7XE_rIDkhzetcH1z2sf9QL5Vd9RkdJUgFKPJEneyRmeZyBxHKn5cgrtF3cANZJlvIBZ2Mxu1OFxcQx6mGy-nHUTEPz1dHFPi2FZ8xkBgUxLeaQMflLgIv6nICpe_uESRvP91MxIQ--vEsrjN7Cy9A',
28-
}
29-
}
30-
}
31-
});
32-
33-
const openApi: OpenApi = isString(config.input) ? await getOpenApiSpec(config.input) : config.input;
19+
const openApi: OpenApi = isString(config.input) ? await getOpenApiSpec(config.input) : config.input;
3420

3521
if (config.removeLodashPrefixes && openApi.components && openApi.components.schemas) {
3622
const newSchemas: Dictionary<OpenApiSchema> = {};

types/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export type Options = {
3131
};
3232

3333
export type CustomConfig = Options & {
34-
useSaddlebackServices?: boolean;
3534
additionalModelFileExtension?: boolean;
3635
additionalServiceFileExtension?: boolean;
3736
removeLodashPrefixes?: boolean;

0 commit comments

Comments
 (0)