Skip to content

Commit f007d73

Browse files
committed
import security only when it's required
1 parent 1c043a8 commit f007d73

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/main/java/io/swagger/codegen/v3/generators/dotnet/AbstractCSharpCodegen.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {
535535
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
536536
super.postProcessOperations(objs);
537537
if (objs != null) {
538+
boolean hasAuthMethods = false;
538539
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
539540
if (operations != null) {
540541
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
@@ -583,8 +584,12 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
583584
}
584585

585586
processOperation(operation);
587+
if (getBooleanValue(operation, CodegenConstants.HAS_AUTH_METHODS_EXT_NAME)) {
588+
hasAuthMethods = true;
589+
}
586590
}
587591
}
592+
objs.put("hasAuthMethods", hasAuthMethods);
588593
}
589594

590595
return objs;

src/main/resources/handlebars/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
{

src/main/resources/mustache/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
{

0 commit comments

Comments
 (0)