mirror of
https://github.com/Redocly/redoc.git
synced 2025-07-10 16:22:27 +03:00
add expand-responses option
This commit is contained in:
parent
03e779c0d1
commit
95f2da8b97
|
@ -124,6 +124,7 @@ ReDoc makes use of the following [vendor extensions](http://swagger.io/specifica
|
||||||
* `suppress-warnings` - if set, warnings are not rendered at the top of documentation (they still are logged to the console).
|
* `suppress-warnings` - if set, warnings are not rendered at the top of documentation (they still are logged to the console).
|
||||||
* `lazy-rendering` - if set, enables lazy rendering mode in ReDoc. This mode is useful for APIs with big number of operations (e.g. > 50). In this mode ReDoc shows initial screen ASAP and then renders the rest operations asynchronously while showing progress bar on the top. Check out the [demo](\\rebilly.github.io/ReDoc) for the example.
|
* `lazy-rendering` - if set, enables lazy rendering mode in ReDoc. This mode is useful for APIs with big number of operations (e.g. > 50). In this mode ReDoc shows initial screen ASAP and then renders the rest operations asynchronously while showing progress bar on the top. Check out the [demo](\\rebilly.github.io/ReDoc) for the example.
|
||||||
* `hide-hostname` - if set, the protocol and hostname is not shown in the method definition.
|
* `hide-hostname` - if set, the protocol and hostname is not shown in the method definition.
|
||||||
|
* `expand-responses` - specify which responses to expand by default by response codes. Values should be passed as comma-separated list without spaces e.g. `expand-responses="200,201"`. Special value `"all"` expands all responses by default. Be careful: this option can slow-down documentation rendering time.
|
||||||
|
|
||||||
## Advanced usage
|
## Advanced usage
|
||||||
Instead of adding `spec-url` attribute to the `<redoc>` element you can initialize ReDoc via globally exposed `Redoc` object:
|
Instead of adding `spec-url` attribute to the `<redoc>` element you can initialize ReDoc via globally exposed `Redoc` object:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<h2 class="responses-list-header" *ngIf="responses.length"> Responses </h2>
|
<h2 class="responses-list-header" *ngIf="responses.length"> Responses </h2>
|
||||||
<zippy *ngFor="let response of responses;trackBy:trackByCode" [title]="response.code + ' ' + response.description | marked"
|
<zippy *ngFor="let response of responses;trackBy:trackByCode" [title]="response.code + ' ' + response.description | marked"
|
||||||
[type]="response.type" [empty]="response.empty" (open)="lazySchema.load()">
|
[type]="response.type" [visible]="response.expanded" [empty]="response.empty" (open)="lazySchema.load()">
|
||||||
<div *ngIf="response.headers" class="response-headers">
|
<div *ngIf="response.headers" class="response-headers">
|
||||||
<header>
|
<header>
|
||||||
Headers
|
Headers
|
||||||
|
@ -20,6 +20,6 @@
|
||||||
<header *ngIf="response.schema">
|
<header *ngIf="response.schema">
|
||||||
Response Schema
|
Response Schema
|
||||||
</header>
|
</header>
|
||||||
<json-schema-lazy #lazySchema pointer="{{response.schema ? response.pointer + '/schema' : null}}">
|
<json-schema-lazy [auto]="response.expanded" #lazySchema pointer="{{response.schema ? response.pointer + '/schema' : null}}">
|
||||||
</json-schema-lazy>
|
</json-schema-lazy>
|
||||||
</zippy>
|
</zippy>
|
||||||
|
|
|
@ -49,6 +49,13 @@ export class ResponsesList extends BaseComponent implements OnInit {
|
||||||
resp.empty = !resp.schema;
|
resp.empty = !resp.schema;
|
||||||
resp.code = respCode;
|
resp.code = respCode;
|
||||||
resp.type = statusCodeType(resp.code);
|
resp.type = statusCodeType(resp.code);
|
||||||
|
|
||||||
|
if (this.options.expandResponses) {
|
||||||
|
if (this.options.expandResponses === 'all' || this.options.expandResponses.has(respCode.toString())) {
|
||||||
|
resp.expanded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (resp.headers && !(resp.headers instanceof Array)) {
|
if (resp.headers && !(resp.headers instanceof Array)) {
|
||||||
resp.headers = Object.keys(resp.headers).map((k) => {
|
resp.headers = Object.keys(resp.headers).map((k) => {
|
||||||
let respInfo = resp.headers[k];
|
let respInfo = resp.headers[k];
|
||||||
|
|
|
@ -14,7 +14,8 @@ describe('Options Service', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
document.body.removeChild(tmpDiv);
|
if (tmpDiv) document.body.removeChild(tmpDiv);
|
||||||
|
tmpDiv = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -47,4 +48,18 @@ describe('Options Service', () => {
|
||||||
optionsService.parseOptions(elem);
|
optionsService.parseOptions(elem);
|
||||||
optionsService.options.scrollYOffset().should.be.equal(123);
|
optionsService.options.scrollYOffset().should.be.equal(123);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should convert expandResponses options to Set', () => {
|
||||||
|
optionsService.options = { expandResponses: '200,300' };
|
||||||
|
optionsService._normalizeOptions();
|
||||||
|
optionsService.options.expandResponses.should.be.instanceof(Set);
|
||||||
|
Array.from(optionsService.options.expandResponses.values()).should.deepEqual(['200', '300']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should preserve special value "all" as string', () => {
|
||||||
|
optionsService.options = { expandResponses: 'all' };
|
||||||
|
optionsService._normalizeOptions();
|
||||||
|
optionsService.options.expandResponses.should.be.of.type('string');
|
||||||
|
optionsService.options.expandResponses.should.be.equal('all');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,7 +14,8 @@ const OPTION_NAMES = new Set([
|
||||||
'specUrl',
|
'specUrl',
|
||||||
'suppressWarnings',
|
'suppressWarnings',
|
||||||
'hideHostname',
|
'hideHostname',
|
||||||
'lazyRendering'
|
'lazyRendering',
|
||||||
|
'expandResponses'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
|
@ -24,6 +25,7 @@ interface Options {
|
||||||
suppressWarnings?: boolean;
|
suppressWarnings?: boolean;
|
||||||
hideHostname?: boolean;
|
hideHostname?: boolean;
|
||||||
lazyRendering?: boolean;
|
lazyRendering?: boolean;
|
||||||
|
expandResponses?: Set<string> | 'all';
|
||||||
$scrollParent?: HTMLElement | Window;
|
$scrollParent?: HTMLElement | Window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +38,7 @@ export class OptionsService {
|
||||||
this._normalizeOptions();
|
this._normalizeOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
get options():Options {
|
get options(): Options {
|
||||||
return this._options;
|
return this._options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,5 +91,10 @@ export class OptionsService {
|
||||||
if (isString(this._options.suppressWarnings)) this._options.suppressWarnings = true;
|
if (isString(this._options.suppressWarnings)) this._options.suppressWarnings = true;
|
||||||
if (isString(this._options.hideHostname)) this._options.hideHostname = true;
|
if (isString(this._options.hideHostname)) this._options.hideHostname = true;
|
||||||
if (isString(this._options.lazyRendering)) this._options.lazyRendering = true;
|
if (isString(this._options.lazyRendering)) this._options.lazyRendering = true;
|
||||||
|
if (isString(this._options.expandResponses)) {
|
||||||
|
let str = this._options.expandResponses as string;
|
||||||
|
if (str === 'all') return;
|
||||||
|
this._options.expandResponses = new Set(str.split(','));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user