import clsx from 'clsx';
import type {
OpenAPICustomOperationProperties,
OpenAPIStability,
OpenAPIV3,
} from '@gitbook/openapi-parser';
import { Markdown } from './Markdown';
import { OpenAPICodeSample } from './OpenAPICodeSample';
import { OpenAPIPath } from './OpenAPIPath';
import { OpenAPIResponseExample } from './OpenAPIResponseExample';
import { OpenAPISpec } from './OpenAPISpec';
import { getOpenAPIClientContext } from './context';
import type { OpenAPIContext, OpenAPIOperationData } from './types';
import { resolveDescription } from './utils';
/**
* Display an interactive OpenAPI operation.
*/
export function OpenAPIOperation(props: {
className?: string;
data: OpenAPIOperationData;
context: OpenAPIContext;
}) {
const { className, data, context } = props;
const { operation } = data;
const clientContext = getOpenAPIClientContext(context);
return (
{(operation.deprecated || operation['x-stability']) && (
{operation.deprecated && (
Deprecated
)}
{operation['x-stability'] && (
)}
)}
{operation.summary
? context.renderHeading({
deprecated: operation.deprecated ?? false,
stability: operation['x-stability'],
title: operation.summary,
})
: null}
{operation['x-deprecated-sunset'] ? (
This operation is deprecated and will be sunset on{' '}
{operation['x-deprecated-sunset']}
{'.'}
) : null}
);
}
function OpenAPIOperationDescription(props: {
operation: OpenAPIV3.OperationObject;
context: OpenAPIContext;
}) {
const { operation } = props;
if (operation['x-gitbook-description-document']) {
return (
{props.context.renderDocument({
document: operation['x-gitbook-description-document'],
})}
);
}
const description = resolveDescription(operation);
if (!description) {
return null;
}
return (
);
}
const stabilityEnum = {
experimental: 'Experimental',
alpha: 'Alpha',
beta: 'Beta',
} as const;
function OpenAPIOperationStability(props: { stability: OpenAPIStability }) {
const { stability } = props;
const foundStability = stabilityEnum[stability];
if (!foundStability) {
return null;
}
return (
{foundStability}
);
}