Skip to content

Commit cad47fb

Browse files
authored
Add descriptions for more HTTP status codes (#2872)
Add descriptions for more HTTP status codes.
1 parent ae3078f commit cad47fb

File tree

6 files changed

+55
-14
lines changed

6 files changed

+55
-14
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ Will produce the following response metadata:
394394
```
395395
responses: {
396396
200: {
397-
description: "Success",
397+
description: "OK",
398398
content: {
399399
"application/json": {
400400
schema: {
@@ -423,7 +423,7 @@ Will produce the following response metadata:
423423
```
424424
responses: {
425425
200: {
426-
description: "Success",
426+
description: "OK",
427427
content: {
428428
"application/json": {
429429
schema: {
@@ -446,7 +446,7 @@ responses: {
446446
}
447447
},
448448
500: {
449-
description: "Server Error",
449+
description: "Internal Server Error",
450450
content: {}
451451
}
452452
}
@@ -788,7 +788,7 @@ If the generator encounters complex parameter or response types, it will generat
788788
```
789789
responses: {
790790
200: {
791-
description: "Success",
791+
description: "OK",
792792
content: {
793793
"application/json": {
794794
schema: {

src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,31 +667,64 @@ private static bool IsFromFormAttributeUsedWithIFormFile(ApiParameterDescription
667667

668668
private static readonly IReadOnlyCollection<KeyValuePair<string, string>> ResponseDescriptionMap = new[]
669669
{
670-
new KeyValuePair<string, string>("1\\d{2}", "Information"),
670+
new KeyValuePair<string, string>("100", "Continue"),
671+
new KeyValuePair<string, string>("101", "Switching Protocols"),
672+
new KeyValuePair<string, string>("1\\d{2}", "Information"),
671673

674+
new KeyValuePair<string, string>("200", "OK"),
672675
new KeyValuePair<string, string>("201", "Created"),
673676
new KeyValuePair<string, string>("202", "Accepted"),
677+
new KeyValuePair<string, string>("203", "Non-Authoritative Information"),
674678
new KeyValuePair<string, string>("204", "No Content"),
679+
new KeyValuePair<string, string>("205", "Reset Content"),
680+
new KeyValuePair<string, string>("206", "Partial Content"),
675681
new KeyValuePair<string, string>("2\\d{2}", "Success"),
676682

683+
new KeyValuePair<string, string>("300", "Multiple Choices"),
684+
new KeyValuePair<string, string>("301", "Moved Permanently"),
685+
new KeyValuePair<string, string>("302", "Found"),
686+
new KeyValuePair<string, string>("303", "See Other"),
677687
new KeyValuePair<string, string>("304", "Not Modified"),
688+
new KeyValuePair<string, string>("305", "Use Proxy"),
689+
new KeyValuePair<string, string>("307", "Temporary Redirect"),
690+
new KeyValuePair<string, string>("308", "Permanent Redirect"),
678691
new KeyValuePair<string, string>("3\\d{2}", "Redirect"),
679692

680693
new KeyValuePair<string, string>("400", "Bad Request"),
681694
new KeyValuePair<string, string>("401", "Unauthorized"),
695+
new KeyValuePair<string, string>("402", "Payment Required"),
682696
new KeyValuePair<string, string>("403", "Forbidden"),
683697
new KeyValuePair<string, string>("404", "Not Found"),
684698
new KeyValuePair<string, string>("405", "Method Not Allowed"),
685699
new KeyValuePair<string, string>("406", "Not Acceptable"),
700+
new KeyValuePair<string, string>("407", "Proxy Authentication Required"),
686701
new KeyValuePair<string, string>("408", "Request Timeout"),
687702
new KeyValuePair<string, string>("409", "Conflict"),
703+
new KeyValuePair<string, string>("410", "Gone"),
704+
new KeyValuePair<string, string>("411", "Length Required"),
705+
new KeyValuePair<string, string>("412", "Precondition Failed"),
706+
new KeyValuePair<string, string>("413", "Content Too Large"),
707+
new KeyValuePair<string, string>("414", "URI Too Long"),
708+
new KeyValuePair<string, string>("415", "Unsupported Media Type"),
709+
new KeyValuePair<string, string>("416", "Range Not Satisfiable"),
710+
new KeyValuePair<string, string>("417", "Expectation Failed"),
711+
new KeyValuePair<string, string>("421", "Misdirected Request"),
712+
new KeyValuePair<string, string>("422", "Unprocessable Content"),
713+
new KeyValuePair<string, string>("423", "Locked"),
714+
new KeyValuePair<string, string>("424", "Failed Dependency"),
715+
new KeyValuePair<string, string>("426", "Upgrade Required"),
716+
new KeyValuePair<string, string>("428", "Precondition Required"),
688717
new KeyValuePair<string, string>("429", "Too Many Requests"),
718+
new KeyValuePair<string, string>("431", "Request Header Fields Too Large"),
719+
new KeyValuePair<string, string>("451", "Unavailable For Legal Reasons"),
689720
new KeyValuePair<string, string>("4\\d{2}", "Client Error"),
690721

722+
new KeyValuePair<string, string>("500", "Internal Server Error"),
691723
new KeyValuePair<string, string>("501", "Not Implemented"),
692724
new KeyValuePair<string, string>("502", "Bad Gateway"),
693725
new KeyValuePair<string, string>("503", "Service Unavailable"),
694726
new KeyValuePair<string, string>("504", "Gateway Timeout"),
727+
new KeyValuePair<string, string>("505", "HTTP Version Not Supported"),
695728
new KeyValuePair<string, string>("5\\d{2}", "Server Error"),
696729

697730
new KeyValuePair<string, string>("default", "Error")

test/Swashbuckle.AspNetCore.SwaggerGen.Test/SwaggerGenerator/SwaggerGeneratorTests.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Reflection;
45
using System.Text.Json;
56
using System.Threading.Tasks;
6-
using System.Reflection;
77
using Microsoft.AspNetCore.Authentication;
88
using Microsoft.AspNetCore.Http;
99
using Microsoft.AspNetCore.Mvc;
@@ -943,6 +943,11 @@ public void GetSwagger_GeneratesResponses_ForSupportedResponseTypes()
943943
StatusCode = 400
944944
},
945945
new ApiResponseType
946+
{
947+
ApiResponseFormats = new [] { new ApiResponseFormat { MediaType = "application/json" } },
948+
StatusCode = 422
949+
},
950+
new ApiResponseType
946951
{
947952
ApiResponseFormats = new [] { new ApiResponseFormat { MediaType = "application/json" } },
948953
IsDefaultResponse = true
@@ -956,13 +961,16 @@ public void GetSwagger_GeneratesResponses_ForSupportedResponseTypes()
956961
var document = subject.GetSwagger("v1");
957962

958963
var operation = document.Paths["/resource"].Operations[OperationType.Post];
959-
Assert.Equal(new[] { "200", "400", "default" }, operation.Responses.Keys);
964+
Assert.Equal(new[] { "200", "400", "422", "default" }, operation.Responses.Keys);
960965
var response200 = operation.Responses["200"];
961-
Assert.Equal("Success", response200.Description);
966+
Assert.Equal("OK", response200.Description);
962967
Assert.Equal(new[] { "application/json" }, response200.Content.Keys);
963968
var response400 = operation.Responses["400"];
964969
Assert.Equal("Bad Request", response400.Description);
965970
Assert.Empty(response400.Content.Keys);
971+
var response422 = operation.Responses["422"];
972+
Assert.Equal("Unprocessable Content", response422.Description);
973+
Assert.Empty(response422.Content.Keys);
966974
var responseDefault = operation.Responses["default"];
967975
Assert.Equal("Error", responseDefault.Description);
968976
Assert.Empty(responseDefault.Content.Keys);

test/WebSites/CliExample/wwwroot/swagger/v1/swagger.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"responses": {
1919
"200": {
20-
"description": "Success",
20+
"description": "OK",
2121
"content": {
2222
"application/json": {
2323
"schema": {
@@ -51,4 +51,4 @@
5151
}
5252
}
5353
}
54-
}
54+
}

test/WebSites/CliExampleWithFactory/wwwroot/swagger/v1/swagger.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"responses": {
1919
"200": {
20-
"description": "Success",
20+
"description": "OK",
2121
"content": {
2222
"application/json": {
2323
"schema": {
@@ -51,4 +51,4 @@
5151
}
5252
}
5353
}
54-
}
54+
}

test/WebSites/NswagClientExample/swagger.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
},
6868
"responses": {
6969
"200": {
70-
"description": "Success"
70+
"description": "OK"
7171
}
7272
}
7373
}
@@ -137,4 +137,4 @@
137137
}
138138
}
139139
}
140-
}
140+
}

0 commit comments

Comments
 (0)