From 47738f6cd65d335b78d4805a256e72ac32de30ac Mon Sep 17 00:00:00 2001 From: wing328 Date: Fri, 5 Aug 2016 16:30:59 +0800 Subject: [PATCH] [Sinatra][Nancyfx] fix enum in Sinatra and nancyfx (#3532) * fix enum in sintra and nancyfx * add isContainer check for sinatra allowable value * fix EOL in nancyfx enum template --- .../main/resources/nancyfx/innerApiEnum.mustache | 8 +++++++- .../resources/nancyfx/innerApiEnumName.mustache | 2 +- .../src/main/resources/sinatra/api.mustache | 2 +- samples/server/petstore/nancyfx/IO.Swagger.sln | 10 +++++----- .../nancyfx/src/IO.Swagger/IO.Swagger.csproj | 2 +- .../nancyfx/src/IO.Swagger/Modules/PetModule.cs | 16 +++++++++++----- 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/nancyfx/innerApiEnum.mustache b/modules/swagger-codegen/src/main/resources/nancyfx/innerApiEnum.mustache index 5a7a89aa528..0c6a219e7bb 100644 --- a/modules/swagger-codegen/src/main/resources/nancyfx/innerApiEnum.mustache +++ b/modules/swagger-codegen/src/main/resources/nancyfx/innerApiEnum.mustache @@ -1,4 +1,10 @@ /// /// {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}} /// - public enum {{>innerApiEnumName}} { {{#allowableValues}}{{#values}}{{&.}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}} }; \ No newline at end of file + public enum {{>innerApiEnumName}} + { + {{#allowableValues}} +{{#values}} {{&.}}{{^-last}}, {{/-last}} +{{/values}} + {{/allowableValues}} + }; diff --git a/modules/swagger-codegen/src/main/resources/nancyfx/innerApiEnumName.mustache b/modules/swagger-codegen/src/main/resources/nancyfx/innerApiEnumName.mustache index f54069fb50c..f2b90daa144 100644 --- a/modules/swagger-codegen/src/main/resources/nancyfx/innerApiEnumName.mustache +++ b/modules/swagger-codegen/src/main/resources/nancyfx/innerApiEnumName.mustache @@ -1 +1 @@ -{{#datatypeWithEnum}}{{operationId}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} \ No newline at end of file +{{#datatypeWithEnum}}{{operationId}}{{^isContainer}}{{.}}{{/isContainer}}{{#isContainer}}{{{items.datatypeWithEnum}}}{{/isContainer}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/sinatra/api.mustache b/modules/swagger-codegen/src/main/resources/sinatra/api.mustache index 27830feed31..55230231f2c 100644 --- a/modules/swagger-codegen/src/main/resources/sinatra/api.mustache +++ b/modules/swagger-codegen/src/main/resources/sinatra/api.mustache @@ -18,7 +18,7 @@ MyApp.add_route('{{httpMethod}}', '{{basePathWithoutHost}}{{path}}', { "dataType" => "{{dataType}}", "paramType" => "query", {{#collectionFormat}}"collectionFormat" => "{{collectionFormat}}",{{/collectionFormat}} - "allowableValues" => "{{allowableValues}}", + "allowableValues" => "{{^isContainer}}{{{allowableValues.values}}}{{/isContainer}}", {{#defaultValue}}"defaultValue" => "{{{defaultValue}}}"{{/defaultValue}} }, {{/queryParams}} diff --git a/samples/server/petstore/nancyfx/IO.Swagger.sln b/samples/server/petstore/nancyfx/IO.Swagger.sln index 87b0eca9e40..0a38b2ea778 100644 --- a/samples/server/petstore/nancyfx/IO.Swagger.sln +++ b/samples/server/petstore/nancyfx/IO.Swagger.sln @@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 VisualStudioVersion = 12.0.0.0 MinimumVisualStudioVersion = 10.0.0.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{4E6FF76E-03ED-499F-B05C-4315904C488E}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{D198220E-91F6-402F-966F-8EF6105B1B75}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -10,10 +10,10 @@ Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution -{4E6FF76E-03ED-499F-B05C-4315904C488E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU -{4E6FF76E-03ED-499F-B05C-4315904C488E}.Debug|Any CPU.Build.0 = Debug|Any CPU -{4E6FF76E-03ED-499F-B05C-4315904C488E}.Release|Any CPU.ActiveCfg = Release|Any CPU -{4E6FF76E-03ED-499F-B05C-4315904C488E}.Release|Any CPU.Build.0 = Release|Any CPU +{D198220E-91F6-402F-966F-8EF6105B1B75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{D198220E-91F6-402F-966F-8EF6105B1B75}.Debug|Any CPU.Build.0 = Debug|Any CPU +{D198220E-91F6-402F-966F-8EF6105B1B75}.Release|Any CPU.ActiveCfg = Release|Any CPU +{D198220E-91F6-402F-966F-8EF6105B1B75}.Release|Any CPU.Build.0 = Release|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.csproj b/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.csproj index 694e6c1ad4d..1d18142a14a 100644 --- a/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.csproj +++ b/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - {4E6FF76E-03ED-499F-B05C-4315904C488E} + {D198220E-91F6-402F-966F-8EF6105B1B75} Library Properties IO.Swagger.v2 diff --git a/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/PetModule.cs b/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/PetModule.cs index 3f47101563f..d6922531e24 100644 --- a/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/PetModule.cs +++ b/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/PetModule.cs @@ -12,7 +12,13 @@ namespace IO.Swagger.v2.Modules /// /// Status values that need to be considered for filter /// - public enum FindPetsByStatusList<StatusEnum> { }; + public enum FindPetsByStatusStatusEnum + { + available, + pending, + sold + }; + /// /// Module processing requests of Pet domain. @@ -46,7 +52,7 @@ namespace IO.Swagger.v2.Modules Get["/pet/findByStatus"] = parameters => { - var status = Parameters.ValueOf(parameters, Context.Request, "status", ParameterType.Query); + var status = Parameters.ValueOf(parameters, Context.Request, "status", ParameterType.Query); Preconditions.IsNotNull(status, "Required parameter: 'status' is missing at 'FindPetsByStatus'"); return service.FindPetsByStatus(Context, status); @@ -128,7 +134,7 @@ namespace IO.Swagger.v2.Modules /// Context of request /// Status values that need to be considered for filter /// List<Pet> - List FindPetsByStatus(NancyContext context, FindPetsByStatusList<StatusEnum>? status); + List FindPetsByStatus(NancyContext context, FindPetsByStatusStatusEnum? status); /// /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -190,7 +196,7 @@ namespace IO.Swagger.v2.Modules DeletePet(petId, apiKey); } - public virtual List FindPetsByStatus(NancyContext context, FindPetsByStatusList<StatusEnum>? status) + public virtual List FindPetsByStatus(NancyContext context, FindPetsByStatusStatusEnum? status) { return FindPetsByStatus(status); } @@ -224,7 +230,7 @@ namespace IO.Swagger.v2.Modules protected abstract void DeletePet(long? petId, string apiKey); - protected abstract List FindPetsByStatus(FindPetsByStatusList<StatusEnum>? status); + protected abstract List FindPetsByStatus(FindPetsByStatusStatusEnum? status); protected abstract List FindPetsByTags(List tags);