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,14 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { FormatFlags, schemaToString } from '../../utils/schema-to-string.js';
3
- import { combineSchema } from '../../utils/combine-schema.js';
3
+ import { mergeAllOf } from '../../utils/merge-schema.js';
4
4
  import { SchemaUILazy } from '../../ui/schema/lazy.js';
5
- export function Schema({ ctx, root, ...props }) {
5
+ export function Schema({ ctx, ...options }) {
6
6
  if (ctx.schemaUI?.render) {
7
- return ctx.schemaUI.render({ root, ...props }, ctx);
7
+ return ctx.schemaUI.render(options, ctx);
8
8
  }
9
- return (_jsx(SchemaUILazy, { ...props, generated: generateSchemaUI({ ctx, root }) }));
9
+ return (_jsx(SchemaUILazy, { ...options.client, generated: generateSchemaUI(options, ctx) }));
10
10
  }
11
- export function generateSchemaUI({ ctx, root, }) {
11
+ export function generateSchemaUI({ root, readOnly, writeOnly }, ctx) {
12
12
  const refs = {};
13
13
  const { showExample = false } = ctx.schemaUI ?? {};
14
14
  function generateInfoTags(schema) {
@@ -65,6 +65,15 @@ export function generateSchemaUI({ ctx, root, }) {
65
65
  autoIds.set(schema, generated);
66
66
  return generated;
67
67
  }
68
+ function isVisible(schema) {
69
+ if (typeof schema === 'boolean')
70
+ return true;
71
+ if (schema.writeOnly)
72
+ return writeOnly ?? false;
73
+ if (schema.readOnly)
74
+ return readOnly ?? false;
75
+ return true;
76
+ }
68
77
  function base(schema) {
69
78
  if (typeof schema === 'boolean') {
70
79
  const name = schema ? 'any' : 'never';
@@ -79,8 +88,6 @@ export function generateSchemaUI({ ctx, root, }) {
79
88
  typeName: schemaToString(schema, ctx.schema),
80
89
  aliasName: schemaToString(schema, ctx.schema, FormatFlags.UseAlias),
81
90
  deprecated: schema.deprecated,
82
- readOnly: schema.readOnly,
83
- writeOnly: schema.writeOnly,
84
91
  };
85
92
  }
86
93
  function scanRefs(id, schema) {
@@ -101,12 +108,11 @@ export function generateSchemaUI({ ctx, root, }) {
101
108
  };
102
109
  refs[id] = out;
103
110
  for (const type of schema.type) {
104
- const item = {
111
+ const key = `${id}_type:${type}`;
112
+ scanRefs(key, {
105
113
  ...schema,
106
114
  type,
107
- };
108
- const key = `${id}_type:${type}`;
109
- scanRefs(key, item);
115
+ });
110
116
  out.items.push({
111
117
  name: type,
112
118
  $type: key,
@@ -114,34 +120,64 @@ export function generateSchemaUI({ ctx, root, }) {
114
120
  }
115
121
  return;
116
122
  }
117
- if (schema.oneOf) {
123
+ if (schema.oneOf && schema.anyOf) {
124
+ const out = {
125
+ type: 'and',
126
+ items: [],
127
+ ...base(schema),
128
+ };
129
+ refs[id] = out;
130
+ const $oneOf = `${id}_oneOf`;
131
+ const $anyOf = `${id}_anyOf`;
132
+ scanRefs($oneOf, {
133
+ ...schema,
134
+ anyOf: undefined,
135
+ });
136
+ scanRefs($anyOf, {
137
+ ...schema,
138
+ oneOf: undefined,
139
+ });
140
+ out.items.push({
141
+ name: refs[$oneOf].aliasName,
142
+ $type: $oneOf,
143
+ }, {
144
+ name: refs[$anyOf].aliasName,
145
+ $type: $anyOf,
146
+ });
147
+ return;
148
+ }
149
+ // display both `oneOf` & `anyOf` as OR for simplified overview
150
+ const union = schema.oneOf ?? schema.anyOf;
151
+ if (union) {
118
152
  const out = {
119
153
  type: 'or',
120
154
  items: [],
121
155
  ...base(schema),
122
156
  };
123
157
  refs[id] = out;
124
- for (const item of schema.oneOf) {
125
- if (typeof item !== 'object')
158
+ for (const item of union) {
159
+ if (typeof item !== 'object' || !isVisible(item))
126
160
  continue;
127
161
  const key = `${id}_extends:${getSchemaId(item)}`;
128
- const extended = {
162
+ scanRefs(key, {
129
163
  ...schema,
164
+ oneOf: undefined,
165
+ anyOf: undefined,
130
166
  ...item,
131
- };
132
- delete extended['oneOf'];
133
- scanRefs(key, extended);
167
+ properties: {
168
+ ...schema.properties,
169
+ ...item.properties,
170
+ },
171
+ });
134
172
  out.items.push({
135
173
  $type: key,
136
- name: schemaToString(extended, ctx.schema, FormatFlags.UseAlias),
174
+ name: refs[key].aliasName,
137
175
  });
138
176
  }
139
177
  return;
140
178
  }
141
- const of = schema.allOf ?? schema.anyOf;
142
- if (of) {
143
- const combined = combineSchema(of);
144
- scanRefs(id, combined);
179
+ if (schema.allOf) {
180
+ scanRefs(id, mergeAllOf(schema));
145
181
  return;
146
182
  }
147
183
  if (schema.type === 'object') {
@@ -151,10 +187,13 @@ export function generateSchemaUI({ ctx, root, }) {
151
187
  ...base(schema),
152
188
  };
153
189
  refs[id] = out;
154
- const props = Object.entries(schema.properties ?? {});
155
- if (schema.patternProperties)
156
- props.push(...Object.entries(schema.patternProperties));
190
+ const { properties = {}, patternProperties, additionalProperties, } = schema;
191
+ const props = Object.entries(properties);
192
+ if (patternProperties)
193
+ props.push(...Object.entries(patternProperties));
157
194
  for (const [key, prop] of props) {
195
+ if (!isVisible(prop))
196
+ continue;
158
197
  const $type = getSchemaId(prop);
159
198
  scanRefs($type, prop);
160
199
  out.props.push({
@@ -163,9 +202,10 @@ export function generateSchemaUI({ ctx, root, }) {
163
202
  required: schema.required?.includes(key) ?? false,
164
203
  });
165
204
  }
166
- if (schema.additionalProperties) {
167
- const $type = getSchemaId(schema.additionalProperties);
168
- scanRefs($type, schema.additionalProperties);
205
+ if (additionalProperties !== undefined &&
206
+ isVisible(additionalProperties)) {
207
+ const $type = getSchemaId(additionalProperties);
208
+ scanRefs($type, additionalProperties);
169
209
  out.props.push({
170
210
  $type,
171
211
  name: '[key: string]',
@@ -0,0 +1,2 @@
1
+ export declare function deepEqual(a: unknown, b: unknown): boolean;
2
+ //# sourceMappingURL=deep-equal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-equal.d.ts","sourceRoot":"","sources":["../../src/utils/deep-equal.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAuCzD"}
@@ -0,0 +1,27 @@
1
+ export function deepEqual(a, b) {
2
+ if (a === b) {
3
+ return true;
4
+ }
5
+ if (a == null || b == null) {
6
+ return false;
7
+ }
8
+ if (typeof a !== 'object' || typeof b !== 'object') {
9
+ return false;
10
+ }
11
+ if (Array.isArray(a) && Array.isArray(b)) {
12
+ if (a.length !== b.length) {
13
+ return false;
14
+ }
15
+ return a.every((item, index) => deepEqual(item, b[index]));
16
+ }
17
+ if (Array.isArray(a) || Array.isArray(b)) {
18
+ return false;
19
+ }
20
+ const keysA = Object.keys(a);
21
+ const keysB = Object.keys(b);
22
+ if (keysA.length !== keysB.length) {
23
+ return false;
24
+ }
25
+ return keysA.every((key) => Object.prototype.hasOwnProperty.call(b, key) &&
26
+ deepEqual(a[key], b[key]));
27
+ }
@@ -0,0 +1,7 @@
1
+ import { type ParsedSchema } from '../utils/schema.js';
2
+ /**
3
+ * Merge `allOf` object schema
4
+ */
5
+ export declare function mergeAllOf(schema: ParsedSchema): ParsedSchema;
6
+ export declare function intersection(a: ParsedSchema, b: ParsedSchema): ParsedSchema;
7
+ //# sourceMappingURL=merge-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-schema.d.ts","sourceRoot":"","sources":["../../src/utils/merge-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAS7D;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,YAAY,CAgJ3E"}
@@ -0,0 +1,179 @@
1
+ import { deepEqual } from './deep-equal.js';
2
+ /**
3
+ * Merge `allOf` object schema
4
+ */
5
+ export function mergeAllOf(schema) {
6
+ if (typeof schema === 'boolean' || !schema.allOf)
7
+ return schema;
8
+ const { allOf, ...rest } = schema;
9
+ let result = rest;
10
+ for (const item of allOf) {
11
+ result = intersection(result, item);
12
+ }
13
+ return result;
14
+ }
15
+ export function intersection(a, b) {
16
+ a = mergeAllOf(a);
17
+ b = mergeAllOf(b);
18
+ if (typeof a === 'boolean' && typeof b === 'boolean')
19
+ return a && b;
20
+ if (typeof a === 'boolean')
21
+ return a;
22
+ if (typeof b === 'boolean')
23
+ return b;
24
+ const result = { ...a };
25
+ for (const _k in b) {
26
+ const key = _k;
27
+ switch (key) {
28
+ case '$id':
29
+ case '$comment':
30
+ case 'description':
31
+ case 'additionalItems':
32
+ case 'examples':
33
+ case 'allOf':
34
+ case 'writeOnly':
35
+ case 'readOnly':
36
+ // ignored
37
+ break;
38
+ case 'title': {
39
+ const value = b[key];
40
+ if (value === undefined)
41
+ break;
42
+ if (result[key]) {
43
+ result[key] = `${result[key]} & ${value}`;
44
+ }
45
+ else {
46
+ result[key] = value;
47
+ }
48
+ break;
49
+ }
50
+ case 'minItems':
51
+ case 'minimum':
52
+ case 'exclusiveMinimum':
53
+ case 'minProperties':
54
+ case 'minContains':
55
+ case 'minLength': {
56
+ const value = b[key];
57
+ if (value === undefined)
58
+ break;
59
+ result[key] =
60
+ result[key] === undefined ? value : Math.max(result[key], value);
61
+ break;
62
+ }
63
+ case 'maxContains':
64
+ case 'maxItems':
65
+ case 'maxLength':
66
+ case 'maxProperties':
67
+ case 'maximum':
68
+ case 'exclusiveMaximum': {
69
+ const value = b[key];
70
+ if (value === undefined)
71
+ break;
72
+ result[key] =
73
+ result[key] === undefined ? value : Math.min(result[key], value);
74
+ break;
75
+ }
76
+ // intersection
77
+ case 'enum':
78
+ case 'anyOf':
79
+ case 'oneOf': {
80
+ const value = b[key];
81
+ if (value === undefined)
82
+ break;
83
+ result[key] =
84
+ result[key] === undefined
85
+ ? value
86
+ : intersectArray(result[key], value);
87
+ break;
88
+ }
89
+ // require same
90
+ case 'format':
91
+ case 'const':
92
+ case 'type': {
93
+ const value = b[key];
94
+ if (value === undefined)
95
+ break;
96
+ result[key] ?? (result[key] = value);
97
+ if (!deepEqual(result[key], value))
98
+ return false;
99
+ break;
100
+ }
101
+ // add
102
+ case 'required': {
103
+ const value = b[key];
104
+ if (value === undefined)
105
+ break;
106
+ result[key] = [...(result[key] ?? []), ...value];
107
+ break;
108
+ }
109
+ case 'properties':
110
+ case 'patternProperties': {
111
+ const value = b[key];
112
+ if (value === undefined)
113
+ break;
114
+ if (result[key] === undefined) {
115
+ result[key] = value;
116
+ break;
117
+ }
118
+ const out = {};
119
+ const allProps = new Set();
120
+ for (const k in result[key])
121
+ allProps.add(k);
122
+ for (const k in value)
123
+ allProps.add(k);
124
+ for (const prop of allProps) {
125
+ const aProp = result[key][prop];
126
+ const bProp = value[prop];
127
+ if (aProp === undefined) {
128
+ out[prop] = bProp;
129
+ }
130
+ else if (bProp === undefined) {
131
+ out[prop] = aProp;
132
+ }
133
+ else {
134
+ out[prop] = intersection(aProp, bProp);
135
+ }
136
+ }
137
+ result[key] = out;
138
+ break;
139
+ }
140
+ case 'additionalProperties':
141
+ case 'contains':
142
+ case 'items': {
143
+ const value = b[key];
144
+ if (value === undefined)
145
+ break;
146
+ result[key] =
147
+ result[key] === undefined ? value : intersection(result[key], value);
148
+ break;
149
+ }
150
+ case 'not': {
151
+ const value = b[key];
152
+ if (value === undefined)
153
+ break;
154
+ if (result[key] && value) {
155
+ result.not = { anyOf: [result[key], value] };
156
+ }
157
+ else if (value) {
158
+ result.not = value;
159
+ }
160
+ break;
161
+ }
162
+ default:
163
+ result[key] = b[key];
164
+ }
165
+ }
166
+ return result;
167
+ }
168
+ function intersectArray(a, b) {
169
+ const out = new Set();
170
+ for (const item of a) {
171
+ if (b.includes(item))
172
+ out.add(item);
173
+ }
174
+ for (const item of b) {
175
+ if (a.includes(item))
176
+ out.add(item);
177
+ }
178
+ return Array.from(out);
179
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"to-body.d.ts","sourceRoot":"","sources":["../../../src/utils/pages/to-body.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,YAAY,CAoBvD"}
1
+ {"version":3,"file":"to-body.d.ts","sourceRoot":"","sources":["../../../src/utils/pages/to-body.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,YAAY,CAmBvD"}
@@ -1,18 +1,17 @@
1
1
  export function toBody(entry) {
2
2
  if (entry.type === 'operation')
3
3
  return {
4
- hasHead: false,
5
4
  document: entry.schemaId,
6
5
  operations: [entry.item],
7
6
  };
8
7
  if (entry.type === 'webhook')
9
8
  return {
10
- hasHead: false,
11
9
  document: entry.schemaId,
12
10
  webhooks: [entry.item],
13
11
  };
14
12
  return {
15
- hasHead: true,
13
+ showTitle: true,
14
+ showDescription: true,
16
15
  document: entry.schemaId,
17
16
  operations: entry.operations,
18
17
  webhooks: entry.webhooks,
@@ -1 +1 @@
1
- {"version":3,"file":"to-text.d.ts","sourceRoot":"","sources":["../../../src/utils/pages/to-text.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,KAAK,EAAY,SAAS,EAAE,MAAM,SAAS,CAAC;AAKnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,CAAC,EAAE;QACR,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,EAAE,CAAC;IAEJ;;;;OAIG;IACH,WAAW,CAAC,EAAE,CACZ,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,OAAO,EAAE,eAAe,KACrB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE7B;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;;;;OAOG;IACH,mBAAmB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CACxC;AAED,wBAAgB,MAAM,CACpB,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,iBAAiB,EAC5B,OAAO,GAAE,kBAAuB,UAuEjC;AAED,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,OAAO,EACpB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,kBAAkB,GAC1B,MAAM,CA+BR;AAOD,MAAM,MAAM,eAAe,GACvB;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,SAAS,GAAG,SAAS,CAAC;CAC5B,GACD;IACE,IAAI,EAAE,WAAW,CAAC;CACnB,GACD;IACE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
1
+ {"version":3,"file":"to-text.d.ts","sourceRoot":"","sources":["../../../src/utils/pages/to-text.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,KAAK,EAAY,SAAS,EAAE,MAAM,SAAS,CAAC;AAKnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzD,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,CAAC,EAAE;QACR,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,EAAE,CAAC;IAEJ;;;;OAIG;IACH,WAAW,CAAC,EAAE,CACZ,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,OAAO,EAAE,eAAe,KACrB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE7B;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;;;;OAOG;IACH,mBAAmB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CACxC;AAED,wBAAgB,MAAM,CACpB,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,iBAAiB,EAC5B,OAAO,GAAE,kBAAuB,UAqEjC;AAED,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,OAAO,EACpB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,kBAAkB,GAC1B,MAAM,CA+BR;AAOD,MAAM,MAAM,eAAe,GACvB;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,SAAS,GAAG,SAAS,CAAC;CAC5B,GACD;IACE,IAAI,EAAE,WAAW,CAAC;CACnB,GACD;IACE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
@@ -7,7 +7,6 @@ export function toText(entry, processed, options = {}) {
7
7
  case 'operation':
8
8
  return generatePage(entry.schemaId, processed, {
9
9
  operations: [entry.item],
10
- hasHead: false,
11
10
  }, {
12
11
  ...options,
13
12
  ...entry.info,
@@ -18,7 +17,7 @@ export function toText(entry, processed, options = {}) {
18
17
  return generatePage(entry.schemaId, processed, {
19
18
  operations: entry.operations,
20
19
  webhooks: entry.webhooks,
21
- hasHead: true,
20
+ showTitle: true,
22
21
  }, {
23
22
  ...options,
24
23
  ...entry.info,
@@ -29,7 +28,7 @@ export function toText(entry, processed, options = {}) {
29
28
  return generatePage(entry.schemaId, processed, {
30
29
  operations: entry.operations,
31
30
  webhooks: entry.webhooks,
32
- hasHead: true,
31
+ showTitle: true,
33
32
  }, {
34
33
  ...options,
35
34
  ...entry.info,
@@ -40,7 +39,6 @@ export function toText(entry, processed, options = {}) {
40
39
  case 'webhook':
41
40
  return generatePage(entry.schemaId, processed, {
42
41
  webhooks: [entry.item],
43
- hasHead: false,
44
42
  }, {
45
43
  ...options,
46
44
  ...entry.info,
@@ -83,7 +81,13 @@ function generatePage(schemaId, processed, pageProps, options, context) {
83
81
  const operation = page.operations[0];
84
82
  meta = {
85
83
  method: operation.method.toUpperCase(),
86
- route: operation.path,
84
+ };
85
+ }
86
+ else if (page.webhooks?.length === 1) {
87
+ const webhook = page.webhooks[0];
88
+ meta = {
89
+ method: webhook.method.toUpperCase(),
90
+ webhook: true,
87
91
  };
88
92
  }
89
93
  const data = generateStaticData(processed.dereferenced, page);
@@ -111,7 +115,7 @@ function generateStaticData(dereferenced, props) {
111
115
  const operation = dereferenced.paths?.[item.path]?.[item.method];
112
116
  if (!operation)
113
117
  continue;
114
- if (props.hasHead && operation.operationId) {
118
+ if (props.showTitle && operation.operationId) {
115
119
  const title = operation.summary ??
116
120
  (operation.operationId ? idToTitle(operation.operationId) : item.path);
117
121
  const id = slugger.slug(title);
@@ -133,15 +137,26 @@ function generateStaticData(dereferenced, props) {
133
137
  }
134
138
  return { toc, structuredData };
135
139
  }
136
- function pageContent(props) {
140
+ function pageContent({ showTitle, showDescription, document, webhooks, operations, }) {
141
+ const propStrs = [`document={${JSON.stringify(document)}}`];
137
142
  // filter extra properties in props
138
- const operations = (props.operations ?? []).map((item) => ({
139
- path: item.path,
140
- method: item.method,
141
- }));
142
- const webhooks = (props.webhooks ?? []).map((item) => ({
143
- name: item.name,
144
- method: item.method,
145
- }));
146
- return `<APIPage document={${JSON.stringify(props.document)}} operations={${JSON.stringify(operations)}} webhooks={${JSON.stringify(webhooks)}} hasHead={${JSON.stringify(props.hasHead)}} />`;
143
+ if (webhooks) {
144
+ propStrs.push(`webhooks={${JSON.stringify(webhooks.map((item) => ({
145
+ name: item.name,
146
+ method: item.method,
147
+ })))}}`);
148
+ }
149
+ if (operations) {
150
+ propStrs.push(`operations={${JSON.stringify(operations.map((item) => ({
151
+ path: item.path,
152
+ method: item.method,
153
+ })))}}`);
154
+ }
155
+ if (showTitle) {
156
+ propStrs.push(`showTitle={${JSON.stringify(showTitle)}}`);
157
+ }
158
+ if (showDescription) {
159
+ propStrs.push(`showDescription={${JSON.stringify(showDescription)}}`);
160
+ }
161
+ return `<APIPage ${propStrs.join(' ')} />`;
147
162
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schema-to-string.d.ts","sourceRoot":"","sources":["../../src/utils/schema-to-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,oBAAY,WAAW;IACrB,IAAI,IAAI;IACR,QAAQ,IAAS;CAClB;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,cAAc,EACrB,GAAG,CAAC,EAAE,iBAAiB,EACvB,KAAK,GAAE,WAA8B,GACpC,MAAM,CAwER"}
1
+ {"version":3,"file":"schema-to-string.d.ts","sourceRoot":"","sources":["../../src/utils/schema-to-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,oBAAY,WAAW;IACrB,IAAI,IAAI;IACR,QAAQ,IAAS;CAClB;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,cAAc,EACrB,GAAG,CAAC,EAAE,iBAAiB,EACvB,KAAK,GAAE,WAA8B,GACpC,MAAM,CA0ER"}
@@ -39,12 +39,15 @@ export function schemaToString(value, ctx, flags = FormatFlags.None) {
39
39
  }
40
40
  if (schema.type === 'array')
41
41
  return `array<${schema.items ? run(schema.items, flags | FormatFlags.UseAlias) : 'unknown'}>`;
42
- if (schema.oneOf) {
43
- return union(schema.oneOf, ' | ', flags);
42
+ const or = schema.oneOf ?? schema.anyOf;
43
+ if (schema.oneOf && schema.anyOf) {
44
+ return `(${union(schema.oneOf, ' | ', flags)}) & (${union(schema.anyOf, ' | ', flags)})`;
44
45
  }
45
- const combinedOf = schema.anyOf ?? schema.allOf;
46
- if (combinedOf) {
47
- return union(combinedOf, ' & ', flags);
46
+ else if (or) {
47
+ return union(or, ' | ', flags);
48
+ }
49
+ if (schema.allOf) {
50
+ return union(schema.allOf, ' & ', flags);
48
51
  }
49
52
  if (schema.not)
50
53
  return `not ${run(schema.not, flags)}`;
@@ -1,5 +1,6 @@
1
1
  export declare function useQuery<I extends unknown[], T>(fn: (...input: I) => Promise<T>): {
2
2
  start: (...input: I) => void;
3
+ reset: () => void;
3
4
  data?: T;
4
5
  error?: unknown;
5
6
  isLoading: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"use-query.d.ts","sourceRoot":"","sources":["../../src/utils/use-query.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAC7C,EAAE,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC9B;IACD,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC7B,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;CACpB,CAgCA"}
1
+ {"version":3,"file":"use-query.d.ts","sourceRoot":"","sources":["../../src/utils/use-query.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAC7C,EAAE,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC9B;IACD,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC7B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;CACpB,CAqCA"}
@@ -25,5 +25,10 @@ export function useQuery(fn) {
25
25
  setLoading(false);
26
26
  });
27
27
  },
28
+ reset() {
29
+ setData(undefined);
30
+ setError(undefined);
31
+ setLoading(false);
32
+ },
28
33
  }), [error, data, loading]);
29
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "10.0.11",
3
+ "version": "10.1.0",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -59,7 +59,6 @@
59
59
  "ajv": "^8.17.1",
60
60
  "class-variance-authority": "^0.7.1",
61
61
  "github-slugger": "^2.0.0",
62
- "gray-matter": "^4.0.3",
63
62
  "hast-util-to-jsx-runtime": "^2.3.6",
64
63
  "js-yaml": "^4.1.1",
65
64
  "next-themes": "^0.4.6",
@@ -67,10 +66,7 @@
67
66
  "react-hook-form": "^7.66.0",
68
67
  "remark": "^15.0.1",
69
68
  "remark-rehype": "^11.1.2",
70
- "tinyglobby": "^0.2.15",
71
- "xml-js": "^1.6.11",
72
- "fumadocs-core": "16.1.0",
73
- "fumadocs-ui": "16.1.0"
69
+ "xml-js": "^1.6.11"
74
70
  },
75
71
  "devDependencies": {
76
72
  "@scalar/api-client-react": "^1.3.50",
@@ -82,10 +78,14 @@
82
78
  "openapi-types": "^12.1.3",
83
79
  "tailwindcss": "^4.1.17",
84
80
  "tsc-alias": "^1.8.16",
85
- "tsconfig": "0.0.0",
86
- "eslint-config-custom": "0.0.0"
81
+ "fumadocs-core": "16.2.0",
82
+ "fumadocs-ui": "16.2.0",
83
+ "eslint-config-custom": "0.0.0",
84
+ "tsconfig": "0.0.0"
87
85
  },
88
86
  "peerDependencies": {
87
+ "fumadocs-core": "^16.2.0",
88
+ "fumadocs-ui": "^16.2.0",
89
89
  "@scalar/api-client-react": "*",
90
90
  "@types/react": "*",
91
91
  "react": "^19.2.0",
@@ -1,20 +0,0 @@
1
- import { type ReactNode } from 'react';
2
- import type { APIExampleItem } from '../../ui/operation/example-panel/index.js';
3
- import type { RawRequestData, RequestData } from '../../requests/types.js';
4
- export type ExampleUpdateListener = (data: RawRequestData, encoded: RequestData) => void;
5
- export declare function OperationProvider({ route, examples, defaultExampleId, children, }: {
6
- route: string;
7
- examples: APIExampleItem[];
8
- defaultExampleId?: string;
9
- children: ReactNode;
10
- }): import("react/jsx-runtime").JSX.Element;
11
- export declare function useOperationContext(): {
12
- route: string;
13
- examples: APIExampleItem[];
14
- example: string | undefined;
15
- setExample: (id: string) => void;
16
- setExampleData: (data: RawRequestData, encoded: RequestData) => void;
17
- addListener: (listener: ExampleUpdateListener) => void;
18
- removeListener: (listener: ExampleUpdateListener) => void;
19
- };
20
- //# sourceMappingURL=operation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/operation.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,SAAS,EAKf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpE,MAAM,MAAM,qBAAqB,GAAG,CAClC,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,WAAW,KACjB,IAAI,CAAC;AAaV,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAwDA;AAED,wBAAgB,mBAAmB;WA9E1B,MAAM;cACH,cAAc,EAAE;aACjB,MAAM,GAAG,SAAS;gBACf,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI;oBAChB,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,WAAW,KAAK,IAAI;iBAEvD,CAAC,QAAQ,EAAE,qBAAqB,KAAK,IAAI;oBACtC,CAAC,QAAQ,EAAE,qBAAqB,KAAK,IAAI;EAyE1D"}