Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class CodegenResponse {
public boolean hasMore;
public List<Map<String, Object>> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2231,6 +2231,7 @@ public CodegenResponse fromResponse(String responseCode, Response response) {
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();
Expand Down
65 changes: 46 additions & 19 deletions modules/swagger-codegen/src/main/resources/htmlDocs2/index.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -336,24 +336,30 @@
{{#responses}}
<h3> Status: {{code}} - {{message}} </h3>

{{#schema}}
<ul class="nav nav-tabs nav-tabs-examples" >
<ul class="nav nav-tabs nav-tabs-examples" >
{{#schema}}
<li class="active">
<a href="#examples-{{baseName}}-{{nickname}}-schema">Schema</a>
<a data-toggle="tab" href="#responses-{{nickname}}-{{code}}-schema">Schema</a>
</li>

{{#examples}}
<li class="">
<a href="#examples-{{baseName}}-{{nickname}}-example">Response Example</a>
<a data-toggle="tab" href="#responses-{{nickname}}-{{code}}-example">Response Example</a>
</li>
{{/examples}}
</ul>

<div class="tab-content" style='margin-bottom: 10px;'>
<div class="tab-pane active" id="examples-{{baseName}}-{{nickname}}-schema">
<div id='examples-{{baseName}}-{{nickname}}-schema-{{code}}' style="padding: 30px; border-left: 1px solid #eee; border-right: 1px solid #eee; border-bottom: 1px solid #eee;">

<script>
{{/schema}}
{{#hasHeaders}}
<li class="">
<a data-toggle="tab" href="#responses-{{nickname}}-{{code}}-headers">Headers</a>
</li>
{{/hasHeaders}}
</ul>

<div class="tab-content" style='margin-bottom: 10px;'>
{{#schema}}
<div class="tab-pane active" id="responses-{{nickname}}-{{code}}-schema">
<div id='responses-{{nickname}}-{{code}}-schema-{{code}}' style="padding: 30px; border-left: 1px solid #eee; border-right: 1px solid #eee; border-bottom: 1px solid #eee;">
<script>
$(document).ready(function() {
var schemaWrapper = {{{jsonSchema}}};
var schema = schemaWrapper.schema;
Expand All @@ -366,23 +372,44 @@
}, function(err, resolved, metadata) {
//console.log(JSON.stringify(resolved));
var view = new JSONSchemaView(resolved.schema, 3);
$('#examples-{{baseName}}-{{nickname}}-schema-data').val(JSON.stringify(resolved.schema));
var result = $('#examples-{{baseName}}-{{nickname}}-schema-{{code}}');
$('#responses-{{nickname}}-{{code}}-schema-data').val(JSON.stringify(resolved.schema));
var result = $('#responses-{{nickname}}-{{code}}-schema-{{code}}');
result.empty();
result.append(view.render());
});
});
</script>
</div>
<input id='examples-{{baseName}}-{{nickname}}-schema-data' type='hidden' value=''></input>
<input id='responses-{{nickname}}-{{code}}-schema-data' type='hidden' value=''></input>
</div>
{{#examples}}
<div class="tab-pane" id="examples-{{baseName}}-{{nickname}}-example">
<pre class="prettyprint"><code class="json">{{example}}</code></pre>
</div>
<div class="tab-pane" id="responses-{{nickname}}-{{code}}-example">
<pre class="prettyprint"><code class="json">{{example}}</code></pre>
</div>
{{/examples}}
</div>
{{/schema}}
{{/schema}}
{{#hasHeaders}}
<div class="tab-pane" id="responses-{{nickname}}-{{code}}-headers">
<table>
<tr>
<th width="150px">Name</th>
<th width="100px">Type</th>
<th width="100px">Format</th>
<th>Description</th>
</tr>
{{#headers}}
<tr>
<td>{{#name}}{{name}}{{/name}}</td>
<td>{{#datatype}}{{datatype}}{{/datatype}}</td>
<td>{{#dataFormat}}{{dataFormat}}{{/dataFormat}}</td>
<td>{{#description}}{{description}}{{/description}}</td>
</tr>
{{/headers}}
</table>
</div>
{{/hasHeaders}}
</div>

{{/responses}}
</article>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Loading