@@ -60,16 +60,16 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
60
60
public static final String NEWTONSOFT_VERSION = "newtonsoftVersion" ;
61
61
62
62
private String packageGuid = "{" + randomUUID ().toString ().toUpperCase (Locale .ROOT ) + "}" ;
63
+ private String userSecretsGuid = randomUUID ().toString ();
63
64
64
65
@ SuppressWarnings ("hiding" )
65
66
protected Logger LOGGER = LoggerFactory .getLogger (AspNetCoreServerCodegen .class );
66
67
67
68
private boolean useSwashbuckle = true ;
68
69
protected int serverPort = 8080 ;
69
70
protected String serverHost = "0.0.0.0" ;
70
- protected CliOption swashbuckleVersion = new CliOption (SWASHBUCKLE_VERSION , "Swashbucke version: 3.0.0, 4.0.0" );
71
- ; // default to 2.1
72
- protected CliOption aspnetCoreVersion = new CliOption (ASPNET_CORE_VERSION , "ASP.NET Core version: 3.0 (preview4 only), 2.2, 2.1, 2.0 (deprecated)" );
71
+ protected CliOption swashbuckleVersion = new CliOption (SWASHBUCKLE_VERSION , "Swashbuckle version: 3.0.0, 4.0.0, 5.0.0" );
72
+ protected CliOption aspnetCoreVersion = new CliOption (ASPNET_CORE_VERSION , "ASP.NET Core version: 3.1, 3.0, 2.2, 2.1, 2.0 (deprecated)" );
73
73
private CliOption classModifier = new CliOption (CLASS_MODIFIER , "Class Modifier can be empty, abstract" );
74
74
private CliOption operationModifier = new CliOption (OPERATION_MODIFIER , "Operation Modifier can be virtual, abstract or partial" );
75
75
private CliOption modelClassModifier = new CliOption (MODEL_CLASS_MODIFIER , "Model Class Modifier can be nothing or partial" );
@@ -83,7 +83,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
83
83
private boolean useFrameworkReference = false ;
84
84
private boolean useNewtonsoft = true ;
85
85
private boolean useDefaultRouting = true ;
86
- private String newtonsoftVersion = "3.0.0-preview5-19227-01 " ;
86
+ private String newtonsoftVersion = "3.0.0" ;
87
87
88
88
public AspNetCoreServerCodegen () {
89
89
super ();
@@ -186,10 +186,11 @@ public AspNetCoreServerCodegen() {
186
186
187
187
addOption (COMPATIBILITY_VERSION , "ASP.Net Core CompatibilityVersion" , compatibilityVersion );
188
188
189
- aspnetCoreVersion .addEnum ("2.0" , "ASP.NET COre 2.0" );
189
+ aspnetCoreVersion .addEnum ("2.0" , "ASP.NET Core 2.0" );
190
190
aspnetCoreVersion .addEnum ("2.1" , "ASP.NET Core 2.1" );
191
191
aspnetCoreVersion .addEnum ("2.2" , "ASP.NET Core 2.2" );
192
192
aspnetCoreVersion .addEnum ("3.0" , "ASP.NET Core 3.0" );
193
+ aspnetCoreVersion .addEnum ("3.1" , "ASP.NET Core 3.1" );
193
194
aspnetCoreVersion .setDefault ("2.2" );
194
195
aspnetCoreVersion .setOptValue (aspnetCoreVersion .getDefault ());
195
196
addOption (aspnetCoreVersion .getOpt (), aspnetCoreVersion .getDescription (), aspnetCoreVersion .getOptValue ());
@@ -227,7 +228,7 @@ public AspNetCoreServerCodegen() {
227
228
isLibrary );
228
229
229
230
addSwitch (USE_FRAMEWORK_REFERENCE ,
230
- "Use frameworkReference for ASP.NET Core 3.0+ and PackageReference ASP.NET Core 2.2 or earlier." ,
231
+ "Use frameworkReference for ASP.NET Core 3.0+ and PackageReference ASP.NET Core 2.2 or earlier." ,
231
232
useFrameworkReference );
232
233
233
234
addSwitch (USE_NEWTONSOFT ,
@@ -239,7 +240,7 @@ public AspNetCoreServerCodegen() {
239
240
newtonsoftVersion );
240
241
241
242
addSwitch (USE_DEFAULT_ROUTING ,
242
- "Use default routing for the ASP.NET Core version. For 3.0 turn off default because it is not yet supported ." ,
243
+ "Use default routing for the ASP.NET Core version." ,
243
244
useDefaultRouting );
244
245
245
246
addOption (CodegenConstants .ENUM_NAME_SUFFIX ,
@@ -263,7 +264,7 @@ public AspNetCoreServerCodegen() {
263
264
addOption (operationModifier .getOpt (), operationModifier .getDescription (), operationModifier .getOptValue ());
264
265
265
266
buildTarget .addEnum ("program" , "Generate code for a standalone server" );
266
- buildTarget .addEnum ("library" , "Generate code for a server abstract class lbrary " );
267
+ buildTarget .addEnum ("library" , "Generate code for a server abstract class library " );
267
268
buildTarget .setDefault ("program" );
268
269
buildTarget .setOptValue (buildTarget .getDefault ());
269
270
addOption (buildTarget .getOpt (), buildTarget .getDescription (), buildTarget .getOptValue ());
@@ -286,7 +287,6 @@ public AspNetCoreServerCodegen() {
286
287
modelClassModifier .setDefault ("partial" );
287
288
modelClassModifier .setOptValue (modelClassModifier .getDefault ());
288
289
addOption (modelClassModifier .getOpt (), modelClassModifier .getDescription (), modelClassModifier .getOptValue ());
289
-
290
290
}
291
291
292
292
@ Override
@@ -320,6 +320,7 @@ public void processOpts() {
320
320
setPackageGuid ((String ) additionalProperties .get (CodegenConstants .OPTIONAL_PROJECT_GUID ));
321
321
}
322
322
additionalProperties .put ("packageGuid" , packageGuid );
323
+ additionalProperties .put ("userSecretsGuid" , userSecretsGuid );
323
324
324
325
if (!additionalProperties .containsKey (NEWTONSOFT_VERSION )) {
325
326
additionalProperties .put (NEWTONSOFT_VERSION , newtonsoftVersion );
@@ -367,6 +368,9 @@ public void processOpts() {
367
368
supportingFiles .add (new SupportingFile ("gitignore" , packageFolder , ".gitignore" ));
368
369
supportingFiles .add (new SupportingFile ("validateModel.mustache" , packageFolder + File .separator + "Attributes" , "ValidateModelStateAttribute.cs" ));
369
370
supportingFiles .add (new SupportingFile ("typeConverter.mustache" , packageFolder + File .separator + "Converters" , "CustomEnumConverter.cs" ));
371
+ if (aspnetCoreVersion .getOptValue ().startsWith ("3." )) {
372
+ supportingFiles .add (new SupportingFile ("OpenApi" + File .separator + "TypeExtensions.mustache" , packageFolder + File .separator + "OpenApi" , "TypeExtensions.cs" ));
373
+ }
370
374
supportingFiles .add (new SupportingFile ("Project.csproj.mustache" , packageFolder , packageName + ".csproj" ));
371
375
if (!isLibrary ) {
372
376
supportingFiles .add (new SupportingFile ("Dockerfile.mustache" , packageFolder , "Dockerfile" ));
@@ -532,19 +536,34 @@ private void setBuildTarget() {
532
536
533
537
private void setAspnetCoreVersion (String packageFolder ) {
534
538
setCliOption (aspnetCoreVersion );
535
- if ("2.0" .equals (aspnetCoreVersion .getOptValue ())) {
536
- embeddedTemplateDir = templateDir = "aspnetcore/2.0" ;
539
+
540
+ if (aspnetCoreVersion .getOptValue ().startsWith ("3." )) {
541
+ compatibilityVersion = null ;
542
+ } else if ("2.0" .equals (aspnetCoreVersion .getOptValue ())) {
537
543
supportingFiles .add (new SupportingFile ("web.config" , packageFolder , "web.config" ));
538
- LOGGER .info ("ASP.NET core version: 2.0" );
539
544
compatibilityVersion = null ;
540
545
} else {
541
546
// default, do nothing
542
- LOGGER .info ("ASP.NET core version: " + aspnetCoreVersion .getOptValue ());
543
547
compatibilityVersion = "Version_" + aspnetCoreVersion .getOptValue ().replace ("." , "_" );
544
548
}
549
+ LOGGER .info ("ASP.NET core version: " + aspnetCoreVersion .getOptValue ());
550
+ embeddedTemplateDir = templateDir = "aspnetcore/" + determineTemplateVersion (aspnetCoreVersion .getOptValue ());
545
551
additionalProperties .put (COMPATIBILITY_VERSION , compatibilityVersion );
546
552
}
547
553
554
+ private String determineTemplateVersion (String frameworkVersion ) {
555
+ switch (frameworkVersion ) {
556
+ case "3.1" :
557
+ return "3.0" ;
558
+
559
+ case "2.2" :
560
+ return "2.1" ;
561
+
562
+ default :
563
+ return frameworkVersion ;
564
+ }
565
+ }
566
+
548
567
private void setUseSwashbuckle () {
549
568
if (isLibrary ) {
550
569
LOGGER .warn ("buildTarget is " + buildTarget .getOptValue () + " so changing default isLibrary to false " );
@@ -572,7 +591,7 @@ private void setOperationIsAsync() {
572
591
573
592
private void setIsFramework () {
574
593
if (aspnetCoreVersion .getOptValue ().startsWith ("3." )) {// default, do nothing
575
- LOGGER .warn ("ASP.NET core version is " + aspnetCoreVersion .getOptValue () + " so changing to use frameworkReference instead of packageReference " );
594
+ LOGGER .warn ("ASP.NET core version is " + aspnetCoreVersion .getOptValue () + " so changing to use frameworkReference instead of packageReference " );
576
595
useFrameworkReference = true ;
577
596
additionalProperties .put (USE_FRAMEWORK_REFERENCE , useFrameworkReference );
578
597
} else {
@@ -582,7 +601,6 @@ private void setIsFramework() {
582
601
additionalProperties .put (USE_FRAMEWORK_REFERENCE , useFrameworkReference );
583
602
}
584
603
}
585
-
586
604
}
587
605
588
606
private void setUseNewtonsoft () {
@@ -617,8 +635,8 @@ private void setSwashbuckleVersion() {
617
635
setCliOption (swashbuckleVersion );
618
636
619
637
if (aspnetCoreVersion .getOptValue ().startsWith ("3." )) {
620
- LOGGER .warn ("ASP.NET core version is " + aspnetCoreVersion .getOptValue () + " so changing default Swashbuckle version to 4 .0.0." );
621
- swashbuckleVersion .setOptValue ("4 .0.0" );
638
+ LOGGER .warn ("ASP.NET core version is " + aspnetCoreVersion .getOptValue () + " so changing default Swashbuckle version to 5 .0.0." );
639
+ swashbuckleVersion .setOptValue ("5 .0.0" );
622
640
additionalProperties .put (SWASHBUCKLE_VERSION , swashbuckleVersion .getOptValue ());
623
641
} else {
624
642
// default, do nothing
0 commit comments