mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 10:03:31 +00:00
Support for x-stability property (#3064)
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/openapi-parser': patch
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
'gitbook': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Support for x-stability property
|
||||||
@@ -77,7 +77,12 @@ async function OpenAPIOperationBody(props: BlockProps<AnyOpenAPIOperationsBlock>
|
|||||||
ancestorBlocks={props.ancestorBlocks}
|
ancestorBlocks={props.ancestorBlocks}
|
||||||
isEstimatedOffscreen={props.isEstimatedOffscreen}
|
isEstimatedOffscreen={props.isEstimatedOffscreen}
|
||||||
context={props.context}
|
context={props.context}
|
||||||
style={headingProps.deprecated ? 'line-through' : undefined}
|
style={tcls([
|
||||||
|
headingProps.deprecated ? 'line-through' : undefined,
|
||||||
|
headingProps.deprecated || !!headingProps.stability
|
||||||
|
? '[&>div]:mt-0'
|
||||||
|
: undefined,
|
||||||
|
])}
|
||||||
block={{
|
block={{
|
||||||
object: 'block',
|
object: 'block',
|
||||||
key: `${block.key}-heading`,
|
key: `${block.key}-heading`,
|
||||||
|
|||||||
@@ -20,10 +20,31 @@
|
|||||||
@apply flex flex-col items-start justify-start gap-3;
|
@apply flex flex-col items-start justify-start gap-3;
|
||||||
}
|
}
|
||||||
|
|
||||||
.openapi-deprecated {
|
.openapi-summary-tags {
|
||||||
|
@apply flex flex-row gap-2 mt-[0.75em];
|
||||||
|
}
|
||||||
|
|
||||||
|
.openapi-deprecated,
|
||||||
|
.openapi-stability {
|
||||||
@apply py-0.5 px-1.5 min-w-[1.625rem] font-normal w-fit justify-center items-center ring-1 ring-inset ring-tint bg-tint rounded text-sm leading-[calc(max(1.20em,1.25rem))] before:!content-none after:!content-none;
|
@apply py-0.5 px-1.5 min-w-[1.625rem] font-normal w-fit justify-center items-center ring-1 ring-inset ring-tint bg-tint rounded text-sm leading-[calc(max(1.20em,1.25rem))] before:!content-none after:!content-none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.openapi-stability-stable {
|
||||||
|
@apply text-green-600 dark:text-green-300 bg-green-50 dark:bg-green-900/6 ring-green-500/5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.openapi-stability-alpha {
|
||||||
|
@apply text-amber-700 dark:text-amber-300 bg-amber-50 dark:bg-amber-900/6 ring-amber-500/5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.openapi-stability-beta {
|
||||||
|
@apply text-blue-700 dark:text-blue-300 bg-blue-50 dark:bg-blue-900/6 ring-blue-500/5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.openapi-stability-experimental {
|
||||||
|
@apply text-violet-700 dark:text-violet-300 bg-violet-50 dark:bg-violet-900/6 ring-violet-500/5;
|
||||||
|
}
|
||||||
|
|
||||||
.openapi-deprecated-sunset-date {
|
.openapi-deprecated-sunset-date {
|
||||||
@apply font-semibold font-mono truncate;
|
@apply font-semibold font-mono truncate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,8 +62,16 @@ export interface OpenAPICustomOperationProperties {
|
|||||||
name?: string;
|
name?: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stability of the operation.
|
||||||
|
* @enum 'experimental' | 'alpha' | 'beta' | 'stable'
|
||||||
|
*/
|
||||||
|
'x-stability'?: OpenAPIStability;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type OpenAPIStability = 'experimental' | 'alpha' | 'beta' | 'stable';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom code samples that can be defined at the operation level.
|
* Custom code samples that can be defined at the operation level.
|
||||||
* It follows the spec defined by Redocly.
|
* It follows the spec defined by Redocly.
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
|
|
||||||
import type { OpenAPICustomOperationProperties, OpenAPIV3 } from '@gitbook/openapi-parser';
|
import type {
|
||||||
|
OpenAPICustomOperationProperties,
|
||||||
|
OpenAPIStability,
|
||||||
|
OpenAPIV3,
|
||||||
|
} from '@gitbook/openapi-parser';
|
||||||
import { Markdown } from './Markdown';
|
import { Markdown } from './Markdown';
|
||||||
import { OpenAPICodeSample } from './OpenAPICodeSample';
|
import { OpenAPICodeSample } from './OpenAPICodeSample';
|
||||||
import { OpenAPIPath } from './OpenAPIPath';
|
import { OpenAPIPath } from './OpenAPIPath';
|
||||||
@@ -29,14 +33,24 @@ export function OpenAPIOperation(props: {
|
|||||||
return (
|
return (
|
||||||
<div className={clsx('openapi-operation', className)}>
|
<div className={clsx('openapi-operation', className)}>
|
||||||
<div className="openapi-summary" id={operation.summary ? undefined : context.id}>
|
<div className="openapi-summary" id={operation.summary ? undefined : context.id}>
|
||||||
|
{(operation.deprecated || operation['x-stability']) && (
|
||||||
|
<div className="openapi-summary-tags">
|
||||||
|
{operation.deprecated && (
|
||||||
|
<div className="openapi-deprecated">Deprecated</div>
|
||||||
|
)}
|
||||||
|
{operation['x-stability'] && (
|
||||||
|
<OpenAPIOperationStability stability={operation['x-stability']} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{operation.summary
|
{operation.summary
|
||||||
? context.renderHeading({
|
? context.renderHeading({
|
||||||
deprecated: operation.deprecated ?? false,
|
deprecated: operation.deprecated ?? false,
|
||||||
|
stability: operation['x-stability'],
|
||||||
title: operation.summary,
|
title: operation.summary,
|
||||||
})
|
})
|
||||||
: null}
|
: null}
|
||||||
<OpenAPIPath data={data} context={context} />
|
<OpenAPIPath data={data} context={context} />
|
||||||
{operation.deprecated && <div className="openapi-deprecated">Deprecated</div>}
|
|
||||||
</div>
|
</div>
|
||||||
<div className="openapi-columns">
|
<div className="openapi-columns">
|
||||||
<div className="openapi-column-spec">
|
<div className="openapi-column-spec">
|
||||||
@@ -89,3 +103,26 @@ function OpenAPIOperationDescription(props: {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const stabilityEnum = {
|
||||||
|
experimental: 'Experimental',
|
||||||
|
alpha: 'Alpha',
|
||||||
|
beta: 'Beta',
|
||||||
|
stable: 'Stable',
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
function OpenAPIOperationStability(props: { stability: OpenAPIStability }) {
|
||||||
|
const { stability } = props;
|
||||||
|
|
||||||
|
const foundStability = stabilityEnum[stability];
|
||||||
|
|
||||||
|
if (!foundStability) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={`openapi-stability openapi-stability-${foundStability.toLowerCase()}`}>
|
||||||
|
{foundStability}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,7 +13,11 @@ export interface OpenAPIContextProps extends OpenAPIClientContext {
|
|||||||
/**
|
/**
|
||||||
* Render the heading of the operation.
|
* Render the heading of the operation.
|
||||||
*/
|
*/
|
||||||
renderHeading: (props: { deprecated: boolean; title: string }) => React.ReactNode;
|
renderHeading: (props: {
|
||||||
|
deprecated: boolean;
|
||||||
|
title: string;
|
||||||
|
stability?: string;
|
||||||
|
}) => React.ReactNode;
|
||||||
/**
|
/**
|
||||||
* Render the document of the operation.
|
* Render the document of the operation.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user