fumadocs-openapi 10.0.11 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/dist/generate-file.d.ts +6 -5
  2. package/dist/generate-file.d.ts.map +1 -1
  3. package/dist/generate-file.js +44 -37
  4. package/dist/playground/client.d.ts +9 -7
  5. package/dist/playground/client.d.ts.map +1 -1
  6. package/dist/playground/client.js +7 -7
  7. package/dist/playground/components/inputs.d.ts +6 -6
  8. package/dist/playground/components/inputs.d.ts.map +1 -1
  9. package/dist/playground/components/inputs.js +13 -12
  10. package/dist/playground/get-default-values.d.ts +2 -2
  11. package/dist/playground/get-default-values.d.ts.map +1 -1
  12. package/dist/playground/index.d.ts +1 -2
  13. package/dist/playground/index.d.ts.map +1 -1
  14. package/dist/playground/index.js +2 -0
  15. package/dist/playground/schema.d.ts +22 -8
  16. package/dist/playground/schema.d.ts.map +1 -1
  17. package/dist/playground/schema.js +29 -34
  18. package/dist/requests/generators/index.d.ts +1 -1
  19. package/dist/requests/generators/index.d.ts.map +1 -1
  20. package/dist/server/create.d.ts +1 -1
  21. package/dist/server/create.d.ts.map +1 -1
  22. package/dist/server/source-api.d.ts +5 -3
  23. package/dist/server/source-api.d.ts.map +1 -1
  24. package/dist/server/source-api.js +13 -7
  25. package/dist/types.d.ts +3 -3
  26. package/dist/types.d.ts.map +1 -1
  27. package/dist/ui/api-page.d.ts +16 -8
  28. package/dist/ui/api-page.d.ts.map +1 -1
  29. package/dist/ui/api-page.js +7 -7
  30. package/dist/ui/client/index.d.ts +2 -2
  31. package/dist/ui/client/index.d.ts.map +1 -1
  32. package/dist/ui/operation/index.d.ts +4 -3
  33. package/dist/ui/operation/index.d.ts.map +1 -1
  34. package/dist/ui/operation/index.js +37 -20
  35. package/dist/ui/operation/request-tabs.d.ts +18 -0
  36. package/dist/ui/operation/request-tabs.d.ts.map +1 -0
  37. package/dist/ui/operation/request-tabs.js +143 -0
  38. package/dist/ui/operation/response-tabs.d.ts +32 -0
  39. package/dist/ui/operation/response-tabs.d.ts.map +1 -0
  40. package/dist/ui/operation/response-tabs.js +59 -0
  41. package/dist/ui/operation/usage-tabs/client.d.ts +23 -0
  42. package/dist/ui/operation/usage-tabs/client.d.ts.map +1 -0
  43. package/dist/ui/operation/{example-panel → usage-tabs}/client.js +50 -6
  44. package/dist/ui/operation/usage-tabs/index.d.ts +26 -0
  45. package/dist/ui/operation/usage-tabs/index.d.ts.map +1 -0
  46. package/dist/ui/operation/usage-tabs/index.js +52 -0
  47. package/dist/ui/operation/usage-tabs/lazy.d.ts +4 -0
  48. package/dist/ui/operation/usage-tabs/lazy.d.ts.map +1 -0
  49. package/dist/ui/operation/usage-tabs/lazy.js +5 -0
  50. package/dist/ui/schema/client.d.ts +1 -3
  51. package/dist/ui/schema/client.d.ts.map +1 -1
  52. package/dist/ui/schema/client.js +13 -17
  53. package/dist/ui/schema/index.d.ts +19 -5
  54. package/dist/ui/schema/index.d.ts.map +1 -1
  55. package/dist/ui/schema/index.js +69 -29
  56. package/dist/utils/deep-equal.d.ts +2 -0
  57. package/dist/utils/deep-equal.d.ts.map +1 -0
  58. package/dist/utils/deep-equal.js +27 -0
  59. package/dist/utils/merge-schema.d.ts +7 -0
  60. package/dist/utils/merge-schema.d.ts.map +1 -0
  61. package/dist/utils/merge-schema.js +179 -0
  62. package/dist/utils/pages/to-body.d.ts.map +1 -1
  63. package/dist/utils/pages/to-body.js +2 -3
  64. package/dist/utils/pages/to-text.d.ts.map +1 -1
  65. package/dist/utils/pages/to-text.js +31 -16
  66. package/dist/utils/schema-to-string.d.ts.map +1 -1
  67. package/dist/utils/schema-to-string.js +8 -5
  68. package/dist/utils/use-query.d.ts +1 -0
  69. package/dist/utils/use-query.d.ts.map +1 -1
  70. package/dist/utils/use-query.js +5 -0
  71. package/package.json +8 -8
  72. package/dist/ui/contexts/operation.d.ts +0 -20
  73. package/dist/ui/contexts/operation.d.ts.map +0 -1
  74. package/dist/ui/contexts/operation.js +0 -48
  75. package/dist/ui/contexts/operation.lazy.d.ts +0 -2
  76. package/dist/ui/contexts/operation.lazy.d.ts.map +0 -1
  77. package/dist/ui/contexts/operation.lazy.js +0 -3
  78. package/dist/ui/operation/example-panel/client.d.ts +0 -4
  79. package/dist/ui/operation/example-panel/client.d.ts.map +0 -1
  80. package/dist/ui/operation/example-panel/index.d.ts +0 -58
  81. package/dist/ui/operation/example-panel/index.d.ts.map +0 -1
  82. package/dist/ui/operation/example-panel/index.js +0 -140
  83. package/dist/ui/operation/example-panel/lazy.d.ts +0 -3
  84. package/dist/ui/operation/example-panel/lazy.d.ts.map +0 -1
  85. package/dist/ui/operation/example-panel/lazy.js +0 -4
  86. package/dist/ui/operation/get-request-data.d.ts +0 -4
  87. package/dist/ui/operation/get-request-data.d.ts.map +0 -1
  88. package/dist/ui/operation/get-request-data.js +0 -70
  89. package/dist/utils/combine-schema.d.ts +0 -6
  90. package/dist/utils/combine-schema.d.ts.map +0 -1
  91. package/dist/utils/combine-schema.js +0 -51
@@ -1,48 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { createContext, use, useMemo, useRef, useState, } from 'react';
4
- const OperationContext = createContext(null);
5
- export function OperationProvider({ route, examples, defaultExampleId, children, }) {
6
- const [example, setExample] = useState(() => defaultExampleId ?? examples.at(0)?.id);
7
- const listeners = useRef([]);
8
- return (_jsx(OperationContext, { value: useMemo(() => ({
9
- example,
10
- route,
11
- setExample: (newKey) => {
12
- const example = examples.find((example) => example.id === newKey);
13
- if (!example)
14
- return;
15
- setExample(newKey);
16
- for (const listener of listeners.current) {
17
- listener(example.data, example.encoded);
18
- }
19
- },
20
- examples,
21
- setExampleData: (data, encoded) => {
22
- for (const item of examples) {
23
- if (item.id === example) {
24
- // persistent changes
25
- item.data = data;
26
- item.encoded = encoded;
27
- break;
28
- }
29
- }
30
- for (const listener of listeners.current) {
31
- listener(data, encoded);
32
- }
33
- },
34
- removeListener: (listener) => {
35
- listeners.current = listeners.current.filter((item) => item !== listener);
36
- },
37
- addListener: (listener) => {
38
- // initial call to listeners to ensure their data is the latest
39
- // this is necessary to avoid race conditions between `useEffect()`
40
- const active = examples.find((item) => item.id === example);
41
- listener(active.data, active.encoded);
42
- listeners.current.push(listener);
43
- },
44
- }), [example, route, examples]), children: children }));
45
- }
46
- export function useOperationContext() {
47
- return use(OperationContext);
48
- }
@@ -1,2 +0,0 @@
1
- export declare const OperationProviderLazy: typeof import("./operation.js").OperationProvider;
2
- //# sourceMappingURL=operation.lazy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"operation.lazy.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/operation.lazy.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,gDAEjC,CAAC"}
@@ -1,3 +0,0 @@
1
- 'use client';
2
- import { wrapLazy } from '../../utils/lazy.js';
3
- export const OperationProviderLazy = wrapLazy(() => import('./operation.js').then((mod) => ({ default: mod.OperationProvider })));
@@ -1,4 +0,0 @@
1
- import type { CodeUsageGenerator } from './index.js';
2
- export declare function APIExampleSelector(): import("react/jsx-runtime").JSX.Element | null;
3
- export declare function APIExampleUsageTab(sample: CodeUsageGenerator): import("react/jsx-runtime").JSX.Element | null;
4
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/ui/operation/example-panel/client.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAkB,kBAAkB,EAAE,MAAM,GAAG,CAAC;AAE5D,wBAAgB,kBAAkB,mDAkCjC;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,kDAkD5D"}
@@ -1,58 +0,0 @@
1
- import type { MethodInformation, RenderContext, ResponseObject } from '../../../types.js';
2
- import type { ReactNode } from 'react';
3
- import { type NoReference } from '../../../utils/schema.js';
4
- import type { RawRequestData, RequestData, SampleGenerator } from '../../../requests/types.js';
5
- /**
6
- * Generate code example for given programming language
7
- */
8
- export interface CodeUsageGenerator<T = unknown> {
9
- id: string;
10
- lang: string;
11
- label?: string;
12
- /**
13
- * either:
14
- * - code
15
- * - a function imported from a file with "use client" directive
16
- * - false (disabled)
17
- */
18
- source?: string | SampleGenerator<T> | false;
19
- /**
20
- * Pass extra context to client-side source generator
21
- */
22
- serverContext?: T;
23
- }
24
- export interface APIExampleItem {
25
- id: string;
26
- name: string;
27
- description?: string;
28
- data: RawRequestData;
29
- encoded: RequestData;
30
- }
31
- export interface ResponseTab {
32
- /**
33
- * HTTP response code
34
- */
35
- code: string;
36
- response: NoReference<ResponseObject>;
37
- /**
38
- * media type of response
39
- */
40
- mediaType: string | null;
41
- examples?: {
42
- /**
43
- * generated/defined example data
44
- */
45
- sample: unknown;
46
- label: string;
47
- /**
48
- * description (in Markdown)
49
- */
50
- description?: string;
51
- }[];
52
- }
53
- export declare function getAPIExamples(path: string, method: MethodInformation, ctx: RenderContext): APIExampleItem[];
54
- export declare function APIExample({ method, ctx, }: {
55
- method: MethodInformation;
56
- ctx: RenderContext;
57
- }): Promise<import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | (string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined)>;
58
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ui/operation/example-panel/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGpE,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAmB1B;;GAEG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,OAAO;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;IAE7C;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb,QAAQ,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC;IACtC;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzB,QAAQ,CAAC,EAAE;QACT;;WAEG;QACH,MAAM,EAAE,OAAO,CAAC;QAEhB,KAAK,EAAE,MAAM,CAAC;QAEd;;WAEG;QACH,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,EAAE,CAAC;CACL;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,GAAG,EAAE,aAAa,GACjB,cAAc,EAAE,CA0ClB;AAED,wBAAsB,UAAU,CAAC,EAC/B,MAAM,EACN,GAAG,GACJ,EAAE;IACD,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;CACpB,wUAmEA"}
@@ -1,140 +0,0 @@
1
- import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { getPreferredType } from '../../../utils/schema.js';
3
- import { getRequestData } from '../../../ui/operation/get-request-data.js';
4
- import { sample } from 'openapi-sampler';
5
- import { defaultSamples } from '../../../requests/generators/index.js';
6
- import { encodeRequestData } from '../../../requests/media/encode.js';
7
- import { AccordionContent, AccordionHeader, AccordionItem, Accordions, AccordionTrigger, } from '../../../ui/components/accordion.js';
8
- import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
9
- import { CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger, } from 'fumadocs-ui/components/codeblock';
10
- import { APIExampleSelectorLazy, APIExampleUsageTabLazy } from './lazy.js';
11
- export function getAPIExamples(path, method, ctx) {
12
- const media = method.requestBody
13
- ? getPreferredType(method.requestBody.content)
14
- : null;
15
- const bodyOfType = media ? method.requestBody?.content[media] : null;
16
- if (bodyOfType?.examples) {
17
- const result = [];
18
- for (const [key, value] of Object.entries(bodyOfType.examples)) {
19
- const data = getRequestData(path, method, key, ctx);
20
- result.push({
21
- id: key,
22
- name: value.summary ?? key,
23
- description: value.description,
24
- data,
25
- encoded: encodeRequestData(data, ctx.mediaAdapters, method.parameters ?? []),
26
- });
27
- }
28
- if (result.length > 0)
29
- return result;
30
- }
31
- const data = getRequestData(path, method, null, ctx);
32
- return [
33
- {
34
- id: '_default',
35
- name: 'Default',
36
- description: bodyOfType?.schema?.description,
37
- data,
38
- encoded: encodeRequestData(data, ctx.mediaAdapters, method.parameters ?? []),
39
- },
40
- ];
41
- }
42
- export async function APIExample({ method, ctx, }) {
43
- let { renderAPIExampleUsageTabs, renderAPIExampleLayout } = ctx.content ?? {};
44
- renderAPIExampleLayout ?? (renderAPIExampleLayout = (slots) => {
45
- return (_jsxs("div", { className: "prose-no-margin md:sticky md:top-(--fd-api-info-top) xl:w-[400px]", children: [slots.selector, slots.usageTabs, slots.responseTabs] }));
46
- });
47
- renderAPIExampleUsageTabs ?? (renderAPIExampleUsageTabs = (generators) => {
48
- if (generators.length === 0)
49
- return null;
50
- return (_jsxs(CodeBlockTabs, { groupId: "fumadocs_openapi_requests", defaultValue: generators[0].id, children: [_jsx(CodeBlockTabsList, { children: generators.map((item) => (_jsx(CodeBlockTabsTrigger, { value: item.id, children: item.label ?? item.lang }, item.id))) }), generators.map((item) => (_jsx(CodeBlockTab, { value: item.id, children: _jsx(APIExampleUsageTabLazy, { ...item }) }, item.id)))] }));
51
- });
52
- let generators = [...defaultSamples];
53
- if (ctx.generateCodeSamples) {
54
- generators.push(...(await ctx.generateCodeSamples(method)));
55
- }
56
- if (method['x-codeSamples']) {
57
- for (const sample of method['x-codeSamples']) {
58
- generators.push('id' in sample && typeof sample.id === 'string'
59
- ? sample
60
- : {
61
- id: sample.lang,
62
- ...sample,
63
- });
64
- }
65
- }
66
- generators = dedupe(generators);
67
- return renderAPIExampleLayout({
68
- selector: method['x-exclusiveCodeSample'] ? null : (_jsx(APIExampleSelectorLazy, {})),
69
- usageTabs: await renderAPIExampleUsageTabs(generators, ctx),
70
- responseTabs: _jsx(ResponseTabs, { operation: method, ctx: ctx }),
71
- }, ctx);
72
- }
73
- /**
74
- * Remove duplicated ids
75
- */
76
- function dedupe(samples) {
77
- const set = new Set();
78
- const out = [];
79
- for (let i = samples.length - 1; i >= 0; i--) {
80
- const item = samples[i];
81
- if (set.has(item.id))
82
- continue;
83
- set.add(item.id);
84
- if (item.source !== false)
85
- out.unshift(item);
86
- }
87
- return out;
88
- }
89
- function ResponseTabs({ operation, ctx, }) {
90
- if (!operation.responses)
91
- return null;
92
- const tabs = [];
93
- for (const [code, response] of Object.entries(operation.responses)) {
94
- const media = response.content ? getPreferredType(response.content) : null;
95
- const responseOfType = media ? response.content?.[media] : null;
96
- const tab = {
97
- code,
98
- response,
99
- mediaType: media,
100
- };
101
- if (responseOfType?.examples) {
102
- tab.examples ?? (tab.examples = []);
103
- for (const [key, sample] of Object.entries(responseOfType.examples)) {
104
- const title = sample?.summary ?? `Example ${key}`;
105
- tab.examples.push({
106
- label: title,
107
- sample: sample.value,
108
- description: sample?.description,
109
- });
110
- }
111
- }
112
- else if (responseOfType?.example || responseOfType?.schema) {
113
- tab.examples ?? (tab.examples = []);
114
- tab.examples.push({
115
- label: 'Example',
116
- sample: responseOfType.example ?? sample(responseOfType.schema),
117
- });
118
- }
119
- tabs.push(tab);
120
- }
121
- const { renderResponseTabs = renderResponseTabsDefault } = ctx.content ?? {};
122
- return renderResponseTabs(tabs, ctx);
123
- }
124
- function renderResponseTabsDefault(tabs, ctx) {
125
- async function renderResponse(tab) {
126
- const { examples = [] } = tab;
127
- let slot = 'Empty';
128
- if (examples.length > 1) {
129
- slot = (_jsx(Accordions, { type: "single", className: "pt-2", defaultValue: examples[0].label, children: examples.map((example, i) => (_jsxs(AccordionItem, { value: example.label, children: [_jsx(AccordionHeader, { children: _jsx(AccordionTrigger, { children: example.label }) }), _jsxs(AccordionContent, { className: "prose-no-margin", children: [example.description && ctx.renderMarkdown(example.description), ctx.renderCodeBlock('json', JSON.stringify(example.sample, null, 2))] })] }, i))) }));
130
- }
131
- else if (examples.length === 1) {
132
- const example = examples[0];
133
- slot = (_jsxs(_Fragment, { children: [example.description && ctx.renderMarkdown(example.description), ctx.renderCodeBlock('json', JSON.stringify(example.sample, null, 2))] }));
134
- }
135
- return _jsx(Tab, { value: tab.code, children: slot });
136
- }
137
- if (tabs.length === 0)
138
- return null;
139
- return (_jsx(Tabs, { groupId: "fumadocs_openapi_responses", items: tabs.map((tab) => tab.code), children: tabs.map(renderResponse) }));
140
- }
@@ -1,3 +0,0 @@
1
- export declare const APIExampleSelectorLazy: typeof import("./client.js").APIExampleSelector;
2
- export declare const APIExampleUsageTabLazy: typeof import("./client.js").APIExampleUsageTab;
3
- //# sourceMappingURL=lazy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../../../../src/ui/operation/example-panel/lazy.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,sBAAsB,8CAElC,CAAC;AAEF,eAAO,MAAM,sBAAsB,8CAElC,CAAC"}
@@ -1,4 +0,0 @@
1
- 'use client';
2
- import { wrapLazy } from '../../../utils/lazy.js';
3
- export const APIExampleSelectorLazy = wrapLazy(() => import('./client.js').then((mod) => ({ default: mod.APIExampleSelector })));
4
- export const APIExampleUsageTabLazy = wrapLazy(() => import('./client.js').then((mod) => ({ default: mod.APIExampleUsageTab })));
@@ -1,4 +0,0 @@
1
- import type { MethodInformation, RenderContext } from '../../types.js';
2
- import type { RawRequestData } from '../../requests/types.js';
3
- export declare function getRequestData(path: string, method: MethodInformation, sampleKey: string | null, _ctx: RenderContext): RawRequestData;
4
- //# sourceMappingURL=get-request-data.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-request-data.d.ts","sourceRoot":"","sources":["../../../src/ui/operation/get-request-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIhE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,IAAI,EAAE,aAAa,GAClB,cAAc,CAwEhB"}
@@ -1,70 +0,0 @@
1
- import { getPreferredType } from '../../utils/schema.js';
2
- import { sample } from 'openapi-sampler';
3
- export function getRequestData(path, method, sampleKey, _ctx) {
4
- const result = {
5
- path: {},
6
- cookie: {},
7
- header: {},
8
- query: {},
9
- method: method.method,
10
- };
11
- for (const param of method.parameters ?? []) {
12
- let schema = param.schema;
13
- let value;
14
- if (!schema && param.content) {
15
- const type = getPreferredType(param.content);
16
- const content = type ? param.content[type] : undefined;
17
- if (!content || !content.schema)
18
- throw new Error(`Cannot find parameter schema for ${param.name} in ${path} ${method.method}`);
19
- schema = content.schema;
20
- value = content.example ?? param.example;
21
- }
22
- else {
23
- value = param.example;
24
- }
25
- if (param.required) {
26
- value ?? (value = sample(schema));
27
- }
28
- else if (value === undefined) {
29
- continue;
30
- }
31
- switch (param.in) {
32
- case 'cookie':
33
- result.cookie[param.name] = value;
34
- break;
35
- case 'header':
36
- result.header[param.name] = value;
37
- break;
38
- case 'query':
39
- result.query[param.name] = value;
40
- break;
41
- default:
42
- result.path[param.name] = value;
43
- }
44
- }
45
- if (method.requestBody) {
46
- const body = method.requestBody.content;
47
- const type = getPreferredType(body);
48
- if (!type)
49
- throw new Error(`Cannot find body schema for ${path} ${method.method}: missing media type`);
50
- result.bodyMediaType = type;
51
- const bodyOfType = body[type];
52
- if (bodyOfType.examples && sampleKey) {
53
- result.body = bodyOfType.examples[sampleKey].value;
54
- }
55
- else if (bodyOfType.example) {
56
- result.body = bodyOfType.example;
57
- }
58
- else {
59
- result.body = generateBody(method.method, (bodyOfType?.schema ?? {}));
60
- }
61
- }
62
- return result;
63
- }
64
- function generateBody(method, schema) {
65
- return sample(schema, {
66
- skipReadOnly: method !== 'GET',
67
- skipWriteOnly: method === 'GET',
68
- skipNonRequired: true,
69
- });
70
- }
@@ -1,6 +0,0 @@
1
- import { type ParsedSchema } from '../utils/schema.js';
2
- /**
3
- * Combine multiple object schemas into one
4
- */
5
- export declare function combineSchema(schema: ParsedSchema[]): ParsedSchema;
6
- //# sourceMappingURL=combine-schema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"combine-schema.d.ts","sourceRoot":"","sources":["../../src/utils/combine-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAuDlE"}
@@ -1,51 +0,0 @@
1
- /**
2
- * Combine multiple object schemas into one
3
- */
4
- export function combineSchema(schema) {
5
- let result = {};
6
- const types = new Set();
7
- const title = new Set();
8
- function add(s) {
9
- if (typeof s === 'boolean') {
10
- result = s;
11
- return;
12
- }
13
- if (typeof result === 'boolean')
14
- return;
15
- if (s.title)
16
- title.add(s.title);
17
- if (s.type) {
18
- for (const v of Array.isArray(s.type) ? s.type : [s.type]) {
19
- types.add(v);
20
- }
21
- }
22
- for (const key of ['oneOf', 'required', 'enum']) {
23
- if (!s[key])
24
- continue;
25
- result[key] = [...s[key], ...(result[key] ?? [])];
26
- }
27
- for (const key of ['properties', 'patternProperties']) {
28
- if (!s[key])
29
- continue;
30
- result[key] ?? (result[key] = {});
31
- Object.assign(result[key], s[key]);
32
- }
33
- if (s.additionalProperties === true) {
34
- result.additionalProperties = true;
35
- }
36
- else if (s.additionalProperties &&
37
- typeof result.additionalProperties !== 'boolean') {
38
- result.additionalProperties ?? (result.additionalProperties = {});
39
- Object.assign(result.additionalProperties, s.additionalProperties);
40
- }
41
- (s.allOf ?? s.anyOf)?.forEach(add);
42
- }
43
- schema.forEach(add);
44
- if (title.size > 0)
45
- result.title = Array.from(title).join(' & ');
46
- if (types.size > 0) {
47
- const typeArr = Array.from(types.values());
48
- result.type = typeArr.length === 1 ? typeArr[0] : typeArr;
49
- }
50
- return result;
51
- }