diff --git a/src/components/Responses/Response.tsx b/src/components/Responses/Response.tsx
index 58e0ae32..bc6ece8b 100644
--- a/src/components/Responses/Response.tsx
+++ b/src/components/Responses/Response.tsx
@@ -12,11 +12,12 @@ 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 = (!extensions || Object.keys(extensions).length === 0) &&
+ headers.length === 0 && mimes.length === 0 && !description;
return (
diff --git a/src/components/Responses/ResponseDetails.tsx b/src/components/Responses/ResponseDetails.tsx
index 821fc2da..3794eba1 100644
--- a/src/components/Responses/ResponseDetails.tsx
+++ b/src/components/Responses/ResponseDetails.tsx
@@ -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 && }
+
{({ schema }) => {
diff --git a/src/services/__tests__/models/Response.test.ts b/src/services/__tests__/models/Response.test.ts
index ebb836c0..48633619 100644
--- a/src/services/__tests__/models/Response.test.ts
+++ b/src/services/__tests__/models/Response.test.ts
@@ -39,5 +39,12 @@ describe('Models', () => {
const resp = new ResponseModel({ ...props, code: 'default', defaultAsError: true });
expect(resp.type).toEqual('error');
});
+
+ test('ensure extensions are shown if showExtensions is true', () => {
+ const options = new RedocNormalizedOptions({ showExtensions: true });
+ const resp = new ResponseModel(parser, 'default', true, { 'x-example': {a: 1} } as any, options);
+ expect(Object.keys(resp.extensions).length).toEqual(1);
+ expect(resp.extensions['x-example']).toEqual({a: 1});
+ });
});
});
diff --git a/src/services/models/Response.ts b/src/services/models/Response.ts
index 0a264132..a0878093 100644
--- a/src/services/models/Response.ts
+++ b/src/services/models/Response.ts
@@ -2,7 +2,10 @@ import { action, observable, makeObservable } 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';
@@ -27,6 +30,7 @@ export class ResponseModel {
description: string;
type: string;
headers: FieldModel[] = [];
+ extensions: Record;
constructor(props: ResponseProps) {
const { parser, code, defaultAsError, infoOrRef, options, isEvent } = props;
@@ -59,6 +63,10 @@ export class ResponseModel {
return new FieldModel(parser, { ...header, name }, '', options);
});
}
+
+ if (options.showExtensions) {
+ this.extensions = extractExtensions(info, options.showExtensions);
+ }
}
@action
diff --git a/src/types/open-api.ts b/src/types/open-api.ts
index 622c5163..7038aa7a 100644
--- a/src/types/open-api.ts
+++ b/src/types/open-api.ts
@@ -192,7 +192,7 @@ export interface OpenAPIRequestBody {
}
export interface OpenAPIResponses {
- [code: string]: OpenAPIResponse;
+ [code: string]: Referenced;
}
export interface OpenAPIResponse