Skip to content

Commit a81f776

Browse files
cleaned up package.mustache, added parameters for versions
1 parent f55b21f commit a81f776

2 files changed

Lines changed: 51 additions & 75 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNestjsServerCodegen.java

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public class TypeScriptNestjsServerCodegen extends AbstractTypeScriptClientCodeg
5454
public static final String STRING_ENUMS = "stringEnums";
5555
public static final String STRING_ENUMS_DESC = "Generate string enums instead of objects for enum values.";
5656
public static final String USE_SINGLE_REQUEST_PARAMETER = "useSingleRequestParameter";
57+
public static final String NODE_VERSION = "nodeVersion";
58+
public static final String TS_VERSION = "tsVersion";
59+
public static final String RXJS_VERSION = "rxjsVersion";
5760

5861
protected String nestVersion = "10.0.0";
5962
@Getter
@@ -69,6 +72,10 @@ public class TypeScriptNestjsServerCodegen extends AbstractTypeScriptClientCodeg
6972

7073
private boolean taggedUnions = false;
7174

75+
private String nodeVersion = "22.17.0";
76+
private String rxJsVersion = "7.8.1";
77+
private String tsVersion = "5.7.3";
78+
7279
public TypeScriptNestjsServerCodegen() {
7380
super();
7481

@@ -95,14 +102,16 @@ public TypeScriptNestjsServerCodegen() {
95102
this.cliOptions.add(CliOption.newBoolean(TAGGED_UNIONS,
96103
"Use discriminators to create tagged unions instead of extending interfaces.",
97104
this.taggedUnions));
98-
this.cliOptions.add(new CliOption(NEST_VERSION, "The version of Nestjs.").addEnum("10.0.0", "Use latest NestJS with decorators and dependency injection.").addEnum("9.0.0", "Use NestJS 9.x with decorators and dependency injection.").defaultValue(this.nestVersion));
105+
this.cliOptions.add(new CliOption(NEST_VERSION, "The version of Nestjs. (At least 10.0.0)").defaultValue(this.nestVersion));
99106
this.cliOptions.add(new CliOption(API_SUFFIX, "The suffix of the generated API class").defaultValue(this.apiSuffix));
100107
this.cliOptions.add(new CliOption(API_FILE_SUFFIX, "The suffix of the file of the generated API class (api<suffix>.ts).").defaultValue(this.apiFileSuffix));
101108
this.cliOptions.add(new CliOption(MODEL_SUFFIX, "The suffix of the generated model."));
102109
this.cliOptions.add(new CliOption(MODEL_FILE_SUFFIX, "The suffix of the file of the generated model (model<suffix>.ts)."));
103110
this.cliOptions.add(new CliOption(FILE_NAMING, "Naming convention for the output files: 'camelCase', 'kebab-case'.").defaultValue(this.fileNaming));
104111
this.cliOptions.add(new CliOption(STRING_ENUMS, STRING_ENUMS_DESC).defaultValue(String.valueOf(this.stringEnums)));
105112
this.cliOptions.add(new CliOption(USE_SINGLE_REQUEST_PARAMETER, "Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.").defaultValue(Boolean.FALSE.toString()));
113+
this.cliOptions.add(new CliOption(TS_VERSION, "The version of typescript compatible with Angular (see ngVersion option)."));
114+
this.cliOptions.add(new CliOption(RXJS_VERSION, "The version of RxJS compatible with Angular (see ngVersion option)."));
106115
}
107116

108117
@Override
@@ -123,7 +132,7 @@ public String getName() {
123132

124133
@Override
125134
public String getHelp() {
126-
return "Generates a TypeScript NestJS 10.x or 9.x server stub.";
135+
return "Generates a TypeScript NestJS server stub.";
127136
}
128137

129138
@Override
@@ -141,7 +150,6 @@ public void processOpts() {
141150
supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore"));
142151
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
143152
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
144-
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
145153
supportingFiles.add(new SupportingFile("tsconfig.mustache", "", "tsconfig.json"));
146154
supportingFiles.add(new SupportingFile("nest-cli.mustache", "", "nest-cli.json"));
147155

@@ -155,8 +163,32 @@ public void processOpts() {
155163
LOGGER.info(" (you can select the nestjs version by setting the additionalProperty nestVersion)");
156164
}
157165

166+
additionalProperties.put(NEST_VERSION, nestVersion);
167+
158168
if (additionalProperties.containsKey(NPM_NAME)) {
159-
addNpmPackageGeneration(nestVersion);
169+
if(!additionalProperties.containsKey(NPM_VERSION)) {
170+
additionalProperties.put(NPM_VERSION, "0.0.0");
171+
}
172+
173+
if (additionalProperties.containsKey(TS_VERSION)) {
174+
tsVersion = additionalProperties.get(TS_VERSION).toString();
175+
} else {
176+
additionalProperties.put(TS_VERSION, tsVersion);
177+
}
178+
179+
if (additionalProperties.containsKey(RXJS_VERSION)) {
180+
rxJsVersion = additionalProperties.get(RXJS_VERSION).toString();
181+
} else {
182+
additionalProperties.put(RXJS_VERSION, rxJsVersion);
183+
}
184+
185+
if (additionalProperties.containsKey(NODE_VERSION)) {
186+
nodeVersion = additionalProperties.get(NODE_VERSION).toString();
187+
} else {
188+
additionalProperties.put(NODE_VERSION, nodeVersion);
189+
}
190+
191+
addNpmPackageGeneration();
160192
}
161193

162194
if (additionalProperties.containsKey(STRING_ENUMS)) {
@@ -179,11 +211,6 @@ public void processOpts() {
179211
taggedUnions = Boolean.parseBoolean(additionalProperties.get(TAGGED_UNIONS).toString());
180212
}
181213

182-
additionalProperties.put(NEST_VERSION, nestVersion);
183-
additionalProperties.put("injectionToken", nestVersion.atLeast("4.0.0") ? "InjectionToken" : "OpaqueToken");
184-
additionalProperties.put("injectionTokenTyped", nestVersion.atLeast("4.0.0"));
185-
additionalProperties.put("useHttpClient", nestVersion.atLeast("4.3.0"));
186-
additionalProperties.put("useAxiosHttpModule", nestVersion.atLeast("8.0.0"));
187214

188215
if (additionalProperties.containsKey(API_SUFFIX)) {
189216
apiSuffix = additionalProperties.get(API_SUFFIX).toString();
@@ -206,7 +233,7 @@ public void processOpts() {
206233
}
207234
}
208235

209-
private void addNpmPackageGeneration(SemVer nestVersion) {
236+
private void addNpmPackageGeneration() {
210237
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
211238
}
212239

modules/openapi-generator/src/main/resources/typescript-nestjs-server/package.mustache

Lines changed: 14 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,71 +3,20 @@
33
"version": "{{npmVersion}}",
44
"description": "{{description}}",
55
"author": "{{author}}",
6-
"private": true,
76
"license": "{{licenseName}}",
8-
"scripts": {
9-
"build": "nest build",
10-
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
11-
"start": "nest start",
12-
"start:dev": "nest start --watch",
13-
"start:debug": "nest start --debug --watch",
14-
"start:prod": "node dist/main",
15-
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
16-
"test": "jest",
17-
"test:watch": "jest --watch",
18-
"test:cov": "jest --coverage",
19-
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
20-
"test:e2e": "jest --config ./test/jest-e2e.json"
21-
},
22-
"dependencies": {
23-
"@nestjs/common": "^11.0.1",
24-
"@nestjs/core": "^11.0.1",
25-
"@nestjs/platform-express": "^11.0.1",
7+
"peeerDependencies": {
8+
"@nestjs/common": "^{{nestVersion}}",
9+
"@nestjs/core": "^{{nestVersion}}",
10+
"@nestjs/platform-express": "^{{nestVersion}}",
2611
"reflect-metadata": "^0.2.2",
27-
"rxjs": "^7.8.1"
28-
},
29-
"devDependencies": {
30-
"@eslint/eslintrc": "^3.2.0",
31-
"@eslint/js": "^9.18.0",
32-
"@nestjs/cli": "^11.0.0",
33-
"@nestjs/schematics": "^11.0.0",
34-
"@nestjs/testing": "^11.0.1",
35-
"@swc/cli": "^0.6.0",
36-
"@swc/core": "^1.10.7",
37-
"@types/express": "^5.0.0",
38-
"@types/jest": "^29.5.14",
39-
"@types/node": "^22.10.7",
40-
"@types/supertest": "^6.0.2",
41-
"eslint": "^9.18.0",
42-
"eslint-config-prettier": "^10.0.1",
43-
"eslint-plugin-prettier": "^5.2.2",
44-
"globals": "^16.0.0",
45-
"jest": "^29.7.0",
46-
"prettier": "^3.4.2",
47-
"source-map-support": "^0.5.21",
48-
"supertest": "^7.0.0",
49-
"ts-jest": "^29.2.5",
50-
"ts-loader": "^9.5.2",
51-
"ts-node": "^10.9.2",
52-
"tsconfig-paths": "^4.2.0",
53-
"typescript": "^5.7.3",
54-
"typescript-eslint": "^8.20.0"
55-
},
56-
"jest": {
57-
"moduleFileExtensions": [
58-
"js",
59-
"json",
60-
"ts"
61-
],
62-
"rootDir": "src",
63-
"testRegex": ".*\\.spec\\.ts$",
64-
"transform": {
65-
"^.+\\.(t|j)s$": "ts-jest"
66-
},
67-
"collectCoverageFrom": [
68-
"**/*.(t|j)s"
69-
],
70-
"coverageDirectory": "../coverage",
71-
"testEnvironment": "node"
72-
}
12+
"rxjs": "^{{rxjsVersion}}"
13+
},
14+
"devDependencies": {
15+
"@types/node": "^{{nodeVersion}}",
16+
"typescript": "^{{{tsVersion}}}"
17+
}{{#npmRepository}},
18+
"publishConfig": {
19+
"registry": "{{{npmRepository}}}"
20+
}
21+
{{/npmRepository}}
7322
}

0 commit comments

Comments
 (0)