Skip to content

Commit f1a363a

Browse files
committed
import security only if it's required
1 parent ac99022 commit f1a363a

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {
516516
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
517517
super.postProcessOperations(objs);
518518
if (objs != null) {
519+
boolean hasAuthMethods = false;
519520
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
520521
if (operations != null) {
521522
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
@@ -564,8 +565,13 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
564565
}
565566

566567
processOperation(operation);
568+
569+
if (operation.hasAuthMethods) {
570+
hasAuthMethods = true;
571+
}
567572
}
568573
}
574+
objs.put("hasAuthMethods", hasAuthMethods);
569575
}
570576

571577
return objs;

modules/swagger-codegen/src/main/resources/aspnetcore/3.0/Startup.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using Newtonsoft.Json.Serialization;
1414
using Swashbuckle.AspNetCore.Swagger;
1515
using Swashbuckle.AspNetCore.SwaggerGen;
1616
using {{packageName}}.Filters;
17-
using {{packageName}}.Security;
17+
{{#hasAuthMethods}}using {{packageName}}.Security;{{/hasAuthMethods}}
1818

1919
namespace {{packageName}}
2020
{

modules/swagger-codegen/src/main/resources/aspnetcore/3.0/controller.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using Swashbuckle.AspNetCore.SwaggerGen;
77
using Newtonsoft.Json;
88
using System.ComponentModel.DataAnnotations;
99
using {{packageName}}.Attributes;
10-
using {{packageName}}.Security;
10+
{{#hasAuthMethods}}using {{packageName}}.Security;{{/hasAuthMethods}}
1111
using Microsoft.AspNetCore.Authorization;
1212
using {{modelPackage}};
1313

0 commit comments

Comments
 (0)