Add showExtentions for Responses

This commit is contained in:
Shelby Sanders 2020-10-08 13:44:56 -07:00
parent 918e2414f6
commit dbaab9e306
3 changed files with 15 additions and 4 deletions

View File

@ -12,11 +12,11 @@ export class ResponseView extends React.Component<{ response: ResponseModel }> {
};
render() {
const { headers, type, summary, description, code, expanded, content } = this.props.response;
const { extensions, headers, type, summary, description, code, expanded, content } = this.props.response;
const mimes =
content === undefined ? [] : content.mediaTypes.filter(mime => mime.schema !== undefined);
const empty = headers.length === 0 && mimes.length === 0 && !description;
const empty = Object.keys(extensions).length === 0 && headers.length === 0 && mimes.length === 0 && !description;
return (
<div>

View File

@ -7,15 +7,17 @@ import { DropdownOrLabel } from '../DropdownOrLabel/DropdownOrLabel';
import { MediaTypesSwitch } from '../MediaTypeSwitch/MediaTypesSwitch';
import { Schema } from '../Schema';
import { Extensions } from '../Fields/Extensions';
import { Markdown } from '../Markdown/Markdown';
import { ResponseHeaders } from './ResponseHeaders';
export class ResponseDetails extends React.PureComponent<{ response: ResponseModel }> {
render() {
const { description, headers, content } = this.props.response;
const { description, extensions, headers, content } = this.props.response;
return (
<>
{description && <Markdown source={description} />}
<Extensions extensions={extensions} />
<ResponseHeaders headers={headers} />
<MediaTypesSwitch content={content} renderDropdown={this.renderDropdown}>
{({ schema }) => {

View File

@ -2,7 +2,10 @@ import { action, observable } from 'mobx';
import { OpenAPIResponse, Referenced } from '../../types';
import { getStatusCodeType } from '../../utils';
import {
getStatusCodeType,
extractExtensions
} from '../../utils';
import { OpenAPIParser } from '../OpenAPIParser';
import { RedocNormalizedOptions } from '../RedocNormalizedOptions';
import { FieldModel } from './Field';
@ -19,6 +22,8 @@ export class ResponseModel {
type: string;
headers: FieldModel[] = [];
extensions: Record<string, any>;
constructor(
parser: OpenAPIParser,
code: string,
@ -52,6 +57,10 @@ export class ResponseModel {
return new FieldModel(parser, { ...header, name }, '', options);
});
}
if (options.showExtensions) {
this.extensions = extractExtensions(info, options.showExtensions);
}
}
@action