Move displaying Endpoint info to Callback section

This commit is contained in:
Oleksiy Kachynskyy 2020-03-30 15:35:40 +03:00
parent 7adcdc015d
commit 4f49b28d84
6 changed files with 29 additions and 20 deletions

View File

@ -4,7 +4,6 @@ import * as React from 'react';
import { RightPanelHeader, Tab, TabList, TabPanel, Tabs } from '../../common-elements'; import { RightPanelHeader, Tab, TabList, TabPanel, Tabs } from '../../common-elements';
import { isPayloadSample, RedocNormalizedOptions } from '../../services'; import { isPayloadSample, RedocNormalizedOptions } from '../../services';
import { CallbackModel } from '../../services/models'; import { CallbackModel } from '../../services/models';
import { Endpoint } from '../Endpoint/Endpoint';
import { OptionsContext } from '../OptionsProvider'; import { OptionsContext } from '../OptionsProvider';
import { PayloadSamples } from '../PayloadSamples/PayloadSamples'; import { PayloadSamples } from '../PayloadSamples/PayloadSamples';
import { SourceCodeWithCopy } from '../SourceCode/SourceCode'; import { SourceCodeWithCopy } from '../SourceCode/SourceCode';
@ -57,7 +56,6 @@ export class CallbackSamples extends React.Component<CallbackSamplesProps> {
<TabPanel key={sample.lang + '_' + (sample.label || '')}> <TabPanel key={sample.lang + '_' + (sample.label || '')}>
{isPayloadSample(sample) ? ( {isPayloadSample(sample) ? (
<div> <div>
<Endpoint operation={operation} inverted={false} />
<PayloadSamples content={sample.requestBodyContent} /> <PayloadSamples content={sample.requestBodyContent} />
</div> </div>
) : ( ) : (

View File

@ -15,7 +15,7 @@ export class CallbackView extends React.Component<{ callbackOperation: Operation
const { name, description, expanded } = this.props.callbackOperation; const { name, description, expanded } = this.props.callbackOperation;
return ( return (
<div> <>
<StyledCallbackTitle <StyledCallbackTitle
onClick={this.toggle} onClick={this.toggle}
name={name} name={name}
@ -27,7 +27,7 @@ export class CallbackView extends React.Component<{ callbackOperation: Operation
<CallbackDetails callbackOperation={this.props.callbackOperation} /> <CallbackDetails callbackOperation={this.props.callbackOperation} />
</CallbackDetailsWrap> </CallbackDetailsWrap>
)} )}
</div> </>
); );
} }
} }

View File

@ -2,9 +2,15 @@ import * as React from 'react';
import { OperationModel } from '../../services/models'; import { OperationModel } from '../../services/models';
import { OperationItem } from '../ContentItems/ContentItems'; import { OperationItem } from '../ContentItems/ContentItems';
import { Endpoint } from '../Endpoint/Endpoint';
export class CallbackDetails extends React.PureComponent<{ callbackOperation: OperationModel }> { export class CallbackDetails extends React.PureComponent<{ callbackOperation: OperationModel }> {
render() { render() {
return <OperationItem item={this.props.callbackOperation} />; return (
<div>
<Endpoint operation={this.props.callbackOperation} inverted={true} />
<OperationItem item={this.props.callbackOperation} />
</div>
);
} }
} }

View File

@ -11,5 +11,8 @@ export const StyledCallbackTitle = styled(CallbackTitle)`
`; `;
export const CallbackDetailsWrap = styled.div` export const CallbackDetailsWrap = styled.div`
padding: 10px; padding: 10px 25px;
background-color: #fafafa;
margin-bottom: 5px;
margin-top: 5px;
`; `;

View File

@ -108,6 +108,10 @@ export class OperationModel implements IMenuItem {
this.path = operationSpec.pathName; this.path = operationSpec.pathName;
this.isCallback = isCallback; this.isCallback = isCallback;
const pathInfo = parser.byRef<OpenAPIPath>(
JsonPointer.compile(['paths', operationSpec.pathName]),
);
if (this.isCallback) { if (this.isCallback) {
// NOTE: Use callback's event name as the view label, not the operationID. // NOTE: Use callback's event name as the view label, not the operationID.
this.name = callbackEventName || getOperationSummary(operationSpec); this.name = callbackEventName || getOperationSummary(operationSpec);
@ -116,24 +120,24 @@ export class OperationModel implements IMenuItem {
this.security = (operationSpec.security || []).map( this.security = (operationSpec.security || []).map(
security => new SecurityRequirementModel(security, parser), security => new SecurityRequirementModel(security, parser),
); );
// TODO: update getting pathInfo
this.servers = normalizeServers(
'',
operationSpec.servers || (pathInfo && pathInfo.servers) || [],
);
} else { } else {
this.name = getOperationSummary(operationSpec); this.name = getOperationSummary(operationSpec);
this.security = (operationSpec.security || parser.spec.security || []).map( this.security = (operationSpec.security || parser.spec.security || []).map(
security => new SecurityRequirementModel(security, parser), security => new SecurityRequirementModel(security, parser),
); );
this.servers = normalizeServers(
parser.specUrl,
operationSpec.servers || (pathInfo && pathInfo.servers) || parser.spec.servers || [],
);
} }
const pathInfo = parser.byRef<OpenAPIPath>(
JsonPointer.compile(['paths', operationSpec.pathName]),
);
// NOTE: Callbacks by default will inherit the specification's global `servers` definition.
// In many cases, this may be undesirable. Override individually in the specification to remedy this.
this.servers = normalizeServers(
parser.specUrl,
operationSpec.servers || (pathInfo && pathInfo.servers) || parser.spec.servers || [],
);
if (options.showExtensions) { if (options.showExtensions) {
this.extensions = extractExtensions(operationSpec, options.showExtensions); this.extensions = extractExtensions(operationSpec, options.showExtensions);
} }

View File

@ -10,9 +10,7 @@ const {
createGlobalStyle, createGlobalStyle,
keyframes, keyframes,
ThemeProvider, ThemeProvider,
} = (styledComponents as any) as styledComponents.ThemedStyledComponentsModule< } = styledComponents as styledComponents.ThemedStyledComponentsModule<ResolvedThemeInterface>;
ResolvedThemeInterface
>;
export const media = { export const media = {
lessThan(breakpoint, print?: boolean) { lessThan(breakpoint, print?: boolean) {