mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-12 05:48:57 +00:00
Schemas disclosure label causing client error (#3192)
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@gitbook/react-openapi': patch
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Fix schemas disclosure label causing client error
|
||||
@@ -755,11 +755,16 @@ body:has(.openapi-select-popover) {
|
||||
|
||||
.openapi-disclosure:not(
|
||||
.openapi-disclosure-group .openapi-disclosure,
|
||||
.openapi-schema-alternatives .openapi-disclosure
|
||||
.openapi-schema-alternatives .openapi-disclosure,
|
||||
.openapi-schemas-disclosure .openapi-schema.openapi-disclosure
|
||||
) {
|
||||
@apply rounded-xl;
|
||||
}
|
||||
|
||||
.openapi-disclosure .openapi-schemas-disclosure .openapi-schema.openapi-disclosure {
|
||||
@apply !rounded-none;
|
||||
}
|
||||
|
||||
.openapi-disclosure:has(> .openapi-disclosure-trigger:hover) {
|
||||
@apply bg-tint-subtle;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { OpenAPIDisclosure } from './OpenAPIDisclosure';
|
||||
import { OpenAPISchemaName } from './OpenAPISchemaName';
|
||||
import type { OpenAPIClientContext } from './context';
|
||||
import { retrocycle } from './decycle';
|
||||
import { getDisclosureLabel } from './getDisclosureLabel';
|
||||
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
||||
import { tString } from './translate';
|
||||
import { checkIsReference, resolveDescription, resolveFirstExample } from './utils';
|
||||
@@ -606,6 +607,11 @@ function getSchemaTitle(schema: OpenAPIV3.SchemaObject): string {
|
||||
if (schema.format) {
|
||||
type += ` · ${schema.format}`;
|
||||
}
|
||||
|
||||
// Only add the title if it's an object (no need for the title of a string, number, etc.)
|
||||
if (type === 'object' && schema.title) {
|
||||
type += ` · ${schema.title.replaceAll(' ', '')}`;
|
||||
}
|
||||
}
|
||||
|
||||
if ('anyOf' in schema) {
|
||||
@@ -620,25 +626,3 @@ function getSchemaTitle(schema: OpenAPIV3.SchemaObject): string {
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
function getDisclosureLabel(props: {
|
||||
schema: OpenAPIV3.SchemaObject;
|
||||
isExpanded: boolean;
|
||||
context: OpenAPIClientContext;
|
||||
}) {
|
||||
const { schema, isExpanded, context } = props;
|
||||
let label: string;
|
||||
if (schema.type === 'array' && !!schema.items) {
|
||||
if (schema.items.oneOf) {
|
||||
label = tString(context.translation, 'available_items').toLowerCase();
|
||||
} else if (schema.items.enum || schema.items.type === 'object') {
|
||||
label = tString(context.translation, 'properties').toLowerCase();
|
||||
} else {
|
||||
label = schema.items.title ?? schema.title ?? getSchemaTitle(schema.items);
|
||||
}
|
||||
} else {
|
||||
label = schema.title || tString(context.translation, 'properties').toLowerCase();
|
||||
}
|
||||
|
||||
return tString(context.translation, isExpanded ? 'hide' : 'show', label);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
'use client';
|
||||
|
||||
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
||||
import type { OpenAPIClientContext } from './context';
|
||||
import { tString } from './translate';
|
||||
|
||||
export function getDisclosureLabel(props: {
|
||||
schema: OpenAPIV3.SchemaObject;
|
||||
isExpanded: boolean;
|
||||
context: OpenAPIClientContext;
|
||||
}) {
|
||||
const { schema, isExpanded, context } = props;
|
||||
let label: string;
|
||||
if (schema.type === 'array' && !!schema.items) {
|
||||
if (schema.items.oneOf) {
|
||||
label = tString(context.translation, 'available_items').toLowerCase();
|
||||
} else {
|
||||
label = tString(context.translation, 'properties').toLowerCase();
|
||||
}
|
||||
} else {
|
||||
label = tString(context.translation, 'properties').toLowerCase();
|
||||
}
|
||||
|
||||
return tString(context.translation, isExpanded ? 'hide' : 'show', label);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
'use client';
|
||||
|
||||
import { SectionBody } from '../StaticSection';
|
||||
|
||||
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
||||
import { OpenAPIDisclosure } from '../OpenAPIDisclosure';
|
||||
import { OpenAPIRootSchema } from '../OpenAPISchemaServer';
|
||||
import { Section } from '../StaticSection';
|
||||
import type { OpenAPIClientContext } from '../context';
|
||||
import { getDisclosureLabel } from '../getDisclosureLabel';
|
||||
|
||||
export function OpenAPISchemaItem(props: {
|
||||
name: string;
|
||||
schema: OpenAPIV3.SchemaObject;
|
||||
context: OpenAPIClientContext;
|
||||
}) {
|
||||
const { schema, context, name } = props;
|
||||
|
||||
return (
|
||||
<OpenAPIDisclosure
|
||||
className="openapi-schemas-disclosure"
|
||||
key={name}
|
||||
icon={context.icons.plus}
|
||||
header={name}
|
||||
label={(isExpanded) => getDisclosureLabel({ schema, isExpanded, context })}
|
||||
>
|
||||
<Section className="openapi-section-schemas">
|
||||
<SectionBody>
|
||||
<OpenAPIRootSchema schema={schema} context={context} />
|
||||
</SectionBody>
|
||||
</Section>
|
||||
</OpenAPIDisclosure>
|
||||
);
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
import type { OpenAPISchema } from '@gitbook/openapi-parser';
|
||||
import clsx from 'clsx';
|
||||
import { OpenAPIDisclosure } from '../OpenAPIDisclosure';
|
||||
import { OpenAPIExample } from '../OpenAPIExample';
|
||||
import { OpenAPIRootSchema } from '../OpenAPISchemaServer';
|
||||
import { Section, SectionBody, StaticSection } from '../StaticSection';
|
||||
import { StaticSection } from '../StaticSection';
|
||||
import {
|
||||
type OpenAPIContextInput,
|
||||
getOpenAPIClientContext,
|
||||
resolveOpenAPIContext,
|
||||
} from '../context';
|
||||
import { t, tString } from '../translate';
|
||||
import { t } from '../translate';
|
||||
import { getExampleFromSchema } from '../util/example';
|
||||
import { OpenAPISchemaItem } from './OpenAPISchemaItem';
|
||||
|
||||
/**
|
||||
* OpenAPI Schemas component.
|
||||
@@ -85,21 +85,12 @@ export function OpenAPISchemas(props: {
|
||||
<div className={clsx('openapi-schemas', className)}>
|
||||
{schemas.map(({ name, schema }) => {
|
||||
return (
|
||||
<OpenAPIDisclosure
|
||||
className="openapi-schemas-disclosure"
|
||||
<OpenAPISchemaItem
|
||||
key={name}
|
||||
icon={context.icons.chevronRight}
|
||||
header={name}
|
||||
label={(isExpanded) =>
|
||||
tString(context.translation, isExpanded ? 'hide' : 'show')
|
||||
}
|
||||
>
|
||||
<Section className="openapi-section-schemas">
|
||||
<SectionBody>
|
||||
<OpenAPIRootSchema schema={schema} context={clientContext} />
|
||||
</SectionBody>
|
||||
</Section>
|
||||
</OpenAPIDisclosure>
|
||||
name={name}
|
||||
context={clientContext}
|
||||
schema={schema}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user