2
2
3
3
import com .fasterxml .jackson .core .JsonProcessingException ;
4
4
import com .samskivert .mustache .Mustache ;
5
- import io .swagger .codegen .v3 .CodegenArgument ;
6
5
import io .swagger .codegen .v3 .CodegenConstants ;
7
6
import io .swagger .codegen .v3 .CodegenContent ;
8
7
import io .swagger .codegen .v3 .CodegenOperation ;
9
8
import io .swagger .codegen .v3 .CodegenSecurity ;
10
9
import io .swagger .codegen .v3 .CodegenType ;
11
10
import io .swagger .codegen .v3 .SupportingFile ;
12
- import io .swagger .codegen .v3 .generators .handlebars .ExtensionHelper ;
13
- import io .swagger .codegen .v3 .utils .URLPathUtil ;
14
11
import io .swagger .v3 .core .util .Json ;
15
12
import io .swagger .v3 .oas .models .OpenAPI ;
16
13
import io .swagger .v3 .oas .models .security .SecurityScheme ;
19
16
import org .slf4j .LoggerFactory ;
20
17
21
18
import java .io .File ;
22
- import java .net .URL ;
23
19
import java .util .Arrays ;
24
20
import java .util .List ;
25
21
import java .util .Map ;
26
- import java .util .Optional ;
27
22
import java .util .stream .Collectors ;
28
23
29
24
import static io .swagger .codegen .v3 .generators .handlebars .ExtensionHelper .getBooleanValue ;
@@ -35,7 +30,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
35
30
private static final String ASP_NET_CORE_VERSION_OPTION = "--aspnet-core-version" ;
36
31
private static final String INTERFACE_ONLY_OPTION = "--interface-only" ;
37
32
private static final String INTERFACE_CONTROLLER_OPTION = "--interface-controller" ;
38
- private final String DEFAULT_ASP_NET_CORE_VERSION = "2.2 " ;
33
+ private final String DEFAULT_ASP_NET_CORE_VERSION = "3.0 " ;
39
34
private String aspNetCoreVersion ;
40
35
41
36
@ SuppressWarnings ("hiding" )
@@ -151,13 +146,30 @@ public void processOpts() {
151
146
supportingFiles .add (new SupportingFile ("Program.mustache" , packageFolder , "Program.cs" ));
152
147
supportingFiles .add (new SupportingFile ("Project.csproj.mustache" , packageFolder , this .packageName + ".csproj" ));
153
148
supportingFiles .add (new SupportingFile ("Dockerfile.mustache" , packageFolder , "Dockerfile" ));
154
- } else {
149
+ supportingFiles .add (new SupportingFile ("Filters" + File .separator + "BasePathFilter.mustache" , packageFolder + File .separator + "Filters" , "BasePathFilter.cs" ));
150
+ supportingFiles .add (new SupportingFile ("Filters" + File .separator + "GeneratePathParamsValidationFilter.mustache" , packageFolder + File .separator + "Filters" , "GeneratePathParamsValidationFilter.cs" ));
151
+ supportingFiles .add (new SupportingFile ("Startup.mustache" , packageFolder , "Startup.cs" ));
152
+ } else if (aspNetCoreVersion .equals ("2.1" )) {
155
153
apiTemplateFiles .put ("2.1/controller.mustache" , ".cs" );
156
154
addInterfaceControllerTemplate ();
157
155
158
156
supportingFiles .add (new SupportingFile ("2.1/Program.mustache" , packageFolder , "Program.cs" ));
159
157
supportingFiles .add (new SupportingFile ("2.1/Project.csproj.mustache" , packageFolder , this .packageName + ".csproj" ));
160
158
supportingFiles .add (new SupportingFile ("2.1/Dockerfile.mustache" , packageFolder , "Dockerfile" ));
159
+ supportingFiles .add (new SupportingFile ("Filters" + File .separator + "BasePathFilter.mustache" , packageFolder + File .separator + "Filters" , "BasePathFilter.cs" ));
160
+ supportingFiles .add (new SupportingFile ("Filters" + File .separator + "GeneratePathParamsValidationFilter.mustache" , packageFolder + File .separator + "Filters" , "GeneratePathParamsValidationFilter.cs" ));
161
+ supportingFiles .add (new SupportingFile ("Startup.mustache" , packageFolder , "Startup.cs" ));
162
+ } else {
163
+ apiTemplateFiles .put ("3.0/controller.mustache" , ".cs" );
164
+ addInterfaceControllerTemplate ();
165
+
166
+ supportingFiles .add (new SupportingFile ("3.0" + File .separator + "Filters" + File .separator + "BasePathFilter.mustache" , packageFolder + File .separator + "Filters" , "BasePathFilter.cs" ));
167
+ supportingFiles .add (new SupportingFile ("3.0" + File .separator + "Filters" + File .separator + "GeneratePathParamsValidationFilter.mustache" , packageFolder + File .separator + "Filters" , "GeneratePathParamsValidationFilter.cs" ));
168
+
169
+ supportingFiles .add (new SupportingFile ("3.0/Startup.mustache" , packageFolder , "Startup.cs" ));
170
+ supportingFiles .add (new SupportingFile ("3.0/Program.mustache" , packageFolder , "Program.cs" ));
171
+ supportingFiles .add (new SupportingFile ("3.0/Project.csproj.mustache" , packageFolder , this .packageName + ".csproj" ));
172
+ supportingFiles .add (new SupportingFile ("3.0/Dockerfile.mustache" , packageFolder , "Dockerfile" ));
161
173
}
162
174
163
175
if (!additionalProperties .containsKey (CodegenConstants .API_PACKAGE )) {
@@ -178,15 +190,15 @@ public void processOpts() {
178
190
supportingFiles .add (new SupportingFile ("gitignore" , packageFolder , ".gitignore" ));
179
191
supportingFiles .add (new SupportingFile ("appsettings.json" , packageFolder , "appsettings.json" ));
180
192
181
- supportingFiles .add (new SupportingFile ("Startup.mustache" , packageFolder , "Startup.cs" ));
193
+ // supportingFiles.add(new SupportingFile("Startup.mustache", packageFolder, "Startup.cs"));
182
194
183
195
supportingFiles .add (new SupportingFile ("validateModel.mustache" , packageFolder + File .separator + "Attributes" , "ValidateModelStateAttribute.cs" ));
184
196
supportingFiles .add (new SupportingFile ("web.config" , packageFolder , "web.config" ));
185
197
186
198
supportingFiles .add (new SupportingFile ("Properties" + File .separator + "launchSettings.json" , packageFolder + File .separator + "Properties" , "launchSettings.json" ));
187
199
188
- supportingFiles .add (new SupportingFile ("Filters" + File .separator + "BasePathFilter.mustache" , packageFolder + File .separator + "Filters" , "BasePathFilter.cs" ));
189
- supportingFiles .add (new SupportingFile ("Filters" + File .separator + "GeneratePathParamsValidationFilter.mustache" , packageFolder + File .separator + "Filters" , "GeneratePathParamsValidationFilter.cs" ));
200
+ // supportingFiles.add(new SupportingFile("Filters" + File.separator + "BasePathFilter.mustache", packageFolder + File.separator + "Filters", "BasePathFilter.cs"));
201
+ // supportingFiles.add(new SupportingFile("Filters" + File.separator + "GeneratePathParamsValidationFilter.mustache", packageFolder + File.separator + "Filters", "GeneratePathParamsValidationFilter.cs"));
190
202
191
203
supportingFiles .add (new SupportingFile ("wwwroot" + File .separator + "README.md" , packageFolder + File .separator + "wwwroot" , "README.md" ));
192
204
supportingFiles .add (new SupportingFile ("wwwroot" + File .separator + "index.html" , packageFolder + File .separator + "wwwroot" , "index.html" ));
0 commit comments