mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-08 06:04:56 +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 * as React from 'react';
|
||||||
|
|
||||||
|
import { isRedocExtension } from '../../utils/openapi';
|
||||||
import { OptionsContext } from '../OptionsProvider';
|
import { OptionsContext } from '../OptionsProvider';
|
||||||
|
|
||||||
import { SchemaModel } from '../../services/models';
|
import { SchemaModel } from '../../services/models';
|
||||||
|
@ -10,33 +11,25 @@ export interface ExtensionsProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Extensions extends React.PureComponent<ExtensionsProps> {
|
export class Extensions extends React.PureComponent<ExtensionsProps> {
|
||||||
redocExtensions = [
|
constructor(props) {
|
||||||
'x-circular-ref',
|
super(props);
|
||||||
'x-code-samples',
|
this.getExtensions = this.getExtensions.bind(this);
|
||||||
'x-displayName',
|
}
|
||||||
'x-examples',
|
|
||||||
'x-ignoredHeaderParameters',
|
|
||||||
'x-logo',
|
|
||||||
'x-nullable',
|
|
||||||
'x-servers',
|
|
||||||
'x-tagGroups',
|
|
||||||
'x-traitTag',
|
|
||||||
];
|
|
||||||
|
|
||||||
render() {
|
getExtensions() {
|
||||||
const { schema } = this.props;
|
const { schema } = this.props;
|
||||||
const fullSchema = schema.schema;
|
const fullSchema = schema.schema;
|
||||||
const extensionList = Object.keys(fullSchema).filter(
|
return Object.keys(fullSchema).filter(key => key.startsWith('x-') && !isRedocExtension(key));
|
||||||
key => key.startsWith('x-') && !this.redocExtensions.includes(key),
|
}
|
||||||
);
|
|
||||||
|
|
||||||
|
render() {
|
||||||
return (
|
return (
|
||||||
<OptionsContext.Consumer>
|
<OptionsContext.Consumer>
|
||||||
{options => (
|
{options => (
|
||||||
<>
|
<>
|
||||||
{options.showExtensions &&
|
{options.showExtensions &&
|
||||||
extensionList.map(key => (
|
this.getExtensions().map(key => (
|
||||||
<FieldDetail key={key} label={key} value={fullSchema[key]} />
|
<FieldDetail key={key} label={key} value={this.props.schema.schema[key]} />
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -286,3 +286,20 @@ export const shortenHTTPVerb = verb =>
|
||||||
delete: 'del',
|
delete: 'del',
|
||||||
options: 'opts',
|
options: 'opts',
|
||||||
}[verb] || verb);
|
}[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