Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support of $ref in parameters and responses #131

Merged
merged 1 commit into from
Mar 23, 2018
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
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