From 61109072e96d5fa606e2be12be27813e9b3be052 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Fri, 15 Nov 2024 21:48:06 +0100 Subject: [PATCH 1/4] Add more HTTP codes to `ResponseDescriptionMap` --- .../SwaggerGenerator/SwaggerGenerator.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs index 610479e7b8..313a749dc5 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -998,6 +998,8 @@ private static bool IsFromFormAttributeUsedWithIFormFile(ApiParameterDescription [ new KeyValuePair("100", "Continue"), new KeyValuePair("101", "Switching Protocols"), + new KeyValuePair("102", "Processing"), + new KeyValuePair("103", "Early Hints"), new KeyValuePair("1\\d{2}", "Information"), new KeyValuePair("200", "OK"), @@ -1007,6 +1009,9 @@ private static bool IsFromFormAttributeUsedWithIFormFile(ApiParameterDescription new KeyValuePair("204", "No Content"), new KeyValuePair("205", "Reset Content"), new KeyValuePair("206", "Partial Content"), + new KeyValuePair("207", "Multi-Status "), + new KeyValuePair("208", "Already Reported"), + new KeyValuePair("226", "IM Used"), new KeyValuePair("2\\d{2}", "Success"), new KeyValuePair("300", "Multiple Choices"), @@ -1037,10 +1042,12 @@ private static bool IsFromFormAttributeUsedWithIFormFile(ApiParameterDescription new KeyValuePair("415", "Unsupported Media Type"), new KeyValuePair("416", "Range Not Satisfiable"), new KeyValuePair("417", "Expectation Failed"), + new KeyValuePair("418", "I'm a teapot"), new KeyValuePair("421", "Misdirected Request"), new KeyValuePair("422", "Unprocessable Content"), new KeyValuePair("423", "Locked"), new KeyValuePair("424", "Failed Dependency"), + new KeyValuePair("425", "Too Early"), new KeyValuePair("426", "Upgrade Required"), new KeyValuePair("428", "Precondition Required"), new KeyValuePair("429", "Too Many Requests"), @@ -1054,6 +1061,11 @@ private static bool IsFromFormAttributeUsedWithIFormFile(ApiParameterDescription new KeyValuePair("503", "Service Unavailable"), new KeyValuePair("504", "Gateway Timeout"), new KeyValuePair("505", "HTTP Version Not Supported"), + new KeyValuePair("506", "Variant Also Negotiates"), + new KeyValuePair("507", "Insufficient Storage"), + new KeyValuePair("508", "Loop Detected "), + new KeyValuePair("510", "Not Extended"), + new KeyValuePair("511", "Network Authentication Required"), new KeyValuePair("5\\d{2}", "Server Error"), new KeyValuePair("default", "Error") From f2163992b13fc4ce5cb37cb9264ac5f0c17280dc Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 16 Nov 2024 11:06:47 +0100 Subject: [PATCH 2/4] Add comments --- .../SwaggerGenerator/SwaggerGenerator.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs index 313a749dc5..67c686ad85 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs @@ -996,12 +996,14 @@ private static bool IsFromFormAttributeUsedWithIFormFile(ApiParameterDescription private static readonly IReadOnlyCollection> ResponseDescriptionMap = [ + // Informational responses new KeyValuePair("100", "Continue"), new KeyValuePair("101", "Switching Protocols"), new KeyValuePair("102", "Processing"), new KeyValuePair("103", "Early Hints"), new KeyValuePair("1\\d{2}", "Information"), + // Successful responses new KeyValuePair("200", "OK"), new KeyValuePair("201", "Created"), new KeyValuePair("202", "Accepted"), @@ -1014,6 +1016,7 @@ private static bool IsFromFormAttributeUsedWithIFormFile(ApiParameterDescription new KeyValuePair("226", "IM Used"), new KeyValuePair("2\\d{2}", "Success"), + // Redirection messages new KeyValuePair("300", "Multiple Choices"), new KeyValuePair("301", "Moved Permanently"), new KeyValuePair("302", "Found"), @@ -1024,6 +1027,7 @@ private static bool IsFromFormAttributeUsedWithIFormFile(ApiParameterDescription new KeyValuePair("308", "Permanent Redirect"), new KeyValuePair("3\\d{2}", "Redirect"), + // Client error responses new KeyValuePair("400", "Bad Request"), new KeyValuePair("401", "Unauthorized"), new KeyValuePair("402", "Payment Required"), @@ -1055,6 +1059,7 @@ private static bool IsFromFormAttributeUsedWithIFormFile(ApiParameterDescription new KeyValuePair("451", "Unavailable For Legal Reasons"), new KeyValuePair("4\\d{2}", "Client Error"), + // Server error responses new KeyValuePair("500", "Internal Server Error"), new KeyValuePair("501", "Not Implemented"), new KeyValuePair("502", "Bad Gateway"), From feca9de4f74cd1431e209a0029d83dd17eef4844 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 16 Nov 2024 11:07:20 +0100 Subject: [PATCH 3/4] Use target-typed new --- .../SwaggerGenerator/SwaggerGenerator.cs | 138 +++++++++--------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs index 67c686ad85..06ac139bba 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs @@ -997,83 +997,83 @@ private static bool IsFromFormAttributeUsedWithIFormFile(ApiParameterDescription private static readonly IReadOnlyCollection> ResponseDescriptionMap = [ // Informational responses - new KeyValuePair("100", "Continue"), - new KeyValuePair("101", "Switching Protocols"), - new KeyValuePair("102", "Processing"), - new KeyValuePair("103", "Early Hints"), - new KeyValuePair("1\\d{2}", "Information"), + new("100", "Continue"), + new("101", "Switching Protocols"), + new("102", "Processing"), + new("103", "Early Hints"), + new("1\\d{2}", "Information"), // Successful responses - new KeyValuePair("200", "OK"), - new KeyValuePair("201", "Created"), - new KeyValuePair("202", "Accepted"), - new KeyValuePair("203", "Non-Authoritative Information"), - new KeyValuePair("204", "No Content"), - new KeyValuePair("205", "Reset Content"), - new KeyValuePair("206", "Partial Content"), - new KeyValuePair("207", "Multi-Status "), - new KeyValuePair("208", "Already Reported"), - new KeyValuePair("226", "IM Used"), - new KeyValuePair("2\\d{2}", "Success"), + new("200", "OK"), + new("201", "Created"), + new("202", "Accepted"), + new("203", "Non-Authoritative Information"), + new("204", "No Content"), + new("205", "Reset Content"), + new("206", "Partial Content"), + new("207", "Multi-Status "), + new("208", "Already Reported"), + new("226", "IM Used"), + new("2\\d{2}", "Success"), // Redirection messages - new KeyValuePair("300", "Multiple Choices"), - new KeyValuePair("301", "Moved Permanently"), - new KeyValuePair("302", "Found"), - new KeyValuePair("303", "See Other"), - new KeyValuePair("304", "Not Modified"), - new KeyValuePair("305", "Use Proxy"), - new KeyValuePair("307", "Temporary Redirect"), - new KeyValuePair("308", "Permanent Redirect"), - new KeyValuePair("3\\d{2}", "Redirect"), + new("300", "Multiple Choices"), + new("301", "Moved Permanently"), + new("302", "Found"), + new("303", "See Other"), + new("304", "Not Modified"), + new("305", "Use Proxy"), + new("307", "Temporary Redirect"), + new("308", "Permanent Redirect"), + new("3\\d{2}", "Redirect"), // Client error responses - new KeyValuePair("400", "Bad Request"), - new KeyValuePair("401", "Unauthorized"), - new KeyValuePair("402", "Payment Required"), - new KeyValuePair("403", "Forbidden"), - new KeyValuePair("404", "Not Found"), - new KeyValuePair("405", "Method Not Allowed"), - new KeyValuePair("406", "Not Acceptable"), - new KeyValuePair("407", "Proxy Authentication Required"), - new KeyValuePair("408", "Request Timeout"), - new KeyValuePair("409", "Conflict"), - new KeyValuePair("410", "Gone"), - new KeyValuePair("411", "Length Required"), - new KeyValuePair("412", "Precondition Failed"), - new KeyValuePair("413", "Content Too Large"), - new KeyValuePair("414", "URI Too Long"), - new KeyValuePair("415", "Unsupported Media Type"), - new KeyValuePair("416", "Range Not Satisfiable"), - new KeyValuePair("417", "Expectation Failed"), - new KeyValuePair("418", "I'm a teapot"), - new KeyValuePair("421", "Misdirected Request"), - new KeyValuePair("422", "Unprocessable Content"), - new KeyValuePair("423", "Locked"), - new KeyValuePair("424", "Failed Dependency"), - new KeyValuePair("425", "Too Early"), - new KeyValuePair("426", "Upgrade Required"), - new KeyValuePair("428", "Precondition Required"), - new KeyValuePair("429", "Too Many Requests"), - new KeyValuePair("431", "Request Header Fields Too Large"), - new KeyValuePair("451", "Unavailable For Legal Reasons"), - new KeyValuePair("4\\d{2}", "Client Error"), + new("400", "Bad Request"), + new("401", "Unauthorized"), + new("402", "Payment Required"), + new("403", "Forbidden"), + new("404", "Not Found"), + new("405", "Method Not Allowed"), + new("406", "Not Acceptable"), + new("407", "Proxy Authentication Required"), + new("408", "Request Timeout"), + new("409", "Conflict"), + new("410", "Gone"), + new("411", "Length Required"), + new("412", "Precondition Failed"), + new("413", "Content Too Large"), + new("414", "URI Too Long"), + new("415", "Unsupported Media Type"), + new("416", "Range Not Satisfiable"), + new("417", "Expectation Failed"), + new("418", "I'm a teapot"), + new("421", "Misdirected Request"), + new("422", "Unprocessable Content"), + new("423", "Locked"), + new("424", "Failed Dependency"), + new("425", "Too Early"), + new("426", "Upgrade Required"), + new("428", "Precondition Required"), + new("429", "Too Many Requests"), + new("431", "Request Header Fields Too Large"), + new("451", "Unavailable For Legal Reasons"), + new("4\\d{2}", "Client Error"), // Server error responses - new KeyValuePair("500", "Internal Server Error"), - new KeyValuePair("501", "Not Implemented"), - new KeyValuePair("502", "Bad Gateway"), - new KeyValuePair("503", "Service Unavailable"), - new KeyValuePair("504", "Gateway Timeout"), - new KeyValuePair("505", "HTTP Version Not Supported"), - new KeyValuePair("506", "Variant Also Negotiates"), - new KeyValuePair("507", "Insufficient Storage"), - new KeyValuePair("508", "Loop Detected "), - new KeyValuePair("510", "Not Extended"), - new KeyValuePair("511", "Network Authentication Required"), - new KeyValuePair("5\\d{2}", "Server Error"), - - new KeyValuePair("default", "Error") + new("500", "Internal Server Error"), + new("501", "Not Implemented"), + new("502", "Bad Gateway"), + new("503", "Service Unavailable"), + new("504", "Gateway Timeout"), + new("505", "HTTP Version Not Supported"), + new("506", "Variant Also Negotiates"), + new("507", "Insufficient Storage"), + new("508", "Loop Detected "), + new("510", "Not Extended"), + new("511", "Network Authentication Required"), + new("5\\d{2}", "Server Error"), + + new("default", "Error") ]; #if NET7_0_OR_GREATER From 61d8b1ab9018e88200588799ac8482d7da19c765 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sun, 17 Nov 2024 15:11:36 +0100 Subject: [PATCH 4/4] Delete extra spaces --- .../SwaggerGenerator/SwaggerGenerator.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs index 06ac139bba..08587282dd 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs @@ -1011,7 +1011,7 @@ private static bool IsFromFormAttributeUsedWithIFormFile(ApiParameterDescription new("204", "No Content"), new("205", "Reset Content"), new("206", "Partial Content"), - new("207", "Multi-Status "), + new("207", "Multi-Status"), new("208", "Already Reported"), new("226", "IM Used"), new("2\\d{2}", "Success"), @@ -1068,7 +1068,7 @@ private static bool IsFromFormAttributeUsedWithIFormFile(ApiParameterDescription new("505", "HTTP Version Not Supported"), new("506", "Variant Also Negotiates"), new("507", "Insufficient Storage"), - new("508", "Loop Detected "), + new("508", "Loop Detected"), new("510", "Not Extended"), new("511", "Network Authentication Required"), new("5\\d{2}", "Server Error"),