Skip to content

Commit

Permalink
Merge pull request #131 from schursin/master
Browse files Browse the repository at this point in the history
support of $ref in parameters and responses
  • Loading branch information
auscaster authored Mar 23, 2018
2 parents bdf2846 + ff1ac52 commit 1f088a4
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 72 deletions.
10 changes: 10 additions & 0 deletions app/helpers/schemaReferenceContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var common = require('../lib/common');

/**
* Resolve a (local) json schema $ref and replace context to referenced object.
* @param reference
* @param options
*/
module.exports = function(reference, options) {
return options.fn(reference ? common.resolveSchemaReference(reference, options.data.root) : this);
};
52 changes: 27 additions & 25 deletions app/views/partials/swagger/parameters.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,36 @@
{{#if parameters}}
<section class="swagger-request-params">
{{#each parameters}}
<div class="prop-row prop-group">
<div class="prop-name">
<div class="prop-title">{{name}}</div>
{{#if required}}
<span class="json-property-required"></span>
{{/if}}
<div class="prop-subtitle">
in {{in}}
{{#schemaReferenceContext $ref}}
<div class="prop-row prop-group">
<div class="prop-name">
<div class="prop-title">{{name}}</div>
{{#if required}}
<span class="json-property-required"></span>
{{/if}}
<div class="prop-subtitle">
in {{in}}
</div>
<div class="prop-subtitle">
{{~>json-schema/datatype . ~}}
</div>
{{!--
{{#if schema.$ref}}
<span class="swagger-global"></span> <span class="json-schema-reference"><a href="{{$ref}}">{{$ref}}</a></span>
{{/if}}
--}}
</div>
<div class="prop-subtitle">
{{~>json-schema/datatype . ~}}
<div class="prop-value">
{{>swagger/description description}}
</div>
{{!--
{{#if schema.$ref}}
<span class="swagger-global"></span> <span class="json-schema-reference"><a href="{{$ref}}">{{$ref}}</a></span>
{{/if}}
--}}
</div>
<div class="prop-value">
{{>swagger/description description}}
</div>
</div>
{{! parameter `collectionFormat` field }}
{{~#if collectionFormat ~}}
<div class="prop-row prop-inner">
{{md (swaggerCollectionFormat collectionFormat name) stripParagraph=true}}
</div>
{{~/if}}
{{! parameter `collectionFormat` field }}
{{~#if collectionFormat ~}}
<div class="prop-row prop-inner">
{{md (swaggerCollectionFormat collectionFormat name) stripParagraph=true}}
</div>
{{~/if}}
{{/schemaReferenceContext}}
{{/each}}
</section>
{{/if}}
98 changes: 51 additions & 47 deletions app/views/partials/swagger/responses.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,27 @@
--}}

{{#each responses}}
<div class="prop-row prop-group">
<div class="prop-name">
{{! Use response-code and http-name as text}}
<div class="prop-title">{{@key}} {{httpResponseCode @key}}</div>
{{#if schema}}
<div class="prop-ref">{{>json-schema/reference schema}}</div>
<!-- <span class="swagger-global"></span> <span class="json-schema-reference"><a href="{{$ref}}">{{$ref}}</a></span> -->
{{/if}}
{{#schemaReferenceContext $ref}}
<div class="prop-row prop-group">
<div class="prop-name">
{{! Use response-code and http-name as text}}
<div class="prop-title">{{@key}} {{httpResponseCode @key}}</div>
{{#if schema}}
<div class="prop-ref">{{>json-schema/reference schema}}</div>
<!-- <span class="swagger-global"></span> <span class="json-schema-reference"><a href="{{$ref}}">{{$ref}}</a></span> -->
{{/if}}
</div>
<div class="prop-value">
{{md description}}
</div>
</div>
<div class="prop-value">
{{md description}}
</div>
</div>
{{#if schema.type}}
<div class="prop-row prop-inner">
<div class="prop-name">type</div>
<div class="prop-value">{{>json-schema/datatype schema}}</div>
</div>
{{/if}}
{{#if schema.type}}
<div class="prop-row prop-inner">
<div class="prop-name">type</div>
<div class="prop-value">{{>json-schema/datatype schema}}</div>
</div>
{{/if}}
{{/schemaReferenceContext}}
{{/each}}
</section>
</div>
Expand All @@ -53,37 +55,39 @@
{{/if}}

{{#each responses}}
{{#if schema}}
<section>
<h5>Response Example <span>({{@key}} {{httpResponseCode @key}})</span></h5>
{{>swagger/print-example .}}
</section>
{{/if}}
{{#if headers}}
{{#schemaReferenceContext $ref}}
{{#if schema}}
<section>
<h5>Response Headers <span>({{@key}} {{httpResponseCode @key}})</span></h5>
<section class="swagger-response-headers">
<table class="table">
<thead>
<tr>
<th class="swagger-response-header-name"></th>
<th class="swagger-response-header-description"></th>
<th class="swagger-response-header-data-type"></th>
</tr>
</thead>
<tbody>
{{#each headers}}
{{#if $ref}}
{{> swagger/responseHeaderRow header=(json-schema-resolve-ref $ref) name=@key}}
{{else}}
{{> swagger/responseHeaderRow header=. name=@key}}
{{/if}}
{{/each}}
</tbody>
</table>
</section>
<h5>Response Example <span>({{@key}} {{httpResponseCode @key}})</span></h5>
{{>swagger/print-example .}}
</section>
{{/if}}
{{/if}}
{{#if headers}}
<section>
<h5>Response Headers <span>({{@key}} {{httpResponseCode @key}})</span></h5>
<section class="swagger-response-headers">
<table class="table">
<thead>
<tr>
<th class="swagger-response-header-name"></th>
<th class="swagger-response-header-description"></th>
<th class="swagger-response-header-data-type"></th>
</tr>
</thead>
<tbody>
{{#each headers}}
{{#if $ref}}
{{> swagger/responseHeaderRow header=(json-schema-resolve-ref $ref) name=@key}}
{{else}}
{{> swagger/responseHeaderRow header=. name=@key}}
{{/if}}
{{/each}}
</tbody>
</table>
</section>
</section>
{{/if}}
{{/schemaReferenceContext}}
{{/each}}
</div>
</div>
Expand Down

0 comments on commit 1f088a4

Please sign in to comment.