Skip to content

Commit 93ec745

Browse files
js2mejnpoyser
andauthored
Release 6.2.0 (#190)
* Split routes based on first tag (#188) * bump: up version to 6.2.0 Co-authored-by: James Poyser <[email protected]>
1 parent 071c2a1 commit 93ec745

File tree

12 files changed

+1906
-4
lines changed

12 files changed

+1906
-4
lines changed

CHANGELOG.md

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

3+
# 6.2.0
4+
5+
Features:
6+
- `--module-name-first-tag` option. Splits routes based on the first tag (thanks @jnpoyser)
7+
38
# 6.1.2
49

510
Fixes:

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Options:
5252
Also combine path params and query params into one object
5353
--module-name-index <number> determines which path index should be used for routes separation (default: 0)
5454
(example: GET:/fruites/getFruit -> index:0 -> moduleName -> fruites)
55+
--module-name-first-tag splits routes based on the first tag
5556
--modular generate separated files for http client, data contracts, and routes (default: false)
5657
--disableStrictSSL disabled strict SSL (default: false)
5758
--clean-output clean output folder before generate api. WARNING: May cause data loss (default: false)
@@ -173,6 +174,9 @@ Example:
173174
with `--module-name-index 0` Api class will have one property `api`
174175
When we change it to `--module-name-index 1` then Api class have two properties `fruits` and `vegetables`
175176

177+
### **`--module-name-first-tag`**
178+
This option will group your API operations based on their first tag - mirroring how the Swagger UI groups displayed operations
179+
176180

177181
## 📄 Mass media
178182

index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ interface GenerateApiParams {
6363
* determines which path index should be used for routes separation
6464
*/
6565
moduleNameIndex?: number;
66+
/**
67+
* users operation's first tag for route separation
68+
*/
69+
moduleNameFirstTag?: boolean;
6670
/**
6771
* disabled SSL check
6872
*/
@@ -254,6 +258,7 @@ export interface GenerateApiConfiguration {
254258
componentsMap: Record<string, SchemaComponent>;
255259
convertedFromSwagger2: boolean;
256260
moduleNameIndex: number;
261+
moduleNameFirstTag: boolean;
257262
disableStrictSSL: boolean;
258263
extractRequestParams: boolean;
259264
fileNames: {

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ program
6161
"determines which path index should be used for routes separation (example: GET:/fruites/getFruit -> index:0 -> moduleName -> fruites)",
6262
0,
6363
)
64+
.option("--module-name-first-tag", "splits routes based on the first tag", false)
6465
.option("--disableStrictSSL", "disabled strict SSL", false)
6566
.option("--axios", "generate axios http client", false)
6667
.option("--single-http-client", "Ability to send HttpClient instance to Api constructor", false)
@@ -87,6 +88,7 @@ const {
8788
modular,
8889
js,
8990
moduleNameIndex,
91+
moduleNameFirstTag,
9092
extractRequestParams,
9193
enumNamesAsValues,
9294
disableStrictSSL,
@@ -115,6 +117,7 @@ generateApi({
115117
toJS: !!js,
116118
enumNamesAsValues: enumNamesAsValues,
117119
moduleNameIndex: +(moduleNameIndex || 0),
120+
moduleNameFirstTag: moduleNameFirstTag,
118121
disableStrictSSL: !!disableStrictSSL,
119122
singleHttpClient: !!singleHttpClient,
120123
cleanOutput: !!cleanOutput,

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-typescript-api",
3-
"version": "6.1.2",
3+
"version": "6.2.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 --extract-request-params --enum-names-as-values",
@@ -24,6 +24,7 @@
2424
"test:--responses": "node tests/spec/responses/test.js",
2525
"test:specProperty": "node tests/spec/specProperty/test.js",
2626
"test:--module-name-index": "node tests/spec/moduleNameIndex/test.js",
27+
"test:--module-name-first-tag": "node tests/spec/moduleNameFirstTag/test.js",
2728
"test:--modular": "node tests/spec/modular/test.js",
2829
"test:--single-http-client": "node tests/spec/singleHttpClient/test.js",
2930
"test:--extract-request-params": "node tests/spec/extractRequestParams/test.js",

src/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const config = {
2828

2929
/** url index from paths used for merging into modules */
3030
moduleNameIndex: 0,
31+
32+
/** use the first tag for the module name */
33+
moduleNameFirstTag: false,
3134
disableStrictSSL: false,
3235
extractRequestParams: false,
3336
fileNames: {

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module.exports = {
3636
httpClientType = config.httpClientType,
3737
generateUnionEnums = config.generateUnionEnums,
3838
moduleNameIndex = config.moduleNameIndex,
39+
moduleNameFirstTag = config.moduleNameFirstTag,
3940
extractRequestParams = config.extractRequestParams,
4041
defaultResponseType = config.defaultResponseType,
4142
singleHttpClient = config.singleHttpClient,
@@ -57,6 +58,7 @@ module.exports = {
5758
templates,
5859
generateUnionEnums,
5960
moduleNameIndex,
61+
moduleNameFirstTag,
6062
prettierOptions,
6163
modular,
6264
extractRequestParams,
@@ -102,6 +104,7 @@ module.exports = {
102104
usageSchema,
103105
parsedSchemas,
104106
moduleNameIndex,
107+
moduleNameFirstTag,
105108
extractRequestParams,
106109
});
107110

src/routes.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,13 @@ const getResponseBodyInfo = (routeInfo, routeParams, parsedSchemas) => {
451451
};
452452
};
453453

454-
const parseRoutes = ({ usageSchema, parsedSchemas, moduleNameIndex, extractRequestParams }) => {
454+
const parseRoutes = ({
455+
usageSchema,
456+
parsedSchemas,
457+
moduleNameIndex,
458+
moduleNameFirstTag,
459+
extractRequestParams,
460+
}) => {
455461
const { paths, security: globalSecurity } = usageSchema;
456462
const pathsEntries = _.entries(paths);
457463

@@ -480,7 +486,11 @@ const parseRoutes = ({ usageSchema, parsedSchemas, moduleNameIndex, extractReque
480486
const { route, pathParams } = parseRoute(rawRoute);
481487

482488
const routeId = nanoid(12);
483-
const moduleName = _.camelCase(_.compact(_.split(route, "/"))[moduleNameIndex]);
489+
const firstTag = tags && tags.length > 0 ? tags[0] : null;
490+
const moduleName =
491+
moduleNameFirstTag && firstTag
492+
? _.camelCase(firstTag)
493+
: _.camelCase(_.compact(_.split(route, "/"))[moduleNameIndex]);
484494
const hasSecurity = !!(
485495
(globalSecurity && globalSecurity.length) ||
486496
(security && security.length)

0 commit comments

Comments
 (0)