Skip to content

Commit 5b1e01c

Browse files
authored
Support for x-stability property (#3064)
1 parent 813b2af commit 5b1e01c

File tree

6 files changed

+87
-5
lines changed

6 files changed

+87
-5
lines changed

.changeset/silly-mice-lie.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@gitbook/openapi-parser': patch
3+
'@gitbook/react-openapi': patch
4+
'gitbook': patch
5+
---
6+
7+
Support for x-stability property

packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPIOperation.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ async function OpenAPIOperationBody(props: BlockProps<AnyOpenAPIOperationsBlock>
7777
ancestorBlocks={props.ancestorBlocks}
7878
isEstimatedOffscreen={props.isEstimatedOffscreen}
7979
context={props.context}
80-
style={headingProps.deprecated ? 'line-through' : undefined}
80+
style={tcls([
81+
headingProps.deprecated ? 'line-through' : undefined,
82+
headingProps.deprecated || !!headingProps.stability
83+
? '[&>div]:mt-0'
84+
: undefined,
85+
])}
8186
block={{
8287
object: 'block',
8388
key: `${block.key}-heading`,

packages/gitbook/src/components/DocumentView/OpenAPI/style.css

+22-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,31 @@
2020
@apply flex flex-col items-start justify-start gap-3;
2121
}
2222

23-
.openapi-deprecated {
23+
.openapi-summary-tags {
24+
@apply flex flex-row gap-2 mt-[0.75em];
25+
}
26+
27+
.openapi-deprecated,
28+
.openapi-stability {
2429
@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;
2530
}
2631

32+
.openapi-stability-stable {
33+
@apply text-green-600 dark:text-green-300 bg-green-50 dark:bg-green-900/6 ring-green-500/5;
34+
}
35+
36+
.openapi-stability-alpha {
37+
@apply text-amber-700 dark:text-amber-300 bg-amber-50 dark:bg-amber-900/6 ring-amber-500/5;
38+
}
39+
40+
.openapi-stability-beta {
41+
@apply text-blue-700 dark:text-blue-300 bg-blue-50 dark:bg-blue-900/6 ring-blue-500/5;
42+
}
43+
44+
.openapi-stability-experimental {
45+
@apply text-violet-700 dark:text-violet-300 bg-violet-50 dark:bg-violet-900/6 ring-violet-500/5;
46+
}
47+
2748
.openapi-deprecated-sunset-date {
2849
@apply font-semibold font-mono truncate;
2950
}

packages/openapi-parser/src/types.ts

+8
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,16 @@ export interface OpenAPICustomOperationProperties {
6262
name?: string;
6363
};
6464
};
65+
66+
/**
67+
* Stability of the operation.
68+
* @enum 'experimental' | 'alpha' | 'beta' | 'stable'
69+
*/
70+
'x-stability'?: OpenAPIStability;
6571
}
6672

73+
export type OpenAPIStability = 'experimental' | 'alpha' | 'beta' | 'stable';
74+
6775
/**
6876
* Custom code samples that can be defined at the operation level.
6977
* It follows the spec defined by Redocly.

packages/react-openapi/src/OpenAPIOperation.tsx

+39-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import clsx from 'clsx';
22

3-
import type { OpenAPICustomOperationProperties, OpenAPIV3 } from '@gitbook/openapi-parser';
3+
import type {
4+
OpenAPICustomOperationProperties,
5+
OpenAPIStability,
6+
OpenAPIV3,
7+
} from '@gitbook/openapi-parser';
48
import { Markdown } from './Markdown';
59
import { OpenAPICodeSample } from './OpenAPICodeSample';
610
import { OpenAPIPath } from './OpenAPIPath';
@@ -29,14 +33,24 @@ export function OpenAPIOperation(props: {
2933
return (
3034
<div className={clsx('openapi-operation', className)}>
3135
<div className="openapi-summary" id={operation.summary ? undefined : context.id}>
36+
{(operation.deprecated || operation['x-stability']) && (
37+
<div className="openapi-summary-tags">
38+
{operation.deprecated && (
39+
<div className="openapi-deprecated">Deprecated</div>
40+
)}
41+
{operation['x-stability'] && (
42+
<OpenAPIOperationStability stability={operation['x-stability']} />
43+
)}
44+
</div>
45+
)}
3246
{operation.summary
3347
? context.renderHeading({
3448
deprecated: operation.deprecated ?? false,
49+
stability: operation['x-stability'],
3550
title: operation.summary,
3651
})
3752
: null}
3853
<OpenAPIPath data={data} context={context} />
39-
{operation.deprecated && <div className="openapi-deprecated">Deprecated</div>}
4054
</div>
4155
<div className="openapi-columns">
4256
<div className="openapi-column-spec">
@@ -89,3 +103,26 @@ function OpenAPIOperationDescription(props: {
89103
</div>
90104
);
91105
}
106+
107+
const stabilityEnum = {
108+
experimental: 'Experimental',
109+
alpha: 'Alpha',
110+
beta: 'Beta',
111+
stable: 'Stable',
112+
} as const;
113+
114+
function OpenAPIOperationStability(props: { stability: OpenAPIStability }) {
115+
const { stability } = props;
116+
117+
const foundStability = stabilityEnum[stability];
118+
119+
if (!foundStability) {
120+
return null;
121+
}
122+
123+
return (
124+
<div className={`openapi-stability openapi-stability-${foundStability.toLowerCase()}`}>
125+
{foundStability}
126+
</div>
127+
);
128+
}

packages/react-openapi/src/types.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ export interface OpenAPIContextProps extends OpenAPIClientContext {
1313
/**
1414
* Render the heading of the operation.
1515
*/
16-
renderHeading: (props: { deprecated: boolean; title: string }) => React.ReactNode;
16+
renderHeading: (props: {
17+
deprecated: boolean;
18+
title: string;
19+
stability?: string;
20+
}) => React.ReactNode;
1721
/**
1822
* Render the document of the operation.
1923
*/

0 commit comments

Comments
 (0)