mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-07 21:54:53 +03:00
refactor Extensions, move Redoc extension list to utils file
This commit is contained in:
parent
6d500f0405
commit
3000b67637
|
@ -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]} />
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user