Skip to content

Commit

Permalink
updated aspnet core 2.x samples
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMario committed Jun 20, 2019
1 parent 33cb42b commit 14e0e4c
Show file tree
Hide file tree
Showing 24 changed files with 764 additions and 320 deletions.
2 changes: 1 addition & 1 deletion bin/aspnetcore-petstore-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -Dlogback.configurationFile=bin/logback.xml"
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}"
ags="$@ generate -l aspnetcore -i modules/swagger-codegen/src/test/resources/3_0_0/petstore.yaml -o samples/server/petstore/aspnetcore"

java $JAVA_OPTS -jar $executable $ags
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public Scopes getScopes() {
return scopes;
}

public Boolean getHasScopes() {
return scopes != null && !scopes.isEmpty();
}

public Boolean getIsBasic() {
return getBooleanValue(CodegenConstants.IS_BASIC_EXT_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.6-SNAPSHOT
3.0.9-SNAPSHOT
10 changes: 5 additions & 5 deletions samples/server/petstore/aspnetcore/IO.Swagger.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# Visual Studio 15
VisualStudioVersion = 15.0.26114.2
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "IO.Swagger", "srcIO.SwaggerIO.Swagger.csproj", "{3C799344-F285-4669-8FD5-7ED9B795D5C5}"
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{E48F4D3A-3BD6-4A91-B260-B9BB9AF32F0D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Release|Any CPU.Build.0 = Release|Any CPU
{E48F4D3A-3BD6-4A91-B260-B9BB9AF32F0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E48F4D3A-3BD6-4A91-B260-B9BB9AF32F0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E48F4D3A-3BD6-4A91-B260-B9BB9AF32F0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E48F4D3A-3BD6-4A91-B260-B9BB9AF32F0D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/aspnetcore/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# IO.Swagger - ASP.NET Core 2.0 Server

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

## Run

Expand Down
6 changes: 3 additions & 3 deletions samples/server/petstore/aspnetcore/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@echo off

dotnet restore srcIO.Swagger
dotnet build srcIO.Swagger
echo Now, run the following to start the project: dotnet run -p srcIO.SwaggerIO.Swagger.csproj --launch-profile web.
dotnet restore src\IO.Swagger
dotnet build src\IO.Swagger
echo Now, run the following to start the project: dotnet run -p src\IO.Swagger\IO.Swagger.csproj --launch-profile web.
echo.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Swagger Petstore
*
* This is a sample Petstore server. You can find out more about Swagger at [http:https://swagger.io](http:https://swagger.io) or on [irc.freenode.net, #swagger](http:https://swagger.io/irc/).
*
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using Swashbuckle.AspNetCore.SwaggerGen;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using IO.Swagger.Attributes;
using IO.Swagger.Security;
using Microsoft.AspNetCore.Authorization;
using IO.Swagger.Models;

namespace IO.Swagger.Controllers
{
/// <summary>
///
/// </summary>
[ApiController]
public class DefaultApiController : ControllerBase
{
/// <summary>
///
/// </summary>
/// <response code="200">peticion realizada con exito</response>
[HttpGet]
[Route("/test")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("TestMethod")]
[SwaggerResponse(statusCode: 200, type: typeof(List<Test>), description: "peticion realizada con exito")]
public virtual IActionResult TestMethod()
{
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(200, default(List<Test>));
string exampleJson = null;
exampleJson = "[ \"\", \"\" ]";

var example = exampleJson != null
? JsonConvert.DeserializeObject<List<Test>>(exampleJson)
: default(List<Test>); //TODO: Change the data returned
return new ObjectResult(example);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
/*
* Swagger Petstore
*
* This is a sample server Petstore server. You can find out more about Swagger at [http:https://swagger.io](http:https://swagger.io) or on [irc.freenode.net, #swagger](http:https://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
* This is a sample Petstore server. You can find out more about Swagger at [http:https://swagger.io](http:https://swagger.io) or on [irc.freenode.net, #swagger](http:https://swagger.io/irc/).
*
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Swashbuckle.AspNetCore.Annotations;
using Swashbuckle.AspNetCore.SwaggerGen;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using IO.Swagger.Attributes;
using IO.Swagger.Security;
using Microsoft.AspNetCore.Authorization;
using IO.Swagger.Models;

namespace IO.Swagger.Controllers
{
/// <summary>
///
/// </summary>
public class PetApiController : Controller
[ApiController]
public class PetApiController : ControllerBase
{
/// <summary>
/// Add a new pet to the store
/// </summary>

/// <param name="body">Pet object that needs to be added to the store</param>
/// <response code="405">Invalid input</response>
[HttpPost]
[Route("/v2/pet")]
[Route("/pet")]
[ValidateModelState]
[SwaggerOperation("AddPet")]
public virtual IActionResult AddPet([FromBody]Pet body)
Expand All @@ -51,19 +47,22 @@ public virtual IActionResult AddPet([FromBody]Pet body)
/// <summary>
/// Deletes a pet
/// </summary>

/// <param name="petId">Pet id to delete</param>
/// <param name="apiKey"></param>
/// <response code="400">Invalid pet value</response>
/// <response code="400">Invalid ID supplied</response>
/// <response code="404">Pet not found</response>
[HttpDelete]
[Route("/v2/pet/{petId}")]
[Route("/pet/{petId}")]
[ValidateModelState]
[SwaggerOperation("DeletePet")]
public virtual IActionResult DeletePet([FromRoute][Required]int? petId, [FromHeader]string apiKey)
public virtual IActionResult DeletePet([FromRoute][Required]long? petId, [FromHeader]string apiKey)
{
//TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(400);

//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(404);

throw new NotImplementedException();
}

Expand All @@ -75,7 +74,7 @@ public virtual IActionResult DeletePet([FromRoute][Required]int? petId, [FromHea
/// <response code="200">successful operation</response>
/// <response code="400">Invalid status value</response>
[HttpGet]
[Route("/v2/pet/findByStatus")]
[Route("/pet/findByStatus")]
[ValidateModelState]
[SwaggerOperation("FindPetsByStatus")]
[SwaggerResponse(statusCode: 200, type: typeof(List<Pet>), description: "successful operation")]
Expand All @@ -87,6 +86,7 @@ public virtual IActionResult FindPetsByStatus([FromQuery][Required()]List<string
//TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(400);
string exampleJson = null;
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} ]";

var example = exampleJson != null
? JsonConvert.DeserializeObject<List<Pet>>(exampleJson)
Expand All @@ -97,12 +97,12 @@ public virtual IActionResult FindPetsByStatus([FromQuery][Required()]List<string
/// <summary>
/// Finds Pets by tags
/// </summary>
/// <remarks>Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.</remarks>
/// <remarks>Muliple tags can be provided with comma separated strings. Use\\ \\ tag1, tag2, tag3 for testing.</remarks>
/// <param name="tags">Tags to filter by</param>
/// <response code="200">successful operation</response>
/// <response code="400">Invalid tag value</response>
[HttpGet]
[Route("/v2/pet/findByTags")]
[Route("/pet/findByTags")]
[ValidateModelState]
[SwaggerOperation("FindPetsByTags")]
[SwaggerResponse(statusCode: 200, type: typeof(List<Pet>), description: "successful operation")]
Expand All @@ -114,6 +114,7 @@ public virtual IActionResult FindPetsByTags([FromQuery][Required()]List<string>
//TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(400);
string exampleJson = null;
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} ]";

var example = exampleJson != null
? JsonConvert.DeserializeObject<List<Pet>>(exampleJson)
Expand All @@ -130,11 +131,12 @@ public virtual IActionResult FindPetsByTags([FromQuery][Required()]List<string>
/// <response code="400">Invalid ID supplied</response>
/// <response code="404">Pet not found</response>
[HttpGet]
[Route("/v2/pet/{petId}")]
[Route("/pet/{petId}")]
[Authorize(AuthenticationSchemes = ApiKeyAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetPetById")]
[SwaggerResponse(statusCode: 200, type: typeof(Pet), description: "successful operation")]
public virtual IActionResult GetPetById([FromRoute][Required]int? petId)
public virtual IActionResult GetPetById([FromRoute][Required]long? petId)
{
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(200, default(Pet));
Expand All @@ -145,6 +147,7 @@ public virtual IActionResult GetPetById([FromRoute][Required]int? petId)
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(404);
string exampleJson = null;
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}";

var example = exampleJson != null
? JsonConvert.DeserializeObject<Pet>(exampleJson)
Expand All @@ -155,13 +158,12 @@ public virtual IActionResult GetPetById([FromRoute][Required]int? petId)
/// <summary>
/// Update an existing pet
/// </summary>

/// <param name="body">Pet object that needs to be added to the store</param>
/// <response code="400">Invalid ID supplied</response>
/// <response code="404">Pet not found</response>
/// <response code="405">Validation exception</response>
[HttpPut]
[Route("/v2/pet")]
[Route("/pet")]
[ValidateModelState]
[SwaggerOperation("UpdatePet")]
public virtual IActionResult UpdatePet([FromBody]Pet body)
Expand All @@ -181,16 +183,15 @@ public virtual IActionResult UpdatePet([FromBody]Pet body)
/// <summary>
/// Updates a pet in the store with form data
/// </summary>

/// <param name="petId">ID of pet that needs to be updated</param>
/// <param name="name"></param>
/// <param name="status"></param>
/// <response code="405">Invalid input</response>
[HttpPost]
[Route("/v2/pet/{petId}")]
[Route("/pet/{petId}")]
[ValidateModelState]
[SwaggerOperation("UpdatePetWithForm")]
public virtual IActionResult UpdatePetWithForm([FromRoute][Required]int? petId, [FromForm]string name, [FromForm]string status)
public virtual IActionResult UpdatePetWithForm([FromRoute][Required]long? petId, [FromForm]string name, [FromForm]string status)
{
//TODO: Uncomment the next line to return response 405 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(405);
Expand All @@ -201,21 +202,20 @@ public virtual IActionResult UpdatePetWithForm([FromRoute][Required]int? petId,
/// <summary>
/// uploads an image
/// </summary>

/// <param name="petId">ID of pet to update</param>
/// <param name="additionalMetadata"></param>
/// <param name="file"></param>
/// <param name="body"></param>
/// <response code="200">successful operation</response>
[HttpPost]
[Route("/v2/pet/{petId}/uploadImage")]
[Route("/pet/{petId}/uploadImage")]
[ValidateModelState]
[SwaggerOperation("UploadFile")]
[SwaggerResponse(statusCode: 200, type: typeof(ApiResponse), description: "successful operation")]
public virtual IActionResult UploadFile([FromRoute][Required]int? petId, [FromForm]string additionalMetadata, [FromForm]System.IO.Stream file)
public virtual IActionResult UploadFile([FromRoute][Required]long? petId, [FromBody]Object body)
{
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(200, default(ApiResponse));
string exampleJson = null;
exampleJson = "{\n \"code\" : 0,\n \"type\" : \"type\",\n \"message\" : \"message\"\n}";

var example = exampleJson != null
? JsonConvert.DeserializeObject<ApiResponse>(exampleJson)
Expand Down
Loading

0 comments on commit 14e0e4c

Please sign in to comment.