Skip to content

Commit 74cc5c0

Browse files
authored
Merge pull request #10197 from swagger-api/issue-10059
check complex type for enum in order to avoid duplicated code.
2 parents fd7a80d + ade06df commit 74cc5c0

File tree

28 files changed

+199
-157
lines changed

28 files changed

+199
-157
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

modules/swagger-codegen/src/main/resources/aspnetcore/model.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace {{packageName}}.Models
1919
/// </summary>
2020
[DataContract]
2121
public partial class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}}IEquatable<{{classname}}>
22-
{ {{#vars}}{{#isEnum}}{{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}{{>enumClass}}{{/items}}{{/items.isEnum}}
22+
{ {{#vars}}{{#isEnum}}{{^complexType}}{{>enumClass}}{{/complexType}}{{/isEnum}}{{#items.isEnum}}{{#items}}{{^complexType}}{{>enumClass}}{{/complexType}}{{/items}}{{/items.isEnum}}
2323
/// <summary>
2424
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
2525
/// </summary>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.6-SNAPSHOT
1+
2.4.14-SNAPSHOT

samples/server/petstore/aspnetcore-interface-controller/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# IO.Swagger - ASP.NET Core 2.0 Server
1+
# IO.Swagger - ASP.NET Core 3.0 Server
22

33
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
44

samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/IPetApi.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ public interface IPetApiController
9393

9494
/// <param name="petId">ID of pet to update</param>
9595
/// <param name="additionalMetadata">Additional data to pass to server</param>
96-
/// <param name="file">file to upload</param>
96+
/// <param name="_file">file to upload</param>
9797
/// <response code="200">successful operation</response>
98-
IActionResult UploadFile([FromRoute][Required]long? petId, [FromForm]string additionalMetadata, [FromForm]System.IO.Stream file);
98+
IActionResult UploadFile([FromRoute][Required]long? petId, [FromForm]string additionalMetadata, [FromForm]System.IO.Stream _file);
9999
}
100100
}

samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/PetApi.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ public virtual IActionResult UpdatePetWithForm([FromRoute][Required]long? petId,
219219

220220
/// <param name="petId">ID of pet to update</param>
221221
/// <param name="additionalMetadata">Additional data to pass to server</param>
222-
/// <param name="file">file to upload</param>
222+
/// <param name="_file">file to upload</param>
223223
/// <response code="200">successful operation</response>
224224
[HttpPost]
225225
[Route("/v2/pet/{petId}/uploadImage")]
226226
[ValidateModelState]
227227
[SwaggerOperation("UploadFile")]
228228
[SwaggerResponse(statusCode: 200, type: typeof(ApiResponse), description: "successful operation")]
229-
public virtual IActionResult UploadFile([FromRoute][Required]long? petId, [FromForm]string additionalMetadata, [FromForm]System.IO.Stream file)
229+
public virtual IActionResult UploadFile([FromRoute][Required]long? petId, [FromForm]string additionalMetadata, [FromForm]System.IO.Stream _file)
230230
{
231231
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
232232
// return StatusCode(200, default(ApiResponse));

samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/UserApi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
using Newtonsoft.Json;
1717
using System.ComponentModel.DataAnnotations;
1818
using IO.Swagger.Attributes;
19-
using IO.Swagger.Security;
19+
2020
using Microsoft.AspNetCore.Authorization;
2121
using IO.Swagger.Models;
2222

samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM microsoft/aspnetcore-build:2.0 AS build-env
1+
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build-env
22
WORKDIR /app
33

44
ENV DOTNET_CLI_TELEMETRY_OPTOUT 1
@@ -12,7 +12,7 @@ COPY . ./
1212
RUN dotnet publish -c Release -o out
1313

1414
# build runtime image
15-
FROM microsoft/aspnetcore:2.0
15+
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0
1616
WORKDIR /app
1717
COPY --from=build-env /app/out .
1818
ENTRYPOINT ["dotnet", "IO.Swagger.dll"]

0 commit comments

Comments
 (0)