Skip to content

Commit 14f59aa

Browse files
authored
Release 3.1.0 (#99)
* feat: --module-name-index CLI option (thanks @nikalun), add manual tests for it; docs: update CHANGELOG, README * bump: up version to 3.1.0 * chore: update CHANGELOG
1 parent 9596c3c commit 14f59aa

File tree

9 files changed

+1674
-21
lines changed

9 files changed

+1674
-21
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# next release
22

33

4+
# 3.1.0
5+
6+
Features:
7+
- `--moduleNameIndex` option. determines which path index should be used for routes separation (Thanks @nikalun)
8+
Examples:
9+
GET:api/v1/fruites/getFruit -> index:2 -> moduleName -> fruites
10+
GET:api/v1/fruites/getFruit -> index:0 -> moduleName -> api
11+
412
# 3.0.1
513

614
Fixes:

README.md

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,34 @@ Any questions you can ask [**here**](https://github.com/acacode/swagger-typescri
2323

2424
All examples you can find [**here**](https://github.com/acacode/swagger-typescript-api/tree/master/tests)
2525

26+
## 🛑 It is the latest version on mustache templates
27+
Next versions 4.0.0+ will use the [ETA](https://eta.js.org/docs/syntax) templates.
28+
If you want to create fork with `mustache` templates use `mustache-latest` branch
29+
2630
## 📄 Usage
2731

2832
```muse
2933
Usage: sta [options]
3034
Usage: swagger-typescript-api [options]
3135
3236
Options:
33-
-v, --version output the current version
34-
-p, --path <path> path/url to swagger scheme
35-
-o, --output <output> output path of typescript api file (default: "./")
36-
-n, --name <name> name of output typescript api file (default: "Api.ts")
37-
-t, --templates <path> path to folder containing templates (default: "./src/templates")
38-
-d, --default-as-success use "default" response status code as success response too.
39-
some swagger schemas use "default" response status code
40-
as success response type by default. (default: false)
41-
-r, --responses generate additional information about request responses
42-
also add typings for bad responses
43-
--union-enums generate all "enum" types as union types (T1 | T2 | TN) (default: false)
44-
--route-types generate type definitions for API routes (default: false)
45-
--no-client do not generate an API class
46-
--js generate js api module with declaration file (default: false)
47-
-h, --help output usage information
37+
-v, --version output the current version
38+
-p, --path <path> path/url to swagger scheme
39+
-o, --output <output> output path of typescript api file (default: "./")
40+
-n, --name <name> name of output typescript api file (default: "Api.ts")
41+
-t, --templates <path> path to folder containing templates
42+
-d, --default-as-success use "default" response status code as success response too.
43+
some swagger schemas use "default" response status code
44+
as success response type by default. (default: false)
45+
-r, --responses generate additional information about request responses
46+
also add typings for bad responses (default: false)
47+
--union-enums generate all "enum" types as union types (T1 | T2 | TN) (default: false)
48+
--route-types generate type definitions for API routes (default: false)
49+
--no-client do not generate an API class
50+
--js generate js api module with declaration file (default: false)
51+
--module-name-index <number> determines which path index should be used for routes separation (default: 0)
52+
(example: GET:/fruites/getFruit -> index:0 -> moduleName -> fruites)
53+
-h, --help display help for command
4854
```
4955

5056
Also you can use `npx`:
@@ -97,6 +103,25 @@ generateApi({
97103

98104
```
99105

106+
107+
## 💎 options
108+
### **`--templates`**
109+
This option should be used in cases when you don't want to use default `swagger-typescript-api` output structure
110+
How to use it:
111+
1. copy [**swagger-typescript-api templates**](https://github.com/acacode/swagger-typescript-api/tree/mustache-latest/src/templates/defaults) into your place in project
112+
1. add `--templates PATH_TO_YOUR_TEMPLATES` option
113+
2. modify [Mustache](https://mustache.github.io/) templates as you like
114+
115+
### **`--module-name-index`**
116+
This option should be used in cases when you have api with one global prefix like `/api`
117+
Example:
118+
`GET:/api/fruits/getFruits`
119+
`POST:/api/fruits/addFruits`
120+
`GET:/api/vegetables/addVegetable`
121+
with `--module-name-index 0` Api class will have one property `api`
122+
When we change it to `--module-name-index 1` then Api class have two properties `fruits` and `vegetables`
123+
124+
100125
## 📄 Mass media
101126

102127
- [Why Swagger schemes are needed in frontend development ?](https://dev.to/js2me/why-swagger-schemes-are-needed-in-frontend-development-2cb4)

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ interface GenerateApiParams {
5757
toJS?: boolean;
5858

5959
/**
60-
* url index from paths used for merging into modules
60+
* determines which path index should be used for routes separation
6161
*/
6262
moduleNameIndex?: number;
6363
}

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ program
3333
.option("--union-enums", 'generate all "enum" types as union types (T1 | T2 | TN)', false)
3434
.option("--route-types", "generate type definitions for API routes", false)
3535
.option("--no-client", "do not generate an API class", false)
36-
.option("--js", "generate js api module with declaration file", false);
36+
.option("--js", "generate js api module with declaration file", false)
37+
.option(
38+
"--module-name-index <number>",
39+
"determines which path index should be used for routes separation (example: GET:/fruites/getFruit -> index:0 -> moduleName -> fruites)",
40+
0,
41+
);
3742

3843
program.parse(process.argv);
3944

@@ -48,6 +53,7 @@ const {
4853
defaultAsSuccess,
4954
responses,
5055
js,
56+
moduleNameIndex,
5157
} = program;
5258

5359
generateApi({
@@ -65,4 +71,5 @@ generateApi({
6571
templates || "./src/templates/defaults",
6672
),
6773
toJS: !!js,
74+
moduleNameIndex: +(moduleNameIndex || 0),
6875
});

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "swagger-typescript-api",
3-
"version": "3.0.1",
3+
"version": "3.1.0",
44
"description": "Create typescript api module from swagger schema",
55
"scripts": {
66
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",
77
"cli:yaml": "node index.js -r -d -p ./swagger-test-cli.yaml -n swagger-test-cli.ts",
88
"cli:debug:json": "node --nolazy index.js -p ./swagger-test-cli.json -n swagger-test-cli.ts --union-enums",
99
"cli:debug:yaml": "node --nolazy index.js -p ./swagger-test-cli.yaml -n swagger-test-cli.ts",
1010
"cli:help": "node index.js -h",
11-
"test:all": "npm-run-all generate validate test:routeTypes test:noClient test:defaultAsSuccess test:responses test:templates test:unionEnums test:specProperty test:js --continue-on-error",
11+
"test:all": "npm-run-all generate validate test:routeTypes test:noClient test:defaultAsSuccess test:responses test:templates test:unionEnums test:specProperty test:js test:moduleNameIndex --continue-on-error",
1212
"generate": "node tests/generate.js",
1313
"generate:debug": "node --nolazy tests/generate.js",
1414
"validate": "node tests/validate.js",
@@ -20,6 +20,7 @@
2020
"test:unionEnums": "node tests/spec/unionEnums/test.js",
2121
"test:responses": "node tests/spec/responses/test.js",
2222
"test:specProperty": "node tests/spec/specProperty/test.js",
23+
"test:moduleNameIndex": "node tests/spec/moduleNameIndex/test.js",
2324
"test:js": "node tests/spec/js/test.js"
2425
},
2526
"author": "acacode",

0 commit comments

Comments
 (0)