23
23
public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
24
24
25
25
private String packageGuid = "{" + randomUUID ().toString ().toUpperCase () + "}" ;
26
- private final String DEFAULT_ASP_NET_CORE_VERSION = "2.2 " ;
26
+ private final String DEFAULT_ASP_NET_CORE_VERSION = "3.0 " ;
27
27
private String aspNetCoreVersion ;
28
28
29
29
@ SuppressWarnings ("hiding" )
@@ -64,7 +64,7 @@ public AspNetCoreServerCodegen() {
64
64
sourceFolder );
65
65
66
66
addOption (CodegenConstants .ASP_NET_CORE_VERSION ,
67
- "aspnetcore version to use, current options are: 2.0, 2.1 and 2.2 (default)" ,
67
+ "aspnetcore version to use, current options are: 2.0, 2.1, 2.2 and 3.0 (default)" ,
68
68
this .aspNetCoreVersion );
69
69
70
70
addOption (CodegenConstants .INTERFACE_ONLY ,
@@ -133,16 +133,35 @@ public void processOpts() {
133
133
apiTemplateFiles .put ("controller.mustache" , ".cs" );
134
134
addInterfaceControllerTemplate (interfaceOnly , interfaceController );
135
135
136
+ supportingFiles .add (new SupportingFile ("Filters" + File .separator + "BasePathFilter.mustache" , packageFolder + File .separator + "Filters" , "BasePathFilter.cs" ));
137
+ supportingFiles .add (new SupportingFile ("Filters" + File .separator + "GeneratePathParamsValidationFilter.mustache" , packageFolder + File .separator + "Filters" , "GeneratePathParamsValidationFilter.cs" ));
138
+
139
+ supportingFiles .add (new SupportingFile ("Startup.mustache" , packageFolder , "Startup.cs" ));
136
140
supportingFiles .add (new SupportingFile ("Program.mustache" , packageFolder , "Program.cs" ));
137
141
supportingFiles .add (new SupportingFile ("Project.csproj.mustache" , packageFolder , this .packageName + ".csproj" ));
138
142
supportingFiles .add (new SupportingFile ("Dockerfile.mustache" , packageFolder , "Dockerfile" ));
139
- } else {
143
+ } else if ( this . aspNetCoreVersion . equals ( "2.1" )) {
140
144
apiTemplateFiles .put ("2.1/controller.mustache" , ".cs" );
141
145
addInterfaceControllerTemplate (interfaceOnly , interfaceController );
142
146
147
+ supportingFiles .add (new SupportingFile ("Filters" + File .separator + "BasePathFilter.mustache" , packageFolder + File .separator + "Filters" , "BasePathFilter.cs" ));
148
+ supportingFiles .add (new SupportingFile ("Filters" + File .separator + "GeneratePathParamsValidationFilter.mustache" , packageFolder + File .separator + "Filters" , "GeneratePathParamsValidationFilter.cs" ));
149
+
150
+ supportingFiles .add (new SupportingFile ("Startup.mustache" , packageFolder , "Startup.cs" ));
143
151
supportingFiles .add (new SupportingFile ("2.1/Program.mustache" , packageFolder , "Program.cs" ));
144
152
supportingFiles .add (new SupportingFile ("2.1/Project.csproj.mustache" , packageFolder , this .packageName + ".csproj" ));
145
153
supportingFiles .add (new SupportingFile ("2.1/Dockerfile.mustache" , packageFolder , "Dockerfile" ));
154
+ } else {
155
+ apiTemplateFiles .put ("3.0/controller.mustache" , ".cs" );
156
+ addInterfaceControllerTemplate (interfaceOnly , interfaceController );
157
+
158
+ supportingFiles .add (new SupportingFile ("3.0" + File .separator + "Filters" + File .separator + "BasePathFilter.mustache" , packageFolder + File .separator + "Filters" , "BasePathFilter.cs" ));
159
+ supportingFiles .add (new SupportingFile ("3.0" + File .separator + "Filters" + File .separator + "GeneratePathParamsValidationFilter.mustache" , packageFolder + File .separator + "Filters" , "GeneratePathParamsValidationFilter.cs" ));
160
+
161
+ supportingFiles .add (new SupportingFile ("3.0/Startup.mustache" , packageFolder , "Startup.cs" ));
162
+ supportingFiles .add (new SupportingFile ("3.0/Program.mustache" , packageFolder , "Program.cs" ));
163
+ supportingFiles .add (new SupportingFile ("3.0/Project.csproj.mustache" , packageFolder , this .packageName + ".csproj" ));
164
+ supportingFiles .add (new SupportingFile ("3.0/Dockerfile.mustache" , packageFolder , "Dockerfile" ));
146
165
}
147
166
148
167
additionalProperties .put ("aspNetCoreVersion" , aspNetCoreVersion );
@@ -159,20 +178,14 @@ public void processOpts() {
159
178
supportingFiles .add (new SupportingFile ("build.bat.mustache" , "" , "build.bat" ));
160
179
supportingFiles .add (new SupportingFile ("README.mustache" , "" , "README.md" ));
161
180
supportingFiles .add (new SupportingFile ("Solution.mustache" , "" , this .packageName + ".sln" ));
162
- supportingFiles .add (new SupportingFile ("Dockerfile.mustache" , packageFolder , "Dockerfile" ));
163
181
supportingFiles .add (new SupportingFile ("gitignore" , packageFolder , ".gitignore" ));
164
182
supportingFiles .add (new SupportingFile ("appsettings.json" , packageFolder , "appsettings.json" ));
165
183
166
- supportingFiles .add (new SupportingFile ("Startup.mustache" , packageFolder , "Startup.cs" ));
167
184
supportingFiles .add (new SupportingFile ("validateModel.mustache" , packageFolder + File .separator + "Attributes" , "ValidateModelStateAttribute.cs" ));
168
185
supportingFiles .add (new SupportingFile ("web.config" , packageFolder , "web.config" ));
169
186
170
187
supportingFiles .add (new SupportingFile ("Properties" + File .separator + "launchSettings.json" , packageFolder + File .separator + "Properties" , "launchSettings.json" ));
171
188
172
- supportingFiles .add (new SupportingFile ("Filters" + File .separator + "BasePathFilter.mustache" , packageFolder + File .separator + "Filters" , "BasePathFilter.cs" ));
173
- supportingFiles .add (new SupportingFile ("Filters" + File .separator + "GeneratePathParamsValidationFilter.mustache" , packageFolder + File .separator + "Filters" , "GeneratePathParamsValidationFilter.cs" ));
174
-
175
- supportingFiles .add (new SupportingFile ("wwwroot" + File .separator + "README.md" , packageFolder + File .separator + "wwwroot" , "README.md" ));
176
189
supportingFiles .add (new SupportingFile ("wwwroot" + File .separator + "index.html" , packageFolder + File .separator + "wwwroot" , "index.html" ));
177
190
supportingFiles .add (new SupportingFile ("wwwroot" + File .separator + "web.config" , packageFolder + File .separator + "wwwroot" , "web.config" ));
178
191
@@ -301,7 +314,7 @@ private void setAspNetCoreVersion(String optionValue) {
301
314
return ;
302
315
}
303
316
this .aspNetCoreVersion = optionValue ;
304
- if (!this .aspNetCoreVersion .equals ("2.0" ) && !this .aspNetCoreVersion .equals ("2.1" ) && !this .aspNetCoreVersion .equals ("2.2" )) {
317
+ if (!this .aspNetCoreVersion .equals ("2.0" ) && !this .aspNetCoreVersion .equals ("2.1" ) && !this .aspNetCoreVersion .equals ("2.2" ) && ! this . aspNetCoreVersion . equals ( "3.0" ) ) {
305
318
LOGGER .error ("version '" + this .aspNetCoreVersion + "' is not supported, switching to default version: '" + DEFAULT_ASP_NET_CORE_VERSION + "'" );
306
319
this .aspNetCoreVersion = DEFAULT_ASP_NET_CORE_VERSION ;
307
320
}
0 commit comments