Skip to content

Commit 8668175

Browse files
jimschubertwing328
authored andcommitted
[aspnetcore] Fix string enum generation (#7581)
* [aspnetcore] Fix enum strings generation regression * [aspnetcore] Regenerate sample
1 parent b184fb1 commit 8668175

File tree

8 files changed

+61
-50
lines changed

8 files changed

+61
-50
lines changed
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
12
/// <summary>
23
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
3-
/// </summary>{{#description}}
4-
/// <value>{{{description}}}</value>{{/description}}
4+
/// </summary>
5+
{{#description}}
6+
/// <value>{{{description}}}</value>
7+
{{/description}}
8+
{{#allowableValues}}{{#enumVars}}{{#-first}}{{#isString}}[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]{{/isString}}{{/-first}}{{/enumVars}}{{/allowableValues}}
59
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}
6-
{ {{#allowableValues}}{{#enumVars}}
10+
{
11+
{{#allowableValues}}{{#enumVars}}
712
/// <summary>
813
/// Enum {{name}} for {{{value}}}
914
/// </summary>
10-
[EnumMember(Value = {{#isLong}}"{{/isLong}}{{#isInteger}}"{{/isInteger}}{{#isFloat}}"{{/isFloat}}{{#isDouble}}"{{/isDouble}}{{{value}}}{{#isLong}}"{{/isLong}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isFloat}}"{{/isFloat}})]
11-
{{name}}{{#isLong}} = {{{value}}}{{/isLong}}{{#isInteger}} = {{{value}}}{{/isInteger}}{{^isInteger}} = {{-index}}{{/isInteger}}{{^-last}},
15+
{{#isString}}[EnumMember(Value = "{{{value}}}")]{{/isString}}
16+
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}} = {{-index}}{{/isString}}{{^-last}},
1217
{{/-last}}{{/enumVars}}{{/allowableValues}}
1318
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.0-SNAPSHOT
1+
2.4.0-SNAPSHOT

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public virtual IActionResult FindPetsByStatus([FromQuery][Required()]List<string
9292

9393
string exampleJson = null;
9494
exampleJson = "<Pet>\n <id>123456789</id>\n <name>doggie</name>\n <photoUrls>\n <photoUrls>aeiou</photoUrls>\n </photoUrls>\n <tags>\n </tags>\n <status>aeiou</status>\n</Pet>";
95-
exampleJson = "[ {\n \"tags\" : [ {\n \"id\" : 1,\n \"name\" : \"name\"\n }, {\n \"id\" : 1,\n \"name\" : \"name\"\n } ],\n \"id\" : 0,\n \"category\" : {\n \"id\" : 6,\n \"name\" : \"name\"\n },\n \"status\" : \"available\",\n \"name\" : \"doggie\",\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ]\n}, {\n \"tags\" : [ {\n \"id\" : 1,\n \"name\" : \"name\"\n }, {\n \"id\" : 1,\n \"name\" : \"name\"\n } ],\n \"id\" : 0,\n \"category\" : {\n \"id\" : 6,\n \"name\" : \"name\"\n },\n \"status\" : \"available\",\n \"name\" : \"doggie\",\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ]\n} ]";
95+
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} ]";
9696

9797
var example = exampleJson != null
9898
? JsonConvert.DeserializeObject<List<Pet>>(exampleJson)
@@ -123,7 +123,7 @@ public virtual IActionResult FindPetsByTags([FromQuery][Required()]List<string>
123123

124124
string exampleJson = null;
125125
exampleJson = "<Pet>\n <id>123456789</id>\n <name>doggie</name>\n <photoUrls>\n <photoUrls>aeiou</photoUrls>\n </photoUrls>\n <tags>\n </tags>\n <status>aeiou</status>\n</Pet>";
126-
exampleJson = "[ {\n \"tags\" : [ {\n \"id\" : 1,\n \"name\" : \"name\"\n }, {\n \"id\" : 1,\n \"name\" : \"name\"\n } ],\n \"id\" : 0,\n \"category\" : {\n \"id\" : 6,\n \"name\" : \"name\"\n },\n \"status\" : \"available\",\n \"name\" : \"doggie\",\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ]\n}, {\n \"tags\" : [ {\n \"id\" : 1,\n \"name\" : \"name\"\n }, {\n \"id\" : 1,\n \"name\" : \"name\"\n } ],\n \"id\" : 0,\n \"category\" : {\n \"id\" : 6,\n \"name\" : \"name\"\n },\n \"status\" : \"available\",\n \"name\" : \"doggie\",\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ]\n} ]";
126+
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} ]";
127127

128128
var example = exampleJson != null
129129
? JsonConvert.DeserializeObject<List<Pet>>(exampleJson)
@@ -158,7 +158,7 @@ public virtual IActionResult GetPetById([FromRoute][Required]long? petId)
158158

159159
string exampleJson = null;
160160
exampleJson = "<Pet>\n <id>123456789</id>\n <name>doggie</name>\n <photoUrls>\n <photoUrls>aeiou</photoUrls>\n </photoUrls>\n <tags>\n </tags>\n <status>aeiou</status>\n</Pet>";
161-
exampleJson = "{\n \"tags\" : [ {\n \"id\" : 1,\n \"name\" : \"name\"\n }, {\n \"id\" : 1,\n \"name\" : \"name\"\n } ],\n \"id\" : 0,\n \"category\" : {\n \"id\" : 6,\n \"name\" : \"name\"\n },\n \"status\" : \"available\",\n \"name\" : \"doggie\",\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ]\n}";
161+
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}";
162162

163163
var example = exampleJson != null
164164
? JsonConvert.DeserializeObject<Pet>(exampleJson)
@@ -234,7 +234,7 @@ public virtual IActionResult UploadFile([FromRoute][Required]long? petId, [FromF
234234
// return StatusCode(200, default(ApiResponse));
235235

236236
string exampleJson = null;
237-
exampleJson = "{\n \"message\" : \"message\",\n \"code\" : 0,\n \"type\" : \"type\"\n}";
237+
exampleJson = "{\n \"code\" : 0,\n \"type\" : \"type\",\n \"message\" : \"message\"\n}";
238238

239239
var example = exampleJson != null
240240
? JsonConvert.DeserializeObject<ApiResponse>(exampleJson)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public virtual IActionResult GetOrderById([FromRoute][Required][Range(1, 5)]long
105105

106106
string exampleJson = null;
107107
exampleJson = "<Order>\n <id>123456789</id>\n <petId>123456789</petId>\n <quantity>123</quantity>\n <shipDate>2000-01-23T04:56:07.000Z</shipDate>\n <status>aeiou</status>\n <complete>true</complete>\n</Order>";
108-
exampleJson = "{\n \"id\" : 0,\n \"petId\" : 6,\n \"complete\" : false,\n \"status\" : \"placed\",\n \"quantity\" : 1,\n \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\"\n}";
108+
exampleJson = "{\n \"petId\" : 6,\n \"quantity\" : 1,\n \"id\" : 0,\n \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\",\n \"complete\" : false,\n \"status\" : \"placed\"\n}";
109109

110110
var example = exampleJson != null
111111
? JsonConvert.DeserializeObject<Order>(exampleJson)
@@ -136,7 +136,7 @@ public virtual IActionResult PlaceOrder([FromBody]Order body)
136136

137137
string exampleJson = null;
138138
exampleJson = "<Order>\n <id>123456789</id>\n <petId>123456789</petId>\n <quantity>123</quantity>\n <shipDate>2000-01-23T04:56:07.000Z</shipDate>\n <status>aeiou</status>\n <complete>true</complete>\n</Order>";
139-
exampleJson = "{\n \"id\" : 0,\n \"petId\" : 6,\n \"complete\" : false,\n \"status\" : \"placed\",\n \"quantity\" : 1,\n \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\"\n}";
139+
exampleJson = "{\n \"petId\" : 6,\n \"quantity\" : 1,\n \"id\" : 0,\n \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\",\n \"complete\" : false,\n \"status\" : \"placed\"\n}";
140140

141141
var example = exampleJson != null
142142
? JsonConvert.DeserializeObject<Order>(exampleJson)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public virtual IActionResult GetUserByName([FromRoute][Required]string username)
137137

138138
string exampleJson = null;
139139
exampleJson = "<User>\n <id>123456789</id>\n <username>aeiou</username>\n <firstName>aeiou</firstName>\n <lastName>aeiou</lastName>\n <email>aeiou</email>\n <password>aeiou</password>\n <phone>aeiou</phone>\n <userStatus>123</userStatus>\n</User>";
140-
exampleJson = "{\n \"id\" : 0,\n \"lastName\" : \"lastName\",\n \"phone\" : \"phone\",\n \"username\" : \"username\",\n \"email\" : \"email\",\n \"userStatus\" : 6,\n \"firstName\" : \"firstName\",\n \"password\" : \"password\"\n}";
140+
exampleJson = "{\n \"firstName\" : \"firstName\",\n \"lastName\" : \"lastName\",\n \"password\" : \"password\",\n \"userStatus\" : 6,\n \"phone\" : \"phone\",\n \"id\" : 0,\n \"email\" : \"email\",\n \"username\" : \"username\"\n}";
141141

142142
var example = exampleJson != null
143143
? JsonConvert.DeserializeObject<User>(exampleJson)

samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Order.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,29 @@ public partial class Order : IEquatable<Order>
5050
/// </summary>
5151
[DataMember(Name="shipDate")]
5252
public DateTime? ShipDate { get; set; }
53+
5354
/// <summary>
5455
/// Order Status
5556
/// </summary>
5657
/// <value>Order Status</value>
58+
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
5759
public enum StatusEnum
58-
{
60+
{
61+
5962
/// <summary>
60-
/// Enum PlacedEnum for "placed"
63+
/// Enum PlacedEnum for placed
6164
/// </summary>
6265
[EnumMember(Value = "placed")]
6366
PlacedEnum = 1,
6467

6568
/// <summary>
66-
/// Enum ApprovedEnum for "approved"
69+
/// Enum ApprovedEnum for approved
6770
/// </summary>
6871
[EnumMember(Value = "approved")]
6972
ApprovedEnum = 2,
7073

7174
/// <summary>
72-
/// Enum DeliveredEnum for "delivered"
75+
/// Enum DeliveredEnum for delivered
7376
/// </summary>
7477
[EnumMember(Value = "delivered")]
7578
DeliveredEnum = 3

samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Pet.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,29 @@ public partial class Pet : IEquatable<Pet>
5858
/// </summary>
5959
[DataMember(Name="tags")]
6060
public List<Tag> Tags { get; set; }
61+
6162
/// <summary>
6263
/// pet status in the store
6364
/// </summary>
6465
/// <value>pet status in the store</value>
66+
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
6567
public enum StatusEnum
66-
{
68+
{
69+
6770
/// <summary>
68-
/// Enum AvailableEnum for "available"
71+
/// Enum AvailableEnum for available
6972
/// </summary>
7073
[EnumMember(Value = "available")]
7174
AvailableEnum = 1,
7275

7376
/// <summary>
74-
/// Enum PendingEnum for "pending"
77+
/// Enum PendingEnum for pending
7578
/// </summary>
7679
[EnumMember(Value = "pending")]
7780
PendingEnum = 2,
7881

7982
/// <summary>
80-
/// Enum SoldEnum for "sold"
83+
/// Enum SoldEnum for sold
8184
/// </summary>
8285
[EnumMember(Value = "sold")]
8386
SoldEnum = 3

samples/server/petstore/aspnetcore/src/IO.Swagger/wwwroot/swagger-original.json

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@
108108
"type" : "array",
109109
"items" : {
110110
"type" : "string",
111-
"enum" : [ "available", "pending", "sold" ],
112-
"default" : "available"
111+
"default" : "available",
112+
"enum" : [ "available", "pending", "sold" ]
113113
},
114114
"collectionFormat" : "csv"
115115
} ],
@@ -685,12 +685,12 @@
685685
"title" : "Pet Order",
686686
"description" : "An order for a pets from the pet store",
687687
"example" : {
688-
"id" : 0,
689688
"petId" : 6,
690-
"complete" : false,
691-
"status" : "placed",
692689
"quantity" : 1,
693-
"shipDate" : "2000-01-23T04:56:07.000+00:00"
690+
"id" : 0,
691+
"shipDate" : "2000-01-23T04:56:07.000+00:00",
692+
"complete" : false,
693+
"status" : "placed"
694694
},
695695
"xml" : {
696696
"name" : "Order"
@@ -710,8 +710,8 @@
710710
"title" : "Pet category",
711711
"description" : "A category for a pet",
712712
"example" : {
713-
"id" : 6,
714-
"name" : "name"
713+
"name" : "name",
714+
"id" : 6
715715
},
716716
"xml" : {
717717
"name" : "Category"
@@ -751,14 +751,14 @@
751751
"title" : "a User",
752752
"description" : "A User who is purchasing from the pet store",
753753
"example" : {
754-
"id" : 0,
754+
"firstName" : "firstName",
755755
"lastName" : "lastName",
756+
"password" : "password",
757+
"userStatus" : 6,
756758
"phone" : "phone",
757-
"username" : "username",
759+
"id" : 0,
758760
"email" : "email",
759-
"userStatus" : 6,
760-
"firstName" : "firstName",
761-
"password" : "password"
761+
"username" : "username"
762762
},
763763
"xml" : {
764764
"name" : "User"
@@ -778,8 +778,8 @@
778778
"title" : "Pet Tag",
779779
"description" : "A tag for a pet",
780780
"example" : {
781-
"id" : 1,
782-
"name" : "name"
781+
"name" : "name",
782+
"id" : 1
783783
},
784784
"xml" : {
785785
"name" : "Tag"
@@ -829,21 +829,21 @@
829829
"title" : "a Pet",
830830
"description" : "A pet for sale in the pet store",
831831
"example" : {
832-
"tags" : [ {
833-
"id" : 1,
834-
"name" : "name"
835-
}, {
836-
"id" : 1,
837-
"name" : "name"
838-
} ],
832+
"photoUrls" : [ "photoUrls", "photoUrls" ],
833+
"name" : "doggie",
839834
"id" : 0,
840835
"category" : {
841-
"id" : 6,
842-
"name" : "name"
836+
"name" : "name",
837+
"id" : 6
843838
},
844-
"status" : "available",
845-
"name" : "doggie",
846-
"photoUrls" : [ "photoUrls", "photoUrls" ]
839+
"tags" : [ {
840+
"name" : "name",
841+
"id" : 1
842+
}, {
843+
"name" : "name",
844+
"id" : 1
845+
} ],
846+
"status" : "available"
847847
},
848848
"xml" : {
849849
"name" : "Pet"
@@ -866,9 +866,9 @@
866866
"title" : "An uploaded response",
867867
"description" : "Describes the result of uploading an image resource",
868868
"example" : {
869-
"message" : "message",
870869
"code" : 0,
871-
"type" : "type"
870+
"type" : "type",
871+
"message" : "message"
872872
}
873873
}
874874
},

0 commit comments

Comments
 (0)