Skip to content

Commit a18bbf2

Browse files
authored
Merge pull request #1 from saddlebackdev/features/saddleback-version
[master] Features/saddleback version
2 parents a199552 + 64e7630 commit a18bbf2

Some content is hidden

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

57 files changed

+110558
-235
lines changed

README.md

Lines changed: 122 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,140 @@
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 saddleback-openapi-typescript-codegen --save-dev
299
```
3010

11+
## Step-by-step guide based on ME app
12+
### auto fetch
13+
1. install the package
14+
2. create config files for every microservice that you need (put it in the root project folder for example openapiEvents.config.json)
15+
3. inside the config file you need to specify
16+
1. output folder (for Events it would be ./src/shared/api/events)
17+
2. microservice that you're specifying ("Events")
18+
3. environment that using for fetch ("feature")
19+
4. if you don't want to generate whole microservices, you can specify filterMethod and filterArray
20+
4. create utility files that used in services
21+
1. 'baseAxios' should export axios instance that be used for fetch
22+
2. 'getBaseConfig' and 'serviceError' described here https://github.com/saddlebackdev/church-management/wiki/Services
23+
5. run the command where you should pass your login and pass from saddleback identity server `saddlebackApi --config openapiEvents.config.json --login login --password password`
24+
### local swagger
25+
1. same as above
26+
2. same as above
27+
3. addition specify the input path to the swagger.json file
28+
4. same as above
29+
5. run the command `saddlebackApi --config openapiEvents.config.json`
30+
3131
## Usage
3232

33+
Generated folders should be untouchable. Because every generate action will delete and put generated files into the output folder.
34+
3335
```
34-
$ openapi --help
36+
$ saddlebackOpenapi --help
3537
36-
Usage: openapi [options]
38+
Usage: saddlebackOpenapi [options]
3739
3840
Options:
3941
-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
42+
-i, --input <value> OpenAPI specification, can be a path, url or string content
43+
-o, --output <value> Output directory should end with service name workflows | events | notifications | core | journey | giving | smallGroup
44+
-c, --config <value> Path to the config file
45+
-l, --login <value> Login
46+
-p, --password <value> Password
47+
-e, --environment <value> Environment dev | stage | stage2
48+
-s, --service <value> Service Service Workflows | Events | Notifications | Core | Journey | Giving | SmallGroup
5349
-h, --help display help for command
50+
-m, --filterMethod Filter method include(default) | exclude')
51+
-f, --filterArray Filter array
5452
5553
Examples
56-
$ openapi --input ./spec.json --output ./generated
57-
$ openapi --input ./spec.json --output ./generated --client xhr
54+
$ saddlebackOpenApi --input ./spec.json --output ./generated
55+
$ saddlebackOpenApi --config ./openapi.config.json
56+
$ saddlebackOpenApi -o "./folderPath" -l "Login" -p "Password" -e "dev" -s "core"
57+
```
58+
59+
## Config file
60+
*extends original OPTIONS*
61+
```
62+
input required in the config or cmd arguments
63+
output required in the config or cmd arguments
64+
65+
additionalModelFileExtension optional
66+
additionalServiceFileExtension optional
67+
removeLodashPrefixes optional
5868
```
69+
### Settings:
70+
### `input`
71+
- Default: `undefined`
72+
- Type: `string`
73+
74+
OpenAPI specification, can be a path, url or string content (required in the config or cmd arguments)
75+
76+
### `output`
77+
- Default: `undefined`
78+
- Type: `string`
79+
80+
Output directory (required in the config or cmd arguments)
81+
82+
### `login` (autofetch)
83+
- Default: `undefined`
84+
- Type: `string`
85+
86+
Login to saddleback identity server
87+
88+
### `password` (autofetch)
89+
- Default: `undefined`
90+
- Type: `string`
91+
92+
Password to saddleback identity server
93+
94+
### `environment` (autofetch)
95+
- Default: `undefined`
96+
- Type: `'dev' | 'stage' | 'stage2'`
97+
98+
Which Environment should be used for swagger.json
99+
100+
### `service` (autofetch)
101+
- Default: `undefined`
102+
- Type: `'workflows' | 'event' | 'notifications' | 'core'`
103+
104+
Which service should be fetched
105+
106+
### `filterMethod` (autofetch)
107+
- Default: `include`
108+
- Type: `'include' | 'exclude'`
109+
110+
Which method of sort should be applied to the filter array
111+
112+
### `filterArray` (autofetch)
113+
- Default: `undefined`
114+
- Type: `string[]`
115+
116+
Which services should be *included* or *excluded* to/from generated list
117+
118+
### `additionalModelFileExtension`
119+
- Default: `true`
120+
- Type: `boolean`
121+
122+
Apply `*.models.*` extension to model files.
123+
124+
For example (myModel.ts -> myModel.models.ts)
125+
126+
### `additionalServiceFileExtension`
127+
- Default: `true`
128+
- Type: `boolean`
129+
130+
Apply `*.service.*` extension to service files.
131+
132+
For example (myService.ts -> myService.service.ts)
133+
134+
### `removeLodashPrefixes`
135+
- Default: `true`
136+
- Type: `boolean`
137+
138+
Remove special prefixes that are separated by `_` at the start of names.
59139

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
140+
For example (Custom_Prefix_Name -> Name)

bin/saddleback.cli.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
const path = require('path');
6+
const { program } = require('commander');
7+
const pkg = require('../package.json');
8+
9+
const params = program
10+
.name('saddlebackOpenApi')
11+
.usage('[options]')
12+
.version(pkg.version)
13+
.option('-i, --input <value>', 'OpenAPI specification, can be a path, url or string content (required)')
14+
.option('-o, --output <value>', 'Output directory (required)')
15+
.option('-c, --config <value>', 'Path to the config file')
16+
.option('-l, --login <value>', 'Login')
17+
.option('-p, --password <value>', 'Password')
18+
.option('-e, --environment <value>', 'Environment dev | stage | stage2')
19+
.option(
20+
'-s, --service <value>',
21+
'Service Workflows | Events | Notifications | Core | Journey | Giving | SmallGroup'
22+
)
23+
.option('-m, --filterMethod <value>', 'Filter method include(default) | exclude')
24+
.option('-f, --filterArray <value>', 'Filter array')
25+
.parse(process.argv)
26+
.opts();
27+
28+
const OpenAPI = require(path.resolve(__dirname, '../dist/index.js'));
29+
const config = require(path.resolve(params.config || `openapi.config.json`));
30+
31+
if (OpenAPI) {
32+
OpenAPI.generateSaddlebackSpec({
33+
httpClient: 'saddleback',
34+
clientName: '',
35+
useOptions: true,
36+
useUnionTypes: false,
37+
exportCore: false,
38+
exportServices: true,
39+
exportModels: true,
40+
exportSchemas: false,
41+
indent: '4',
42+
postfix: '',
43+
request: '',
44+
write: true,
45+
additionalModelFileExtension: true,
46+
additionalServiceFileExtension: true,
47+
removeLodashPrefixes: true,
48+
...config,
49+
input: params.input || config.input,
50+
output: params.output || config.output,
51+
username: params.login || config.login,
52+
password: params.password || config.password,
53+
useEnvironment: params.environment || config.environment,
54+
useService: params.service || config.service,
55+
filterMethod: params.filterMethod || config.filterMethod || 'include',
56+
filterArray: params.filterArray || config.filterArray || [],
57+
})
58+
.then(() => {
59+
process.exit(0);
60+
})
61+
.catch(error => {
62+
console.error(error);
63+
process.exit(1);
64+
});
65+
}

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

0 commit comments

Comments
 (0)