Skip to content

Support for x-stability property #3064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/silly-mice-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@gitbook/openapi-parser': patch
'@gitbook/react-openapi': patch
'gitbook': patch
---

Support for x-stability property
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ async function OpenAPIOperationBody(props: BlockProps<AnyOpenAPIOperationsBlock>
ancestorBlocks={props.ancestorBlocks}
isEstimatedOffscreen={props.isEstimatedOffscreen}
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={{
object: 'block',
key: `${block.key}-heading`,
Expand Down
23 changes: 22 additions & 1 deletion packages/gitbook/src/components/DocumentView/OpenAPI/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,31 @@
@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;
}

.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 {
@apply font-semibold font-mono truncate;
}
Expand Down
8 changes: 8 additions & 0 deletions packages/openapi-parser/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,16 @@ export interface OpenAPICustomOperationProperties {
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.
* It follows the spec defined by Redocly.
Expand Down
41 changes: 39 additions & 2 deletions packages/react-openapi/src/OpenAPIOperation.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
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 { OpenAPICodeSample } from './OpenAPICodeSample';
import { OpenAPIPath } from './OpenAPIPath';
Expand Down Expand Up @@ -29,14 +33,24 @@ export function OpenAPIOperation(props: {
return (
<div className={clsx('openapi-operation', className)}>
<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
? context.renderHeading({
deprecated: operation.deprecated ?? false,
stability: operation['x-stability'],
title: operation.summary,
})
: null}
<OpenAPIPath data={data} context={context} />
{operation.deprecated && <div className="openapi-deprecated">Deprecated</div>}
</div>
<div className="openapi-columns">
<div className="openapi-column-spec">
Expand Down Expand Up @@ -89,3 +103,26 @@ function OpenAPIOperationDescription(props: {
</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>
);
}
6 changes: 5 additions & 1 deletion packages/react-openapi/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export interface OpenAPIContextProps extends OpenAPIClientContext {
/**
* 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.
*/
Expand Down