mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-15 23:25:16 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 33c30ba7a1 |
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
'gitbook': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix missing headers in OpenAPIResponses
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
'gitbook': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix OpenAPI enum display
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
},
|
},
|
||||||
"packages/colors": {
|
"packages/colors": {
|
||||||
"name": "@gitbook/colors",
|
"name": "@gitbook/colors",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "^5.5.3",
|
"typescript": "^5.5.3",
|
||||||
},
|
},
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
},
|
},
|
||||||
"packages/gitbook": {
|
"packages/gitbook": {
|
||||||
"name": "gitbook",
|
"name": "gitbook",
|
||||||
"version": "0.8.2",
|
"version": "0.9.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@gitbook/api": "*",
|
"@gitbook/api": "*",
|
||||||
"@gitbook/cache-do": "workspace:*",
|
"@gitbook/cache-do": "workspace:*",
|
||||||
@@ -136,7 +136,7 @@
|
|||||||
},
|
},
|
||||||
"packages/gitbook-v2": {
|
"packages/gitbook-v2": {
|
||||||
"name": "gitbook-v2",
|
"name": "gitbook-v2",
|
||||||
"version": "0.2.2",
|
"version": "0.2.3",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@gitbook/api": "*",
|
"@gitbook/api": "*",
|
||||||
"@gitbook/cache-tags": "workspace:*",
|
"@gitbook/cache-tags": "workspace:*",
|
||||||
@@ -162,7 +162,7 @@
|
|||||||
"name": "@gitbook/icons",
|
"name": "@gitbook/icons",
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
"gitbook-icons": "./bin/gitbook-icons.js",
|
"gitbook-icons": "./bin/gitbook-icons.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-free": "^6.6.0",
|
"@fortawesome/fontawesome-free": "^6.6.0",
|
||||||
@@ -180,7 +180,7 @@
|
|||||||
},
|
},
|
||||||
"packages/openapi-parser": {
|
"packages/openapi-parser": {
|
||||||
"name": "@gitbook/openapi-parser",
|
"name": "@gitbook/openapi-parser",
|
||||||
"version": "2.1.1",
|
"version": "2.1.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@scalar/openapi-parser": "^0.10.10",
|
"@scalar/openapi-parser": "^0.10.10",
|
||||||
"@scalar/openapi-types": "^0.1.9",
|
"@scalar/openapi-types": "^0.1.9",
|
||||||
@@ -219,7 +219,7 @@
|
|||||||
"name": "@gitbook/react-math",
|
"name": "@gitbook/react-math",
|
||||||
"version": "0.6.0",
|
"version": "0.6.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
"gitbook-math": "./bin/gitbook-math.js",
|
"gitbook-math": "./bin/gitbook-math.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"object-hash": "^3.0.0",
|
"object-hash": "^3.0.0",
|
||||||
@@ -234,7 +234,7 @@
|
|||||||
},
|
},
|
||||||
"packages/react-openapi": {
|
"packages/react-openapi": {
|
||||||
"name": "@gitbook/react-openapi",
|
"name": "@gitbook/react-openapi",
|
||||||
"version": "1.1.6",
|
"version": "1.1.8",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@gitbook/openapi-parser": "workspace:*",
|
"@gitbook/openapi-parser": "workspace:*",
|
||||||
"@scalar/api-client-react": "^1.2.5",
|
"@scalar/api-client-react": "^1.2.5",
|
||||||
|
|||||||
@@ -179,4 +179,9 @@ export interface GitBookDataFetcher {
|
|||||||
integrationName: string;
|
integrationName: string;
|
||||||
request: api.RenderIntegrationUI;
|
request: api.RenderIntegrationUI;
|
||||||
}): Promise<DataFetcherResponse<api.ContentKitRenderOutput>>;
|
}): Promise<DataFetcherResponse<api.ContentKitRenderOutput>>;
|
||||||
|
|
||||||
|
getAction(params: {
|
||||||
|
url: string
|
||||||
|
claims: any
|
||||||
|
}): Promise<DataFetcherResponse<{ text: string; url: string; icon?: string }>>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,5 @@
|
|||||||
# gitbook
|
# gitbook
|
||||||
|
|
||||||
## 0.9.2
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- da7b369: Fix missing headers in OpenAPIResponses
|
|
||||||
- 139a805: Fix OpenAPI enum display
|
|
||||||
- Updated dependencies [da7b369]
|
|
||||||
- Updated dependencies [da485f5]
|
|
||||||
- Updated dependencies [139a805]
|
|
||||||
- @gitbook/react-openapi@1.1.9
|
|
||||||
|
|
||||||
## 0.9.1
|
## 0.9.1
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gitbook",
|
"name": "gitbook",
|
||||||
"version": "0.9.2",
|
"version": "0.9.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "env-cmd --silent -f ../../.env.local next dev",
|
"dev": "env-cmd --silent -f ../../.env.local next dev",
|
||||||
|
|||||||
@@ -25,10 +25,21 @@ export async function POST(req: NextRequest) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await revalidateTags(json.tags);
|
try {
|
||||||
|
const result = await revalidateTags(json.tags);
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
stats: result.stats,
|
||||||
|
});
|
||||||
|
} catch (err: unknown) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
error: 'Failed to revalidate tags',
|
||||||
|
message: err instanceof Error ? err.message : 'Internal Server Error',
|
||||||
|
stack: err instanceof Error ? err.stack : '',
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return NextResponse.json({
|
|
||||||
success: true,
|
|
||||||
stats: result.stats,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import assertNever from 'assert-never';
|
|||||||
import { Annotation } from './Annotation/Annotation';
|
import { Annotation } from './Annotation/Annotation';
|
||||||
import type { DocumentContextProps } from './DocumentView';
|
import type { DocumentContextProps } from './DocumentView';
|
||||||
import { Emoji } from './Emoji';
|
import { Emoji } from './Emoji';
|
||||||
|
import { InlineAction } from './InlineAction';
|
||||||
import { InlineImage } from './InlineImage';
|
import { InlineImage } from './InlineImage';
|
||||||
import { InlineLink } from './InlineLink';
|
import { InlineLink } from './InlineLink';
|
||||||
import { InlineMath } from './Math';
|
import { InlineMath } from './Math';
|
||||||
@@ -61,6 +62,8 @@ export function Inline<
|
|||||||
return <Mention {...contextProps} inline={inline} />;
|
return <Mention {...contextProps} inline={inline} />;
|
||||||
case 'inline-image':
|
case 'inline-image':
|
||||||
return <InlineImage {...contextProps} inline={inline} />;
|
return <InlineImage {...contextProps} inline={inline} />;
|
||||||
|
case 'action':
|
||||||
|
return <InlineAction {...contextProps} inline={inline} />;
|
||||||
default:
|
default:
|
||||||
assertNever(inline);
|
assertNever(inline);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { getVisitorAuthClaims } from '@/lib/adaptive';
|
||||||
|
import { getDataOrNull } from '@v2/lib/data';
|
||||||
|
import { getSiteURLDataFromMiddleware } from '@v2/lib/middleware';
|
||||||
|
import type { InlineProps } from './Inline';
|
||||||
|
import { TrackEventButton } from './TrackEventButton';
|
||||||
|
|
||||||
|
export async function InlineAction(props: InlineProps<any>) {
|
||||||
|
const { inline, context } = props;
|
||||||
|
|
||||||
|
if (!context.contentContext) {
|
||||||
|
throw new Error('inline action requires a contentContext');
|
||||||
|
}
|
||||||
|
|
||||||
|
const action = inline.data.action;
|
||||||
|
|
||||||
|
if (action.type === 'url') {
|
||||||
|
return <TrackEventButton action={inline.data.action} resolved={{ url: action.url, text: action.text }} />
|
||||||
|
}
|
||||||
|
|
||||||
|
// API action
|
||||||
|
|
||||||
|
const { dataFetcher } = context.contentContext;
|
||||||
|
|
||||||
|
const siteData = await getSiteURLDataFromMiddleware();
|
||||||
|
const claims = getVisitorAuthClaims(siteData)
|
||||||
|
const resolved = await getDataOrNull(dataFetcher.getAction({ url: inline.data.action.url, claims }));
|
||||||
|
|
||||||
|
if (!resolved) {
|
||||||
|
throw new Error('inline action not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
return <TrackEventButton action={inline.data.action} resolved={resolved} />
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
'use client';
|
||||||
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
import { useTrackEvent } from '../Insights';
|
||||||
|
import { LoadingButton } from '../primitives';
|
||||||
|
|
||||||
|
export function TrackEventButton(props: {
|
||||||
|
action: any;
|
||||||
|
resolved: { url: string; text: string };
|
||||||
|
}) {
|
||||||
|
const { action, resolved } = props;
|
||||||
|
const trackEvent = useTrackEvent();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<LoadingButton
|
||||||
|
onClick={async () => {
|
||||||
|
trackEvent({ type: 'action_click', action: action });
|
||||||
|
window.open(resolved.url, '_blank', 'noopener noreferrer');
|
||||||
|
}}
|
||||||
|
href={resolved.url}
|
||||||
|
variant="primary"
|
||||||
|
size="medium"
|
||||||
|
className={tcls(
|
||||||
|
'theme-bold:bg-header-link theme-bold:text-header-background theme-bold:shadow-none theme-bold:hover:bg-header-link theme-bold:hover:text-header-background theme-bold:hover:shadow-none'
|
||||||
|
)}
|
||||||
|
// insights={{
|
||||||
|
// type: 'link_click',
|
||||||
|
// link: {
|
||||||
|
// target: linkTarget,
|
||||||
|
// position: SiteInsightsLinkPosition.Header,
|
||||||
|
// },
|
||||||
|
// }}
|
||||||
|
>
|
||||||
|
{resolved.text}
|
||||||
|
</LoadingButton>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -93,6 +93,7 @@ export function InsightsProvider(props: InsightsProviderProps) {
|
|||||||
const flushEventsSync = useEventCallback(() => {
|
const flushEventsSync = useEventCallback(() => {
|
||||||
const session = getSession();
|
const session = getSession();
|
||||||
const visitorId = visitorIdRef.current;
|
const visitorId = visitorIdRef.current;
|
||||||
|
console.log('flushEventsSync');
|
||||||
if (!visitorId) {
|
if (!visitorId) {
|
||||||
throw new Error('Visitor ID should be set before flushing events');
|
throw new Error('Visitor ID should be set before flushing events');
|
||||||
}
|
}
|
||||||
@@ -126,6 +127,8 @@ export function InsightsProvider(props: InsightsProviderProps) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('allEvents', allEvents.length)
|
||||||
|
|
||||||
if (allEvents.length > 0) {
|
if (allEvents.length > 0) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
sendEvents({
|
sendEvents({
|
||||||
@@ -143,6 +146,7 @@ export function InsightsProvider(props: InsightsProviderProps) {
|
|||||||
const visitorId = visitorIdRef.current ?? (await getVisitorId(appURL));
|
const visitorId = visitorIdRef.current ?? (await getVisitorId(appURL));
|
||||||
visitorIdRef.current = visitorId;
|
visitorIdRef.current = visitorId;
|
||||||
|
|
||||||
|
console.log('flushBatchedEvents');
|
||||||
flushEventsSync();
|
flushEventsSync();
|
||||||
}, 1500);
|
}, 1500);
|
||||||
|
|
||||||
@@ -167,6 +171,8 @@ export function InsightsProvider(props: InsightsProviderProps) {
|
|||||||
context,
|
context,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log('trackEvent', event, eventsRef.current[pathname].pageContext);
|
||||||
|
|
||||||
if (eventsRef.current[pathname].pageContext !== undefined) {
|
if (eventsRef.current[pathname].pageContext !== undefined) {
|
||||||
// If the pageId is set, we know that the page_view event has been tracked
|
// If the pageId is set, we know that the page_view event has been tracked
|
||||||
// and we can flush the events
|
// and we can flush the events
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { type ClassValue, tcls } from '@/lib/tailwind';
|
|||||||
|
|
||||||
import { Link, type LinkInsightsProps } from './Link';
|
import { Link, type LinkInsightsProps } from './Link';
|
||||||
|
|
||||||
type ButtonProps = {
|
export type ButtonProps = {
|
||||||
href?: string;
|
href?: string;
|
||||||
variant?: 'primary' | 'secondary';
|
variant?: 'primary' | 'secondary';
|
||||||
size?: 'default' | 'medium' | 'small';
|
size?: 'default' | 'medium' | 'small';
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
import { useTransition } from 'react';
|
||||||
|
import { Button, type ButtonProps } from './Button';
|
||||||
|
|
||||||
|
export function LoadingButton({ href, onClick, className, ...rest }: ButtonProps & { onClick: () => Promise<void> }) {
|
||||||
|
const [isPending, startTransition] = useTransition();
|
||||||
|
|
||||||
|
const handleClick = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
startTransition(onClick);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return <Button className={tcls(className, isPending ? 'animate-pulse' : '')} {...rest} onClick={handleClick} />
|
||||||
|
}
|
||||||
@@ -8,3 +8,4 @@ export * from './StyledLink';
|
|||||||
export * from './DateRelative';
|
export * from './DateRelative';
|
||||||
export * from './Emoji';
|
export * from './Emoji';
|
||||||
export * from './LoadingPane';
|
export * from './LoadingPane';
|
||||||
|
export * from './LoadingButton';
|
||||||
@@ -6,6 +6,7 @@ import { headers } from 'next/headers';
|
|||||||
export async function shouldTrackEvents(): Promise<boolean> {
|
export async function shouldTrackEvents(): Promise<boolean> {
|
||||||
const headersList = await headers();
|
const headersList = await headers();
|
||||||
|
|
||||||
|
return true;
|
||||||
if (
|
if (
|
||||||
process.env.NODE_ENV === 'development' ||
|
process.env.NODE_ENV === 'development' ||
|
||||||
(process.env.GITBOOK_BLOCK_PAGE_VIEWS_TRACKING &&
|
(process.env.GITBOOK_BLOCK_PAGE_VIEWS_TRACKING &&
|
||||||
|
|||||||
@@ -270,6 +270,22 @@ async function getDataFetcherV1(): Promise<GitBookDataFetcher> {
|
|||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getAction(params) {
|
||||||
|
return wrapDataFetcherError(async () => {
|
||||||
|
console.log('fetching', params.url);
|
||||||
|
const url = new URL(params.url);
|
||||||
|
Object.keys(params.claims).forEach((key) => {
|
||||||
|
url.searchParams.append(key, params.claims[key]);
|
||||||
|
});
|
||||||
|
const result = await fetch(url.toString());
|
||||||
|
console.log('fetched', result.statusText)
|
||||||
|
if (!result) {
|
||||||
|
throw new DataFetcherError('Action not found', 404);
|
||||||
|
}
|
||||||
|
return await result.json();
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return dataFetcher;
|
return dataFetcher;
|
||||||
|
|||||||
@@ -1,13 +1,5 @@
|
|||||||
# @gitbook/react-openapi
|
# @gitbook/react-openapi
|
||||||
|
|
||||||
## 1.1.9
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- da7b369: Fix missing headers in OpenAPIResponses
|
|
||||||
- da485f5: Fix read-only in generateSchemaExample
|
|
||||||
- 139a805: Fix OpenAPI enum display
|
|
||||||
|
|
||||||
## 1.1.8
|
## 1.1.8
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"default": "./dist/index.js"
|
"default": "./dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version": "1.1.9",
|
"version": "1.1.8",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@gitbook/openapi-parser": "workspace:*",
|
"@gitbook/openapi-parser": "workspace:*",
|
||||||
|
|||||||
@@ -268,7 +268,6 @@ function getExamplesFromMediaTypeObject(args: {
|
|||||||
value: {
|
value: {
|
||||||
[root]: generateSchemaExample(mediaTypeObject.schema, {
|
[root]: generateSchemaExample(mediaTypeObject.schema, {
|
||||||
xml: mediaType === 'application/xml',
|
xml: mediaType === 'application/xml',
|
||||||
mode: 'read',
|
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -278,11 +277,7 @@ function getExamplesFromMediaTypeObject(args: {
|
|||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
key: 'default',
|
key: 'default',
|
||||||
example: {
|
example: { value: generateSchemaExample(mediaTypeObject.schema) },
|
||||||
value: generateSchemaExample(mediaTypeObject.schema, {
|
|
||||||
mode: 'read',
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,14 @@ export function generateSchemaExample(
|
|||||||
schema: OpenAPIV3.SchemaObject,
|
schema: OpenAPIV3.SchemaObject,
|
||||||
options?: GenerateSchemaExampleOptions
|
options?: GenerateSchemaExampleOptions
|
||||||
): JSONValue | undefined {
|
): JSONValue | undefined {
|
||||||
return getExampleFromSchema(schema, {
|
return getExampleFromSchema(
|
||||||
emptyString: 'text',
|
schema,
|
||||||
...options,
|
{
|
||||||
});
|
emptyString: 'text',
|
||||||
|
...options,
|
||||||
|
},
|
||||||
|
3 // Max depth for circular references
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,6 +103,21 @@ function guessFromFormat(schema: Record<string, any>, fallback = '') {
|
|||||||
return genericExampleValues[schema.format] ?? fallback;
|
return genericExampleValues[schema.format] ?? fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Map of all the results */
|
||||||
|
const resultCache = new WeakMap<Record<string, any>, any>();
|
||||||
|
|
||||||
|
/** Store result in the cache, and return the result */
|
||||||
|
function cache(schema: Record<string, any>, result: unknown) {
|
||||||
|
// Avoid unnecessary WeakMap operations for primitive values
|
||||||
|
if (typeof result !== 'object' || result === null) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
resultCache.set(schema, result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function takes an OpenAPI schema and generates an example from it
|
* This function takes an OpenAPI schema and generates an example from it
|
||||||
* Forked from : https://github.com/scalar/scalar/blob/main/packages/oas-utils/src/spec-getters/getExampleFromSchema.ts
|
* Forked from : https://github.com/scalar/scalar/blob/main/packages/oas-utils/src/spec-getters/getExampleFromSchema.ts
|
||||||
@@ -133,20 +152,8 @@ const getExampleFromSchema = (
|
|||||||
},
|
},
|
||||||
level = 0,
|
level = 0,
|
||||||
parentSchema?: Record<string, any>,
|
parentSchema?: Record<string, any>,
|
||||||
name?: string,
|
name?: string
|
||||||
resultCache = new WeakMap<Record<string, any>, any>()
|
|
||||||
): any => {
|
): any => {
|
||||||
// Store result in the cache, and return the result
|
|
||||||
function cache(schema: Record<string, any>, result: unknown) {
|
|
||||||
// Avoid unnecessary WeakMap operations for primitive values
|
|
||||||
if (typeof result !== 'object' || result === null) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
resultCache.set(schema, result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the result is already cached
|
// Check if the result is already cached
|
||||||
if (resultCache.has(schema)) {
|
if (resultCache.has(schema)) {
|
||||||
return resultCache.get(schema);
|
return resultCache.get(schema);
|
||||||
@@ -238,8 +245,7 @@ const getExampleFromSchema = (
|
|||||||
options,
|
options,
|
||||||
level + 1,
|
level + 1,
|
||||||
schema,
|
schema,
|
||||||
propertyName,
|
propertyName
|
||||||
resultCache
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (typeof response[propertyXmlTagName ?? propertyName] === 'undefined') {
|
if (typeof response[propertyXmlTagName ?? propertyName] === 'undefined') {
|
||||||
@@ -263,8 +269,7 @@ const getExampleFromSchema = (
|
|||||||
options,
|
options,
|
||||||
level + 1,
|
level + 1,
|
||||||
schema,
|
schema,
|
||||||
exampleKey,
|
exampleKey
|
||||||
resultCache
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,51 +290,21 @@ const getExampleFromSchema = (
|
|||||||
response.ANY_ADDITIONAL_PROPERTY = getExampleFromSchema(
|
response.ANY_ADDITIONAL_PROPERTY = getExampleFromSchema(
|
||||||
schema.additionalProperties,
|
schema.additionalProperties,
|
||||||
options,
|
options,
|
||||||
level + 1,
|
level + 1
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
resultCache
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schema.anyOf !== undefined) {
|
if (schema.anyOf !== undefined) {
|
||||||
Object.assign(
|
Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1));
|
||||||
response,
|
|
||||||
getExampleFromSchema(
|
|
||||||
schema.anyOf[0],
|
|
||||||
options,
|
|
||||||
level + 1,
|
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
resultCache
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else if (schema.oneOf !== undefined) {
|
} else if (schema.oneOf !== undefined) {
|
||||||
Object.assign(
|
Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1));
|
||||||
response,
|
|
||||||
getExampleFromSchema(
|
|
||||||
schema.oneOf[0],
|
|
||||||
options,
|
|
||||||
level + 1,
|
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
resultCache
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else if (schema.allOf !== undefined) {
|
} else if (schema.allOf !== undefined) {
|
||||||
Object.assign(
|
Object.assign(
|
||||||
response,
|
response,
|
||||||
...schema.allOf
|
...schema.allOf
|
||||||
.map((item: Record<string, any>) =>
|
.map((item: Record<string, any>) =>
|
||||||
getExampleFromSchema(
|
getExampleFromSchema(item, options, level + 1, schema)
|
||||||
item,
|
|
||||||
options,
|
|
||||||
level + 1,
|
|
||||||
schema,
|
|
||||||
undefined,
|
|
||||||
resultCache
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.filter((item: any) => item !== undefined)
|
.filter((item: any) => item !== undefined)
|
||||||
);
|
);
|
||||||
@@ -360,9 +335,7 @@ const getExampleFromSchema = (
|
|||||||
{ type: 'object', allOf: schema.items.allOf },
|
{ type: 'object', allOf: schema.items.allOf },
|
||||||
options,
|
options,
|
||||||
level + 1,
|
level + 1,
|
||||||
schema,
|
schema
|
||||||
undefined,
|
|
||||||
resultCache
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return cache(
|
return cache(
|
||||||
@@ -373,14 +346,7 @@ const getExampleFromSchema = (
|
|||||||
// For non-objects (like strings), collect all examples
|
// For non-objects (like strings), collect all examples
|
||||||
const examples = schema.items.allOf
|
const examples = schema.items.allOf
|
||||||
.map((item: Record<string, any>) =>
|
.map((item: Record<string, any>) =>
|
||||||
getExampleFromSchema(
|
getExampleFromSchema(item, options, level + 1, schema)
|
||||||
item,
|
|
||||||
options,
|
|
||||||
level + 1,
|
|
||||||
schema,
|
|
||||||
undefined,
|
|
||||||
resultCache
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.filter((item: any) => item !== undefined);
|
.filter((item: any) => item !== undefined);
|
||||||
|
|
||||||
@@ -402,14 +368,7 @@ const getExampleFromSchema = (
|
|||||||
const schemas = schema.items[rule].slice(0, 1);
|
const schemas = schema.items[rule].slice(0, 1);
|
||||||
const exampleFromRule = schemas
|
const exampleFromRule = schemas
|
||||||
.map((item: Record<string, any>) =>
|
.map((item: Record<string, any>) =>
|
||||||
getExampleFromSchema(
|
getExampleFromSchema(item, options, level + 1, schema)
|
||||||
item,
|
|
||||||
options,
|
|
||||||
level + 1,
|
|
||||||
schema,
|
|
||||||
undefined,
|
|
||||||
resultCache
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.filter((item: any) => item !== undefined);
|
.filter((item: any) => item !== undefined);
|
||||||
|
|
||||||
@@ -421,14 +380,7 @@ const getExampleFromSchema = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (schema.items?.type) {
|
if (schema.items?.type) {
|
||||||
const exampleFromSchema = getExampleFromSchema(
|
const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1);
|
||||||
schema.items,
|
|
||||||
options,
|
|
||||||
level + 1,
|
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
resultCache
|
|
||||||
);
|
|
||||||
|
|
||||||
return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema];
|
return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema];
|
||||||
}
|
}
|
||||||
@@ -455,14 +407,7 @@ const getExampleFromSchema = (
|
|||||||
const firstOneOfItem = discriminateSchema[0];
|
const firstOneOfItem = discriminateSchema[0];
|
||||||
|
|
||||||
// Return an example for the first item
|
// Return an example for the first item
|
||||||
return getExampleFromSchema(
|
return getExampleFromSchema(firstOneOfItem, options, level + 1);
|
||||||
firstOneOfItem,
|
|
||||||
options,
|
|
||||||
level + 1,
|
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
resultCache
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if schema has the `allOf` key
|
// Check if schema has the `allOf` key
|
||||||
@@ -472,14 +417,7 @@ const getExampleFromSchema = (
|
|||||||
// Loop through all `allOf` schemas
|
// Loop through all `allOf` schemas
|
||||||
schema.allOf.forEach((allOfItem: Record<string, any>) => {
|
schema.allOf.forEach((allOfItem: Record<string, any>) => {
|
||||||
// Return an example from the schema
|
// Return an example from the schema
|
||||||
const newExample = getExampleFromSchema(
|
const newExample = getExampleFromSchema(allOfItem, options, level + 1);
|
||||||
allOfItem,
|
|
||||||
options,
|
|
||||||
level + 1,
|
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
resultCache
|
|
||||||
);
|
|
||||||
|
|
||||||
// Merge or overwrite the example
|
// Merge or overwrite the example
|
||||||
example =
|
example =
|
||||||
|
|||||||
Reference in New Issue
Block a user