Skip to content

Commit d1d7c44

Browse files
committed
updated aspnetcore samples
1 parent b8a0085 commit d1d7c44

File tree

129 files changed

+2718
-1477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+2718
-1477
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.17-SNAPSHOT
1+
3.0.36-SNAPSHOT
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
Microsoft Visual Studio Solution File, Format Version 12.00
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
23
# Visual Studio 15
3-
VisualStudioVersion = 15.0.26114.2
4+
VisualStudioVersion = 15.0.27428.2043
45
MinimumVisualStudioVersion = 10.0.40219.1
5-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{67AC8A46-9D42-4F54-A882-5845BF1B56FC}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{EF2BCDD2-D76C-4156-8052-80240D346BC7}"
67
EndProject
78
Global
8-
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9-
Debug|Any CPU = Debug|Any CPU
10-
Release|Any CPU = Release|Any CPU
11-
EndGlobalSection
12-
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13-
{67AC8A46-9D42-4F54-A882-5845BF1B56FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14-
{67AC8A46-9D42-4F54-A882-5845BF1B56FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
15-
{67AC8A46-9D42-4F54-A882-5845BF1B56FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
16-
{67AC8A46-9D42-4F54-A882-5845BF1B56FC}.Release|Any CPU.Build.0 = Release|Any CPU
17-
EndGlobalSection
18-
GlobalSection(SolutionProperties) = preSolution
19-
HideSolutionNode = FALSE
20-
EndGlobalSection
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{EF2BCDD2-D76C-4156-8052-80240D346BC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{EF2BCDD2-D76C-4156-8052-80240D346BC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{EF2BCDD2-D76C-4156-8052-80240D346BC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{EF2BCDD2-D76C-4156-8052-80240D346BC7}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
2122
EndGlobal

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ public class DefaultApiController : ControllerBase, IDefaultApiController
3636
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
3737
[ValidateModelState]
3838
[SwaggerOperation("TestMethod")]
39-
[SwaggerResponse(statusCode: 200, type: typeof(List<Test>), description: "peticion realizada con exito")]
39+
[SwaggerResponse(statusCode: 200, type: typeof(List<string>), description: "peticion realizada con exito")]
4040
public virtual IActionResult TestMethod()
4141
{
4242
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
43-
// return StatusCode(200, default(List<Test>));
43+
// return StatusCode(200, default(List<string>));
4444
string exampleJson = null;
4545
exampleJson = "[ \"\", \"\" ]";
4646

4747
var example = exampleJson != null
48-
? JsonConvert.DeserializeObject<List<Test>>(exampleJson)
49-
: default(List<Test>); //TODO: Change the data returned
48+
? JsonConvert.DeserializeObject<List<string>>(exampleJson)
49+
: default(List<string>); //TODO: Change the data returned
5050
return new ObjectResult(example);
5151
}
5252
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface IPetApiController
2828
/// <param name="body"></param>
2929
/// <response code="405">Invalid input</response>
3030
/// <response code="200">successful operation</response>
31-
IActionResult AddParrot([FromBody]Body2 body);
31+
IActionResult AddParrot([FromBody]ParrotBody1 body);
3232

3333
/// <summary>
3434
/// Add a new pet to the store
@@ -48,6 +48,14 @@ public interface IPetApiController
4848
/// <response code="404">Pet not found</response>
4949
IActionResult DeletePet([FromRoute][Required]long? petId, [FromHeader]string apiKey);
5050

51+
/// <summary>
52+
///
53+
/// </summary>
54+
55+
/// <param name="body"></param>
56+
/// <response code="200">successful operation</response>
57+
IActionResult DoCategoryStuff([FromBody]SubCategory body);
58+
5159
/// <summary>
5260
/// Find pet by ID
5361
/// </summary>
@@ -102,7 +110,7 @@ public interface IPetApiController
102110
/// <param name="body"></param>
103111
/// <response code="405">Invalid input</response>
104112
/// <response code="200">successful operation</response>
105-
IActionResult UpdateParrots([FromBody]Body1 body);
113+
IActionResult UpdateParrots([FromBody]ParrotBody body);
106114

107115
/// <summary>
108116
/// Update an existing pet

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

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class PetApiController : ControllerBase, IPetApiController
3838
[ValidateModelState]
3939
[SwaggerOperation("AddParrot")]
4040
[SwaggerResponse(statusCode: 200, type: typeof(InlineResponse2001), description: "successful operation")]
41-
public virtual IActionResult AddParrot([FromBody]Body2 body)
41+
public virtual IActionResult AddParrot([FromBody]ParrotBody1 body)
4242
{
4343
//TODO: Uncomment the next line to return response 405 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
4444
// return StatusCode(405);
@@ -93,6 +93,29 @@ public virtual IActionResult DeletePet([FromRoute][Required]long? petId, [FromHe
9393
throw new NotImplementedException();
9494
}
9595

96+
/// <summary>
97+
///
98+
/// </summary>
99+
/// <param name="body"></param>
100+
/// <response code="200">successful operation</response>
101+
[HttpPost]
102+
[Route("/pet/category")]
103+
[ValidateModelState]
104+
[SwaggerOperation("DoCategoryStuff")]
105+
[SwaggerResponse(statusCode: 200, type: typeof(ModelApiResponse), description: "successful operation")]
106+
public virtual IActionResult DoCategoryStuff([FromBody]SubCategory body)
107+
{
108+
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
109+
// return StatusCode(200, default(ModelApiResponse));
110+
string exampleJson = null;
111+
exampleJson = "{\n \"code\" : 0,\n \"type\" : \"type\",\n \"message\" : \"message\"\n}";
112+
113+
var example = exampleJson != null
114+
? JsonConvert.DeserializeObject<ModelApiResponse>(exampleJson)
115+
: default(ModelApiResponse); //TODO: Change the data returned
116+
return new ObjectResult(example);
117+
}
118+
96119
/// <summary>
97120
/// Find pet by ID
98121
/// </summary>
@@ -179,17 +202,17 @@ public virtual IActionResult FindPetsByTags([FromQuery][Required()]List<string>
179202
[Route("/parrot")]
180203
[ValidateModelState]
181204
[SwaggerOperation("GetParrots")]
182-
[SwaggerResponse(statusCode: 200, type: typeof(List<>), description: "successful operation")]
205+
[SwaggerResponse(statusCode: 200, type: typeof(List<Object>), description: "successful operation")]
183206
public virtual IActionResult GetParrots()
184207
{
185208
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
186-
// return StatusCode(200, default(List<>));
209+
// return StatusCode(200, default(List<Object>));
187210
string exampleJson = null;
188211
exampleJson = "[ \"\", \"\" ]";
189212

190213
var example = exampleJson != null
191-
? JsonConvert.DeserializeObject<List<>>(exampleJson)
192-
: default(List<>); //TODO: Change the data returned
214+
? JsonConvert.DeserializeObject<List<Object>>(exampleJson)
215+
: default(List<Object>); //TODO: Change the data returned
193216
return new ObjectResult(example);
194217
}
195218

@@ -237,7 +260,7 @@ public virtual IActionResult GetPetById([FromRoute][Required]long? petId)
237260
[ValidateModelState]
238261
[SwaggerOperation("UpdateParrots")]
239262
[SwaggerResponse(statusCode: 200, type: typeof(InlineResponse200), description: "successful operation")]
240-
public virtual IActionResult UpdateParrots([FromBody]Body1 body)
263+
public virtual IActionResult UpdateParrots([FromBody]ParrotBody body)
241264
{
242265
//TODO: Uncomment the next line to return response 405 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
243266
// return StatusCode(405);
@@ -289,17 +312,17 @@ public virtual IActionResult UpdatePet([FromBody]Pet body)
289312
[Route("/pet/{petId}/uploadImage")]
290313
[ValidateModelState]
291314
[SwaggerOperation("UploadFile")]
292-
[SwaggerResponse(statusCode: 200, type: typeof(ApiResponse), description: "successful operation")]
315+
[SwaggerResponse(statusCode: 200, type: typeof(ModelApiResponse), description: "successful operation")]
293316
public virtual IActionResult UploadFile([FromRoute][Required]long? petId, [FromBody]Object body)
294317
{
295318
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
296-
// return StatusCode(200, default(ApiResponse));
319+
// return StatusCode(200, default(ModelApiResponse));
297320
string exampleJson = null;
298321
exampleJson = "{\n \"code\" : 0,\n \"type\" : \"type\",\n \"message\" : \"message\"\n}";
299322

300323
var example = exampleJson != null
301-
? JsonConvert.DeserializeObject<ApiResponse>(exampleJson)
302-
: default(ApiResponse); //TODO: Change the data returned
324+
? JsonConvert.DeserializeObject<ModelApiResponse>(exampleJson)
325+
: default(ModelApiResponse); //TODO: Change the data returned
303326
return new ObjectResult(example);
304327
}
305328
}

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

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

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

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

samples/composed/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Filters/BasePathFilter.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Text.RegularExpressions;
33
using Swashbuckle.AspNetCore.Swagger;
44
using Swashbuckle.AspNetCore.SwaggerGen;
5+
using Microsoft.OpenApi.Models;
56

67
namespace IO.Swagger.Filters
78
{
@@ -28,11 +29,11 @@ public BasePathFilter(string basePath)
2829
/// <summary>
2930
/// Apply the filter
3031
/// </summary>
31-
/// <param name="swaggerDoc">SwaggerDocument</param>
32+
/// <param name="swaggerDoc">OpenApiDocument</param>
3233
/// <param name="context">FilterContext</param>
33-
public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
34+
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
3435
{
35-
swaggerDoc.BasePath = this.BasePath;
36+
swaggerDoc.Servers.Add(new OpenApiServer() { Url = this.BasePath });
3637

3738
var pathsToModify = swaggerDoc.Paths.Where(p => p.Key.StartsWith(this.BasePath)).ToList();
3839

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.ComponentModel.DataAnnotations;
22
using System.Linq;
33
using Microsoft.AspNetCore.Mvc.Controllers;
4-
using Swashbuckle.AspNetCore.Swagger;
4+
using Microsoft.OpenApi.Models;
55
using Swashbuckle.AspNetCore.SwaggerGen;
66

77
namespace IO.Swagger.Filters
@@ -16,85 +16,81 @@ public class GeneratePathParamsValidationFilter : IOperationFilter
1616
/// </summary>
1717
/// <param name="operation">Operation</param>
1818
/// <param name="context">OperationFilterContext</param>
19-
public void Apply(Operation operation, OperationFilterContext context)
19+
public void Apply(OpenApiOperation operation, OperationFilterContext context)
2020
{
2121
var pars = context.ApiDescription.ParameterDescriptions;
2222

2323
foreach (var par in pars)
2424
{
2525
var swaggerParam = operation.Parameters.SingleOrDefault(p => p.Name == par.Name);
2626

27-
if (par.ParameterDescriptor != null && par.ParameterDescriptor is ControllerParameterDescriptor && ((ControllerParameterDescriptor)par.ParameterDescriptor).ParameterInfo != null)
27+
var attributes = ((ControllerParameterDescriptor)par.ParameterDescriptor).ParameterInfo.CustomAttributes;
28+
29+
if (attributes != null && attributes.Count() > 0 && swaggerParam != null)
2830
{
29-
var attributes = ((ControllerParameterDescriptor)par.ParameterDescriptor).ParameterInfo.CustomAttributes;
31+
// Required - [Required]
32+
var requiredAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RequiredAttribute));
33+
if (requiredAttr != null)
34+
{
35+
swaggerParam.Required = true;
36+
}
3037

31-
if (attributes != null && attributes.Count() > 0 && swaggerParam != null)
38+
// Regex Pattern [RegularExpression]
39+
var regexAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RegularExpressionAttribute));
40+
if (regexAttr != null)
3241
{
33-
// Required - [Required]
34-
var requiredAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RequiredAttribute));
35-
if (requiredAttr != null)
42+
string regex = (string)regexAttr.ConstructorArguments[0].Value;
43+
if (swaggerParam is OpenApiParameter)
3644
{
37-
swaggerParam.Required = true;
45+
((OpenApiParameter)swaggerParam).Schema.Pattern = regex;
3846
}
47+
}
3948

40-
// Regex Pattern [RegularExpression]
41-
var regexAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RegularExpressionAttribute));
42-
if (regexAttr != null)
49+
// String Length [StringLength]
50+
int? minLenght = null, maxLength = null;
51+
var stringLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(StringLengthAttribute));
52+
if (stringLengthAttr != null)
53+
{
54+
if (stringLengthAttr.NamedArguments.Count == 1)
4355
{
44-
string regex = (string)regexAttr.ConstructorArguments[0].Value;
45-
if (swaggerParam is NonBodyParameter)
46-
{
47-
((NonBodyParameter)swaggerParam).Pattern = regex;
48-
}
56+
minLenght = (int)stringLengthAttr.NamedArguments.Single(p => p.MemberName == "MinimumLength").TypedValue.Value;
4957
}
58+
maxLength = (int)stringLengthAttr.ConstructorArguments[0].Value;
59+
}
5060

51-
// String Length [StringLength]
52-
int? minLenght = null, maxLength = null;
53-
var stringLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(StringLengthAttribute));
54-
if (stringLengthAttr != null)
55-
{
56-
if (stringLengthAttr.NamedArguments.Count == 1)
57-
{
58-
minLenght = (int)stringLengthAttr.NamedArguments.Single(p => p.MemberName == "MinimumLength").TypedValue.Value;
59-
}
60-
maxLength = (int)stringLengthAttr.ConstructorArguments[0].Value;
61-
}
61+
var minLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MinLengthAttribute));
62+
if (minLengthAttr != null)
63+
{
64+
minLenght = (int)minLengthAttr.ConstructorArguments[0].Value;
65+
}
6266

63-
var minLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MinLengthAttribute));
64-
if (minLengthAttr != null)
65-
{
66-
minLenght = (int)minLengthAttr.ConstructorArguments[0].Value;
67-
}
67+
var maxLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MaxLengthAttribute));
68+
if (maxLengthAttr != null)
69+
{
70+
maxLength = (int)maxLengthAttr.ConstructorArguments[0].Value;
71+
}
6872

69-
var maxLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MaxLengthAttribute));
70-
if (maxLengthAttr != null)
71-
{
72-
maxLength = (int)maxLengthAttr.ConstructorArguments[0].Value;
73-
}
73+
if (swaggerParam is OpenApiParameter)
74+
{
75+
((OpenApiParameter)swaggerParam).Schema.MinLength = minLenght;
76+
((OpenApiParameter)swaggerParam).Schema.MaxLength = maxLength;
77+
}
7478

75-
if (swaggerParam is NonBodyParameter)
76-
{
77-
((NonBodyParameter)swaggerParam).MinLength = minLenght;
78-
((NonBodyParameter)swaggerParam).MaxLength = maxLength;
79-
}
79+
// Range [Range]
80+
var rangeAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RangeAttribute));
81+
if (rangeAttr != null)
82+
{
83+
int rangeMin = (int)rangeAttr.ConstructorArguments[0].Value;
84+
int rangeMax = (int)rangeAttr.ConstructorArguments[1].Value;
8085

81-
// Range [Range]
82-
var rangeAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RangeAttribute));
83-
if (rangeAttr != null)
86+
if (swaggerParam is OpenApiParameter)
8487
{
85-
int rangeMin = (int)rangeAttr.ConstructorArguments[0].Value;
86-
int rangeMax = (int)rangeAttr.ConstructorArguments[1].Value;
87-
88-
if (swaggerParam is NonBodyParameter)
89-
{
90-
((NonBodyParameter)swaggerParam).Minimum = rangeMin;
91-
((NonBodyParameter)swaggerParam).Maximum = rangeMax;
92-
}
88+
((OpenApiParameter)swaggerParam).Schema.Minimum = rangeMin;
89+
((OpenApiParameter)swaggerParam).Schema.Maximum = rangeMax;
9390
}
9491
}
9592
}
9693
}
9794
}
9895
}
9996
}
100-

0 commit comments

Comments
 (0)