refactor Extensions, move Redoc extension list to utils file

This commit is contained in:
Ingo Claro 2018-07-23 10:13:35 -07:00
parent 6d500f0405
commit 3000b67637
2 changed files with 28 additions and 18 deletions

View File

@ -1,5 +1,6 @@
import * as React from 'react';
import { isRedocExtension } from '../../utils/openapi';
import { OptionsContext } from '../OptionsProvider';
import { SchemaModel } from '../../services/models';
@ -10,33 +11,25 @@ export interface ExtensionsProps {
}
export class Extensions extends React.PureComponent<ExtensionsProps> {
redocExtensions = [
'x-circular-ref',
'x-code-samples',
'x-displayName',
'x-examples',
'x-ignoredHeaderParameters',
'x-logo',
'x-nullable',
'x-servers',
'x-tagGroups',
'x-traitTag',
];
constructor(props) {
super(props);
this.getExtensions = this.getExtensions.bind(this);
}
render() {
getExtensions() {
const { schema } = this.props;
const fullSchema = schema.schema;
const extensionList = Object.keys(fullSchema).filter(
key => key.startsWith('x-') && !this.redocExtensions.includes(key),
);
return Object.keys(fullSchema).filter(key => key.startsWith('x-') && !isRedocExtension(key));
}
render() {
return (
<OptionsContext.Consumer>
{options => (
<>
{options.showExtensions &&
extensionList.map(key => (
<FieldDetail key={key} label={key} value={fullSchema[key]} />
this.getExtensions().map(key => (
<FieldDetail key={key} label={key} value={this.props.schema.schema[key]} />
))}
</>
)}

View File

@ -286,3 +286,20 @@ export const shortenHTTPVerb = verb =>
delete: 'del',
options: 'opts',
}[verb] || verb);
export function isRedocExtension(key: string): boolean {
const redocExtensions = {
'x-circular-ref': true,
'x-code-samples': true,
'x-displayName': true,
'x-examples': true,
'x-ignoredHeaderParameters': true,
'x-logo': true,
'x-nullable': true,
'x-servers': true,
'x-tagGroups': true,
'x-traitTag': true,
};
return key in redocExtensions;
}