mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
Small OpenAPI improvements (#4131)
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@gitbook/react-openapi": patch
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Small OpenAPI Improvements
|
||||||
@@ -2,8 +2,6 @@ import type { JSONDocument } from '@gitbook/api';
|
|||||||
import { Icon } from '@gitbook/icons';
|
import { Icon } from '@gitbook/icons';
|
||||||
import { type OpenAPIContextInput, checkIsValidLocale } from '@gitbook/react-openapi';
|
import { type OpenAPIContextInput, checkIsValidLocale } from '@gitbook/react-openapi';
|
||||||
|
|
||||||
import { tcls } from '@/lib/tailwind';
|
|
||||||
|
|
||||||
import type { BlockProps } from '../Block';
|
import type { BlockProps } from '../Block';
|
||||||
import { PlainCodeBlock } from '../CodeBlock';
|
import { PlainCodeBlock } from '../CodeBlock';
|
||||||
import { DocumentView } from '../DocumentView';
|
import { DocumentView } from '../DocumentView';
|
||||||
@@ -75,12 +73,7 @@ export function getOpenAPIContext(args: {
|
|||||||
ancestorBlocks={props.ancestorBlocks}
|
ancestorBlocks={props.ancestorBlocks}
|
||||||
isEstimatedOffscreen={props.isEstimatedOffscreen}
|
isEstimatedOffscreen={props.isEstimatedOffscreen}
|
||||||
context={props.context}
|
context={props.context}
|
||||||
style={tcls([
|
style={headingProps.deprecated ? 'line-through' : undefined}
|
||||||
headingProps.deprecated ? 'line-through' : undefined,
|
|
||||||
headingProps.deprecated || !!headingProps.stability
|
|
||||||
? '[&>div]:pt-0'
|
|
||||||
: undefined,
|
|
||||||
])}
|
|
||||||
block={{
|
block={{
|
||||||
object: 'block',
|
object: 'block',
|
||||||
key: `${block.key}-heading`,
|
key: `${block.key}-heading`,
|
||||||
|
|||||||
@@ -4,12 +4,13 @@
|
|||||||
/* Layout Components */
|
/* Layout Components */
|
||||||
.openapi-operation,
|
.openapi-operation,
|
||||||
.openapi-schemas,
|
.openapi-schemas,
|
||||||
.openapi-webhook {
|
.openapi-webhook,
|
||||||
@apply flex-1 flex flex-col gap-8 mb-14 min-w-0;
|
.openapi-schemas-single {
|
||||||
|
@apply flex-1 flex flex-col gap-6 mb-14 min-w-0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.openapi-schemas {
|
.openapi-schemas:not(.openapi-schemas-single) {
|
||||||
@apply flex flex-col mb-14 gap-0 flex-1;
|
@apply gap-0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.openapi-schemas-title {
|
.openapi-schemas-title {
|
||||||
@@ -33,6 +34,10 @@
|
|||||||
@apply flex flex-row gap-2 mt-[0.75em];
|
@apply flex flex-row gap-2 mt-[0.75em];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.openapi-summary-tags + .heading {
|
||||||
|
@apply pt-0;
|
||||||
|
}
|
||||||
|
|
||||||
.openapi-deprecated,
|
.openapi-deprecated,
|
||||||
.openapi-stability {
|
.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 straight-corners:rounded-none circular-corners:rounded-sm 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 straight-corners:rounded-none circular-corners:rounded-sm text-sm leading-[calc(max(1.20em,1.25rem))] before:content-none! after:!content-none;
|
||||||
@@ -144,7 +149,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.openapi-column-preview {
|
.openapi-column-preview {
|
||||||
@apply flex flex-col flex-1 xl:max-2xl:pt-20 lg:py-6 sticky max-h-[calc(100vh-var(--toc-top-offset))] top-(--toc-top-offset);
|
@apply flex flex-col flex-1 xl:max-2xl:pt-20 lg:pt-6 sticky self-start max-h-[calc(100vh-var(--toc-top-offset))] top-(--toc-top-offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
.openapi-column-preview-body {
|
.openapi-column-preview-body {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { getDataOrNull } from './data';
|
|||||||
import { getNodeReactText } from './document';
|
import { getNodeReactText } from './document';
|
||||||
import { resolveOpenAPIOperationBlock } from './openapi/resolveOpenAPIOperationBlock';
|
import { resolveOpenAPIOperationBlock } from './openapi/resolveOpenAPIOperationBlock';
|
||||||
import { resolveOpenAPISchemasBlock } from './openapi/resolveOpenAPISchemasBlock';
|
import { resolveOpenAPISchemasBlock } from './openapi/resolveOpenAPISchemasBlock';
|
||||||
|
import { resolveOpenAPIWebhookBlock } from './openapi/resolveOpenAPIWebhookBlock';
|
||||||
import { resolveContentRef } from './references';
|
import { resolveContentRef } from './references';
|
||||||
|
|
||||||
export interface DocumentSection {
|
export interface DocumentSection {
|
||||||
@@ -99,6 +100,25 @@ async function getSectionsFromNodes(
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
case 'openapi-webhook': {
|
||||||
|
const id = block.meta?.id;
|
||||||
|
if (!id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const { data: webhook } = await resolveOpenAPIWebhookBlock({
|
||||||
|
block,
|
||||||
|
context,
|
||||||
|
});
|
||||||
|
if (webhook) {
|
||||||
|
sections.push({
|
||||||
|
id,
|
||||||
|
title: webhook.operation.summary || webhook.name,
|
||||||
|
depth: 1,
|
||||||
|
deprecated: webhook.operation.deprecated,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
case 'openapi-schemas': {
|
case 'openapi-schemas': {
|
||||||
const id = block.meta?.id;
|
const id = block.meta?.id;
|
||||||
if (!id) {
|
if (!id) {
|
||||||
|
|||||||
@@ -25,7 +25,11 @@ export function hasFullWidthBlock(document: JSONDocument): boolean {
|
|||||||
if (block.data && 'fullWidth' in block.data && block.data.fullWidth) {
|
if (block.data && 'fullWidth' in block.data && block.data.fullWidth) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (block.type === 'swagger' || block.type === 'openapi-operation') {
|
if (
|
||||||
|
block.type === 'swagger' ||
|
||||||
|
block.type === 'openapi-operation' ||
|
||||||
|
block.type === 'openapi-webhook'
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export function OpenAPIWebhookExample(props: {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="openapi-panel">
|
<div className="openapi-panel" data-follow-color-scheme="true">
|
||||||
<h4 className="openapi-panel-heading">Payload</h4>
|
<h4 className="openapi-panel-heading">Payload</h4>
|
||||||
<div className="openapi-panel-body">
|
<div className="openapi-panel-body">
|
||||||
<OpenAPIMediaTypeContent
|
<OpenAPIMediaTypeContent
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export function OpenAPISchemas(props: {
|
|||||||
if (schemas.length === 1 && !grouped) {
|
if (schemas.length === 1 && !grouped) {
|
||||||
const title = `The ${firstSchema.name} object`;
|
const title = `The ${firstSchema.name} object`;
|
||||||
return (
|
return (
|
||||||
<div className={clsx('openapi-schemas', className)}>
|
<div className={clsx('openapi-schemas openapi-schemas-single', className)}>
|
||||||
<div className="openapi-summary" id={context.id}>
|
<div className="openapi-summary" id={context.id}>
|
||||||
{context.renderHeading({
|
{context.renderHeading({
|
||||||
title,
|
title,
|
||||||
@@ -61,7 +61,7 @@ export function OpenAPISchemas(props: {
|
|||||||
</div>
|
</div>
|
||||||
<div className="openapi-column-preview">
|
<div className="openapi-column-preview">
|
||||||
<div className="openapi-column-preview-body">
|
<div className="openapi-column-preview-body">
|
||||||
<div className="openapi-panel">
|
<div className="openapi-panel" data-follow-color-scheme="true">
|
||||||
<h4 className="openapi-panel-heading">{title}</h4>
|
<h4 className="openapi-panel-heading">{title}</h4>
|
||||||
<div className="openapi-panel-body">
|
<div className="openapi-panel-body">
|
||||||
<OpenAPIExample
|
<OpenAPIExample
|
||||||
|
|||||||
Reference in New Issue
Block a user