Skip to content

Commit 14e0e4c

Browse files
committed
updated aspnet core 2.x samples
1 parent 33cb42b commit 14e0e4c

File tree

24 files changed

+764
-320
lines changed

24 files changed

+764
-320
lines changed

bin/aspnetcore-petstore-server.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ fi
2626

2727
# if you've executed sbt assembly previously it will use that instead.
2828
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -Dlogback.configurationFile=bin/logback.xml"
29-
ags="$@ generate -l aspnetcore -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/aspnetcore --additional-properties packageGuid={3C799344-F285-4669-8FD5-7ED9B795D5C5}"
29+
ags="$@ generate -l aspnetcore -i modules/swagger-codegen/src/test/resources/3_0_0/petstore.yaml -o samples/server/petstore/aspnetcore"
3030

3131
java $JAVA_OPTS -jar $executable $ags

modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/CodegenSecurity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public Scopes getScopes() {
8282
return scopes;
8383
}
8484

85+
public Boolean getHasScopes() {
86+
return scopes != null && !scopes.isEmpty();
87+
}
88+
8589
public Boolean getIsBasic() {
8690
return getBooleanValue(CodegenConstants.IS_BASIC_EXT_NAME);
8791
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.6-SNAPSHOT
1+
3.0.9-SNAPSHOT

samples/server/petstore/aspnetcore/IO.Swagger.sln

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
# Visual Studio 15
33
VisualStudioVersion = 15.0.26114.2
44
MinimumVisualStudioVersion = 10.0.40219.1
5-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "IO.Swagger", "srcIO.SwaggerIO.Swagger.csproj", "{3C799344-F285-4669-8FD5-7ED9B795D5C5}"
5+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{E48F4D3A-3BD6-4A91-B260-B9BB9AF32F0D}"
66
EndProject
77
Global
88
GlobalSection(SolutionConfigurationPlatforms) = preSolution
99
Debug|Any CPU = Debug|Any CPU
1010
Release|Any CPU = Release|Any CPU
1111
EndGlobalSection
1212
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13-
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14-
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
15-
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
16-
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Release|Any CPU.Build.0 = Release|Any CPU
13+
{E48F4D3A-3BD6-4A91-B260-B9BB9AF32F0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{E48F4D3A-3BD6-4A91-B260-B9BB9AF32F0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{E48F4D3A-3BD6-4A91-B260-B9BB9AF32F0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{E48F4D3A-3BD6-4A91-B260-B9BB9AF32F0D}.Release|Any CPU.Build.0 = Release|Any CPU
1717
EndGlobalSection
1818
GlobalSection(SolutionProperties) = preSolution
1919
HideSolutionNode = FALSE

samples/server/petstore/aspnetcore/README.md

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

3-
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.
3+
This is a sample 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/).
44

55
## Run
66

samples/server/petstore/aspnetcore/build.bat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
@echo off
55

6-
dotnet restore srcIO.Swagger
7-
dotnet build srcIO.Swagger
8-
echo Now, run the following to start the project: dotnet run -p srcIO.SwaggerIO.Swagger.csproj --launch-profile web.
6+
dotnet restore src\IO.Swagger
7+
dotnet build src\IO.Swagger
8+
echo Now, run the following to start the project: dotnet run -p src\IO.Swagger\IO.Swagger.csproj --launch-profile web.
99
echo.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Swagger Petstore
3+
*
4+
* This is a sample 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/).
5+
*
6+
* OpenAPI spec version: 1.0.0
7+
* Contact: [email protected]
8+
* Generated by: https://github.com/swagger-api/swagger-codegen.git
9+
*/
10+
using System;
11+
using System.Collections.Generic;
12+
using Microsoft.AspNetCore.Mvc;
13+
using Swashbuckle.AspNetCore.Annotations;
14+
using Swashbuckle.AspNetCore.SwaggerGen;
15+
using Newtonsoft.Json;
16+
using System.ComponentModel.DataAnnotations;
17+
using IO.Swagger.Attributes;
18+
using IO.Swagger.Security;
19+
using Microsoft.AspNetCore.Authorization;
20+
using IO.Swagger.Models;
21+
22+
namespace IO.Swagger.Controllers
23+
{
24+
/// <summary>
25+
///
26+
/// </summary>
27+
[ApiController]
28+
public class DefaultApiController : ControllerBase
29+
{
30+
/// <summary>
31+
///
32+
/// </summary>
33+
/// <response code="200">peticion realizada con exito</response>
34+
[HttpGet]
35+
[Route("/test")]
36+
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
37+
[ValidateModelState]
38+
[SwaggerOperation("TestMethod")]
39+
[SwaggerResponse(statusCode: 200, type: typeof(List<Test>), description: "peticion realizada con exito")]
40+
public virtual IActionResult TestMethod()
41+
{
42+
//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>));
44+
string exampleJson = null;
45+
exampleJson = "[ \"\", \"\" ]";
46+
47+
var example = exampleJson != null
48+
? JsonConvert.DeserializeObject<List<Test>>(exampleJson)
49+
: default(List<Test>); //TODO: Change the data returned
50+
return new ObjectResult(example);
51+
}
52+
}
53+
}

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,39 @@
11
/*
22
* Swagger Petstore
33
*
4-
* 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.
4+
* This is a sample 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/).
55
*
66
* OpenAPI spec version: 1.0.0
77
* Contact: [email protected]
88
* Generated by: https://github.com/swagger-api/swagger-codegen.git
99
*/
1010
using System;
1111
using System.Collections.Generic;
12-
using System.Linq;
13-
using System.Net;
14-
using System.Threading.Tasks;
15-
using Microsoft.AspNetCore.Http;
1612
using Microsoft.AspNetCore.Mvc;
17-
using Microsoft.AspNetCore.WebUtilities;
18-
using Microsoft.Extensions.Logging;
19-
using Microsoft.Extensions.Primitives;
13+
using Swashbuckle.AspNetCore.Annotations;
2014
using Swashbuckle.AspNetCore.SwaggerGen;
2115
using Newtonsoft.Json;
2216
using System.ComponentModel.DataAnnotations;
2317
using IO.Swagger.Attributes;
18+
using IO.Swagger.Security;
19+
using Microsoft.AspNetCore.Authorization;
2420
using IO.Swagger.Models;
2521

2622
namespace IO.Swagger.Controllers
2723
{
2824
/// <summary>
2925
///
3026
/// </summary>
31-
public class PetApiController : Controller
27+
[ApiController]
28+
public class PetApiController : ControllerBase
3229
{
3330
/// <summary>
3431
/// Add a new pet to the store
3532
/// </summary>
36-
3733
/// <param name="body">Pet object that needs to be added to the store</param>
3834
/// <response code="405">Invalid input</response>
3935
[HttpPost]
40-
[Route("/v2/pet")]
36+
[Route("/pet")]
4137
[ValidateModelState]
4238
[SwaggerOperation("AddPet")]
4339
public virtual IActionResult AddPet([FromBody]Pet body)
@@ -51,19 +47,22 @@ public virtual IActionResult AddPet([FromBody]Pet body)
5147
/// <summary>
5248
/// Deletes a pet
5349
/// </summary>
54-
5550
/// <param name="petId">Pet id to delete</param>
5651
/// <param name="apiKey"></param>
57-
/// <response code="400">Invalid pet value</response>
52+
/// <response code="400">Invalid ID supplied</response>
53+
/// <response code="404">Pet not found</response>
5854
[HttpDelete]
59-
[Route("/v2/pet/{petId}")]
55+
[Route("/pet/{petId}")]
6056
[ValidateModelState]
6157
[SwaggerOperation("DeletePet")]
62-
public virtual IActionResult DeletePet([FromRoute][Required]int? petId, [FromHeader]string apiKey)
58+
public virtual IActionResult DeletePet([FromRoute][Required]long? petId, [FromHeader]string apiKey)
6359
{
6460
//TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
6561
// return StatusCode(400);
6662

63+
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
64+
// return StatusCode(404);
65+
6766
throw new NotImplementedException();
6867
}
6968

@@ -75,7 +74,7 @@ public virtual IActionResult DeletePet([FromRoute][Required]int? petId, [FromHea
7574
/// <response code="200">successful operation</response>
7675
/// <response code="400">Invalid status value</response>
7776
[HttpGet]
78-
[Route("/v2/pet/findByStatus")]
77+
[Route("/pet/findByStatus")]
7978
[ValidateModelState]
8079
[SwaggerOperation("FindPetsByStatus")]
8180
[SwaggerResponse(statusCode: 200, type: typeof(List<Pet>), description: "successful operation")]
@@ -87,6 +86,7 @@ public virtual IActionResult FindPetsByStatus([FromQuery][Required()]List<string
8786
//TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
8887
// return StatusCode(400);
8988
string exampleJson = null;
89+
exampleJson = "[ {\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ],\n \"name\" : \"doggie\",\n \"id\" : 0,\n \"category\" : {\n \"name\" : \"name\",\n \"id\" : 6\n },\n \"tags\" : [ {\n \"name\" : \"name\",\n \"id\" : 1\n }, {\n \"name\" : \"name\",\n \"id\" : 1\n } ],\n \"status\" : \"available\"\n}, {\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ],\n \"name\" : \"doggie\",\n \"id\" : 0,\n \"category\" : {\n \"name\" : \"name\",\n \"id\" : 6\n },\n \"tags\" : [ {\n \"name\" : \"name\",\n \"id\" : 1\n }, {\n \"name\" : \"name\",\n \"id\" : 1\n } ],\n \"status\" : \"available\"\n} ]";
9090

9191
var example = exampleJson != null
9292
? JsonConvert.DeserializeObject<List<Pet>>(exampleJson)
@@ -97,12 +97,12 @@ public virtual IActionResult FindPetsByStatus([FromQuery][Required()]List<string
9797
/// <summary>
9898
/// Finds Pets by tags
9999
/// </summary>
100-
/// <remarks>Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.</remarks>
100+
/// <remarks>Muliple tags can be provided with comma separated strings. Use\\ \\ tag1, tag2, tag3 for testing.</remarks>
101101
/// <param name="tags">Tags to filter by</param>
102102
/// <response code="200">successful operation</response>
103103
/// <response code="400">Invalid tag value</response>
104104
[HttpGet]
105-
[Route("/v2/pet/findByTags")]
105+
[Route("/pet/findByTags")]
106106
[ValidateModelState]
107107
[SwaggerOperation("FindPetsByTags")]
108108
[SwaggerResponse(statusCode: 200, type: typeof(List<Pet>), description: "successful operation")]
@@ -114,6 +114,7 @@ public virtual IActionResult FindPetsByTags([FromQuery][Required()]List<string>
114114
//TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
115115
// return StatusCode(400);
116116
string exampleJson = null;
117+
exampleJson = "[ {\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ],\n \"name\" : \"doggie\",\n \"id\" : 0,\n \"category\" : {\n \"name\" : \"name\",\n \"id\" : 6\n },\n \"tags\" : [ {\n \"name\" : \"name\",\n \"id\" : 1\n }, {\n \"name\" : \"name\",\n \"id\" : 1\n } ],\n \"status\" : \"available\"\n}, {\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ],\n \"name\" : \"doggie\",\n \"id\" : 0,\n \"category\" : {\n \"name\" : \"name\",\n \"id\" : 6\n },\n \"tags\" : [ {\n \"name\" : \"name\",\n \"id\" : 1\n }, {\n \"name\" : \"name\",\n \"id\" : 1\n } ],\n \"status\" : \"available\"\n} ]";
117118

118119
var example = exampleJson != null
119120
? JsonConvert.DeserializeObject<List<Pet>>(exampleJson)
@@ -130,11 +131,12 @@ public virtual IActionResult FindPetsByTags([FromQuery][Required()]List<string>
130131
/// <response code="400">Invalid ID supplied</response>
131132
/// <response code="404">Pet not found</response>
132133
[HttpGet]
133-
[Route("/v2/pet/{petId}")]
134+
[Route("/pet/{petId}")]
135+
[Authorize(AuthenticationSchemes = ApiKeyAuthenticationHandler.SchemeName)]
134136
[ValidateModelState]
135137
[SwaggerOperation("GetPetById")]
136138
[SwaggerResponse(statusCode: 200, type: typeof(Pet), description: "successful operation")]
137-
public virtual IActionResult GetPetById([FromRoute][Required]int? petId)
139+
public virtual IActionResult GetPetById([FromRoute][Required]long? petId)
138140
{
139141
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
140142
// return StatusCode(200, default(Pet));
@@ -145,6 +147,7 @@ public virtual IActionResult GetPetById([FromRoute][Required]int? petId)
145147
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
146148
// return StatusCode(404);
147149
string exampleJson = null;
150+
exampleJson = "{\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ],\n \"name\" : \"doggie\",\n \"id\" : 0,\n \"category\" : {\n \"name\" : \"name\",\n \"id\" : 6\n },\n \"tags\" : [ {\n \"name\" : \"name\",\n \"id\" : 1\n }, {\n \"name\" : \"name\",\n \"id\" : 1\n } ],\n \"status\" : \"available\"\n}";
148151

149152
var example = exampleJson != null
150153
? JsonConvert.DeserializeObject<Pet>(exampleJson)
@@ -155,13 +158,12 @@ public virtual IActionResult GetPetById([FromRoute][Required]int? petId)
155158
/// <summary>
156159
/// Update an existing pet
157160
/// </summary>
158-
159161
/// <param name="body">Pet object that needs to be added to the store</param>
160162
/// <response code="400">Invalid ID supplied</response>
161163
/// <response code="404">Pet not found</response>
162164
/// <response code="405">Validation exception</response>
163165
[HttpPut]
164-
[Route("/v2/pet")]
166+
[Route("/pet")]
165167
[ValidateModelState]
166168
[SwaggerOperation("UpdatePet")]
167169
public virtual IActionResult UpdatePet([FromBody]Pet body)
@@ -181,16 +183,15 @@ public virtual IActionResult UpdatePet([FromBody]Pet body)
181183
/// <summary>
182184
/// Updates a pet in the store with form data
183185
/// </summary>
184-
185186
/// <param name="petId">ID of pet that needs to be updated</param>
186187
/// <param name="name"></param>
187188
/// <param name="status"></param>
188189
/// <response code="405">Invalid input</response>
189190
[HttpPost]
190-
[Route("/v2/pet/{petId}")]
191+
[Route("/pet/{petId}")]
191192
[ValidateModelState]
192193
[SwaggerOperation("UpdatePetWithForm")]
193-
public virtual IActionResult UpdatePetWithForm([FromRoute][Required]int? petId, [FromForm]string name, [FromForm]string status)
194+
public virtual IActionResult UpdatePetWithForm([FromRoute][Required]long? petId, [FromForm]string name, [FromForm]string status)
194195
{
195196
//TODO: Uncomment the next line to return response 405 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
196197
// return StatusCode(405);
@@ -201,21 +202,20 @@ public virtual IActionResult UpdatePetWithForm([FromRoute][Required]int? petId,
201202
/// <summary>
202203
/// uploads an image
203204
/// </summary>
204-
205205
/// <param name="petId">ID of pet to update</param>
206-
/// <param name="additionalMetadata"></param>
207-
/// <param name="file"></param>
206+
/// <param name="body"></param>
208207
/// <response code="200">successful operation</response>
209208
[HttpPost]
210-
[Route("/v2/pet/{petId}/uploadImage")]
209+
[Route("/pet/{petId}/uploadImage")]
211210
[ValidateModelState]
212211
[SwaggerOperation("UploadFile")]
213212
[SwaggerResponse(statusCode: 200, type: typeof(ApiResponse), description: "successful operation")]
214-
public virtual IActionResult UploadFile([FromRoute][Required]int? petId, [FromForm]string additionalMetadata, [FromForm]System.IO.Stream file)
213+
public virtual IActionResult UploadFile([FromRoute][Required]long? petId, [FromBody]Object body)
215214
{
216215
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
217216
// return StatusCode(200, default(ApiResponse));
218217
string exampleJson = null;
218+
exampleJson = "{\n \"code\" : 0,\n \"type\" : \"type\",\n \"message\" : \"message\"\n}";
219219

220220
var example = exampleJson != null
221221
? JsonConvert.DeserializeObject<ApiResponse>(exampleJson)

0 commit comments

Comments
 (0)