From 6746632834dad01834829a28b2a6e2ac535b8168 Mon Sep 17 00:00:00 2001 From: jsone-studios Date: Mon, 20 Feb 2017 09:18:09 +0100 Subject: [PATCH] Fix for #1940 - Show response headers (#4825) --- .../io/swagger/codegen/CodegenResponse.java | 1 + .../io/swagger/codegen/DefaultCodegen.java | 1 + .../main/resources/htmlDocs2/index.mustache | 63 ++- .../resources/2_0/responseHeaderTest.yaml | 41 ++ samples/html2/index.html | 405 +++++++++++++----- 5 files changed, 381 insertions(+), 130 deletions(-) create mode 100644 modules/swagger-codegen/src/test/resources/2_0/responseHeaderTest.yaml diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java index ec0f7f11bb57..b2a734fc9b27 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java @@ -10,6 +10,7 @@ public class CodegenResponse { public boolean hasMore; public List> examples; public String dataType, baseType, containerType; + public boolean hasHeaders; public boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBoolean, isDate, isDateTime; public boolean isDefault; public boolean simpleType; diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index d264523e08c3..586a95fefb4a 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -2231,6 +2231,7 @@ public class DefaultCodegen { r.jsonSchema = Json.pretty(response); r.vendorExtensions = response.getVendorExtensions(); addHeaders(response, r.headers); + r.hasHeaders = !r.headers.isEmpty(); if (r.schema != null) { Property responseProperty = response.getSchema(); diff --git a/modules/swagger-codegen/src/main/resources/htmlDocs2/index.mustache b/modules/swagger-codegen/src/main/resources/htmlDocs2/index.mustache index 01f9f2eb720e..fc0f5f382046 100644 --- a/modules/swagger-codegen/src/main/resources/htmlDocs2/index.mustache +++ b/modules/swagger-codegen/src/main/resources/htmlDocs2/index.mustache @@ -336,24 +336,30 @@ {{#responses}}

Status: {{code}} - {{message}}

- {{#schema}} - -
-
-
- -
- +
{{#examples}} -
-
{{example}}
-
+
+
{{example}}
+
{{/examples}} -
- {{/schema}} + {{/schema}} + {{#hasHeaders}} +
+ + + + + + + + {{#headers}} + + + + + + + {{/headers}} +
NameTypeFormatDescription
{{#name}}{{name}}{{/name}}{{#datatype}}{{datatype}}{{/datatype}}{{#dataFormat}}{{dataFormat}}{{/dataFormat}}{{#description}}{{description}}{{/description}}
+
+ {{/hasHeaders}} + + {{/responses}} diff --git a/modules/swagger-codegen/src/test/resources/2_0/responseHeaderTest.yaml b/modules/swagger-codegen/src/test/resources/2_0/responseHeaderTest.yaml new file mode 100644 index 000000000000..7c868bdabacb --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/2_0/responseHeaderTest.yaml @@ -0,0 +1,41 @@ +swagger: '2.0' +info: + description: 'Test for displaying response headers' + version: 1.0.0 + title: Response header test + license: + name: Apache 2.0 + url: 'http://www.apache.org/licenses/LICENSE-2.0.html' +basePath: / +schemes: + - http +paths: + /test: + get: + summary: Test + description: Test + produces: + - application/json + responses: + '200': + description: successful operation + schema: + type: array + items: + type: string + headers: + X-STATUS: + type: "integer" + description: "Output status of the operation" + '500': + description: "Internal server error" + headers: + X-MSG-ID: + type: "string" + format: ".*" + description: "I am the error description" + X-ERROR-ID: + type: "integer" + description: "I am the error code" + '400': + description: Invalid ID supplied \ No newline at end of file diff --git a/samples/html2/index.html b/samples/html2/index.html index bec62b55586b..92fccb3f6516 100644 --- a/samples/html2/index.html +++ b/samples/html2/index.html @@ -1266,6 +1266,12 @@ except ApiException as e:

Responses

Status: 405 - Invalid input

+ + +
+
+
@@ -1555,7 +1561,7 @@ except ApiException as e: Name Description - apiKey + api_key @@ -1595,6 +1601,12 @@ except ApiException as e:

Responses

Status: 400 - Invalid pet value

+ + +
+
+
@@ -1858,8 +1870,8 @@ except ApiException as e: "type" : "array", "items" : { "type" : "string", - "enum" : [ "available", "pending", "sold" ], - "default" : "available" + "default" : "available", + "enum" : [ "available", "pending", "sold" ] }, "collectionFormat" : "csv" }; @@ -1888,18 +1900,17 @@ except ApiException as e:

Responses

Status: 200 - successful operation

- -
-
-
- -
- +
-
+ +

Status: 400 - Invalid status value

+ + +
+
+
@@ -2224,18 +2242,17 @@ except ApiException as e:

Responses

Status: 200 - successful operation

- -
-
-
- -
- +
-
+ +

Status: 400 - Invalid tag value

+ + +
+
+
@@ -2571,18 +2595,17 @@ except ApiException as e:

Responses

Status: 200 - successful operation

- -
-
-
- -
- +
-
+ +

Status: 400 - Invalid ID supplied

+ + +
+
+

Status: 404 - Pet not found

+ + +
+
+
@@ -2904,10 +2940,28 @@ except ApiException as e:

Responses

Status: 400 - Invalid ID supplied

+ + +
+
+

Status: 404 - Pet not found

+ + +
+
+

Status: 405 - Validation exception

+ + +
+
+
@@ -3280,6 +3334,12 @@ except ApiException as e:

Responses

Status: 405 - Invalid input

+ + +
+
+
@@ -3661,18 +3721,17 @@ except ApiException as e:

Responses

Status: 200 - successful operation

- -
-
-
- -
- +
-
+ +
@@ -3955,8 +4015,20 @@ except ApiException as e:

Responses

Status: 400 - Invalid ID supplied

+ + +
+
+

Status: 404 - Order not found

+ + +
+
+
@@ -4208,18 +4280,17 @@ except ApiException as e:

Responses

Status: 200 - successful operation

- -
-
-
- -
- +
-
+ +
@@ -4515,18 +4587,17 @@ except ApiException as e:

Responses

Status: 200 - successful operation

- -
-
-
- -
- +
-
+ +

Status: 400 - Invalid ID supplied

+ + +
+
+

Status: 404 - Order not found

+ + +
+
+
@@ -4830,18 +4914,17 @@ except ApiException as e:

Responses

Status: 200 - successful operation

- -
-
-
- -
- +
-
+ +

Status: 400 - Invalid Order

+ + +
+
+
@@ -5137,6 +5227,12 @@ except ApiException as e:

Responses

Status: 0 - successful operation

+ + +
+
+
@@ -5402,6 +5498,12 @@ except ApiException as e:

Responses

Status: 0 - successful operation

+ + +
+
+
@@ -5667,6 +5769,12 @@ except ApiException as e:

Responses

Status: 0 - successful operation

+ + +
+
+
@@ -5918,8 +6026,20 @@ except ApiException as e:

Responses

Status: 400 - Invalid username supplied

+ + +
+
+

Status: 404 - User not found

+ + +
+
+
@@ -6180,18 +6300,17 @@ except ApiException as e:

Responses

Status: 200 - successful operation

- -
-
-
- -
- +
-
+ +

Status: 400 - Invalid username supplied

+ + +
+
+

Status: 404 - User not found

+ + +
+
+
@@ -6527,18 +6659,20 @@ except ApiException as e:

Responses

Status: 200 - successful operation

- -
-
-
- -
- +
-
+
+ + + + + + + + + + + + + + + + + + + +
NameTypeFormatDescription
X-Rate-LimitIntegerint32calls per hour allowed by the user
X-Expires-AfterDatedate-timedate in UTC when toekn expires
+
+ +

Status: 400 - Invalid username/password supplied

+ + +
+
+
@@ -6782,6 +6945,12 @@ except ApiException as e:

Responses

Status: 0 - successful operation

+ + +
+
+
@@ -7094,8 +7263,20 @@ except ApiException as e:

Responses

Status: 400 - Invalid user supplied

+ + +
+
+

Status: 404 - User not found

+ + +
+
+
@@ -7112,7 +7293,7 @@ except ApiException as e:
- Generated 2017-01-24T11:58:21.560-05:00 + Generated 2017-02-18T23:37:57.057+01:00