fumadocs-openapi 5.11.1 → 5.11.3

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.
package/dist/index.d.ts CHANGED
@@ -73,7 +73,6 @@ interface ResponseProps {
73
73
  interface APIInfoProps {
74
74
  method: string;
75
75
  route: string;
76
- baseUrls: string[];
77
76
  head: ReactNode;
78
77
  children: ReactNode;
79
78
  }
@@ -100,6 +99,7 @@ interface ResponseTypeProps {
100
99
  }
101
100
  interface RootProps {
102
101
  baseUrl?: string;
102
+ servers: ServerObject[];
103
103
  children: ReactNode;
104
104
  }
105
105
  interface Renderer {
@@ -178,12 +178,7 @@ type SecuritySchemeObject = OpenAPIV3_1.SecuritySchemeObject;
178
178
  type ReferenceObject = OpenAPIV3_1.ReferenceObject;
179
179
  type PathItemObject = OpenAPIV3_1.PathItemObject;
180
180
  type TagObject = OpenAPIV3_1.TagObject;
181
- interface RouteInformation {
182
- path: string;
183
- summary?: string;
184
- description?: string;
185
- methods: MethodInformation[];
186
- }
181
+ type ServerObject = NoReference<OpenAPIV3_1.ServerObject>;
187
182
  type MethodInformation = NoReference<OperationObject> & {
188
183
  method: string;
189
184
  };
@@ -203,7 +198,7 @@ interface RenderContext {
203
198
  */
204
199
  document: NoReference<Document>;
205
200
  baseUrl: string;
206
- baseUrls: string[];
201
+ servers: ServerObject[];
207
202
  slugger: Slugger;
208
203
  dereferenceMap: DereferenceMap;
209
204
  /**
@@ -322,4 +317,4 @@ interface Config extends GenerateOptions {
322
317
  }
323
318
  declare function generateFiles(options: Config): Promise<void>;
324
319
 
325
- export { type Config, type DereferenceMap, type Document, type GenerateOptions, type GeneratePageOutput, type GenerateTagOutput, type MethodInformation, type OperationObject, type ParameterObject, type PathItemObject, type ReferenceObject, type RenderContext, type RouteInformation, type SecurityRequirementObject, type SecuritySchemeObject, type TagObject, generateAll, generateFiles, generatePages, generateTags };
320
+ export { type Config, type DereferenceMap, type Document, type GenerateOptions, type GeneratePageOutput, type GenerateTagOutput, type MethodInformation, type OperationObject, type ParameterObject, type PathItemObject, type ReferenceObject, type RenderContext, type SecurityRequirementObject, type SecuritySchemeObject, type ServerObject, type TagObject, generateAll, generateFiles, generatePages, generateTags };
@@ -75,7 +75,6 @@ interface ResponseProps {
75
75
  interface APIInfoProps {
76
76
  method: string;
77
77
  route: string;
78
- baseUrls: string[];
79
78
  head: ReactNode;
80
79
  children: ReactNode;
81
80
  }
@@ -102,6 +101,7 @@ interface ResponseTypeProps {
102
101
  }
103
102
  interface RootProps {
104
103
  baseUrl?: string;
104
+ servers: ServerObject[];
105
105
  children: ReactNode;
106
106
  }
107
107
  interface Renderer {
@@ -174,6 +174,7 @@ interface CodeSample {
174
174
 
175
175
  type Document = OpenAPIV3_1.Document;
176
176
  type ReferenceObject = OpenAPIV3_1.ReferenceObject;
177
+ type ServerObject = NoReference<OpenAPIV3_1.ServerObject>;
177
178
  type Awaitable<T> = T | Promise<T>;
178
179
  /**
179
180
  * Dereferenced value and its original `$ref` value
@@ -190,7 +191,7 @@ interface RenderContext {
190
191
  */
191
192
  document: NoReference<Document>;
192
193
  baseUrl: string;
193
- baseUrls: string[];
194
+ servers: ServerObject[];
194
195
  slugger: Slugger;
195
196
  dereferenceMap: DereferenceMap;
196
197
  /**
@@ -24,26 +24,6 @@ function getPreferredType(body) {
24
24
  if ('application/json' in body) return 'application/json';
25
25
  return Object.keys(body)[0];
26
26
  }
27
- /**
28
- * Convert input to string (with quotes)
29
- */ function inputToString(value, mediaType = 'application/json', multiLine = 'none') {
30
- const getStr = (v)=>{
31
- if (multiLine === 'none') return JSON.stringify(v);
32
- const delimit = multiLine === 'backtick' ? `\`` : `'`;
33
- return `${delimit}${v.replaceAll(delimit, `\\${delimit}`)}${delimit}`;
34
- };
35
- if (typeof value === 'string') return getStr(value);
36
- if (mediaType === 'application/json' || mediaType === 'multipart/form-data') {
37
- return getStr(JSON.stringify(value, null, 2));
38
- }
39
- if (mediaType === 'application/xml') {
40
- return getStr(js2xml(value, {
41
- compact: true,
42
- spaces: 2
43
- }));
44
- }
45
- throw new Error(`Unsupported media type: ${mediaType}`);
46
- }
47
27
  function isNullable(schema, includeOneOf = true) {
48
28
  if (Array.isArray(schema.type) && schema.type.includes('null')) return true;
49
29
  if (includeOneOf && (schema.anyOf || schema.oneOf)) {
@@ -159,6 +139,27 @@ function generateBody(method, schema) {
159
139
  });
160
140
  }
161
141
 
142
+ /**
143
+ * Convert input value to hardcoded string (with quotes)
144
+ */ function inputToString(value, mediaType = 'application/json', multiLine = 'none') {
145
+ const getStr = (v)=>{
146
+ if (multiLine === 'none') return JSON.stringify(v);
147
+ const delimit = multiLine === 'backtick' ? `\`` : `'`;
148
+ return `${delimit}${v.replaceAll(delimit, `\\${delimit}`)}${delimit}`;
149
+ };
150
+ if (typeof value === 'string') return getStr(value);
151
+ if (mediaType === 'application/json' || mediaType === 'multipart/form-data') {
152
+ return getStr(JSON.stringify(value, null, 2));
153
+ }
154
+ if (mediaType === 'application/xml') {
155
+ return getStr(js2xml(value, {
156
+ compact: true,
157
+ spaces: 2
158
+ }));
159
+ }
160
+ throw new Error(`Unsupported media type: ${mediaType}`);
161
+ }
162
+
162
163
  function getSampleRequest$3(endpoint) {
163
164
  const s = [];
164
165
  s.push(`curl -X ${endpoint.method} "${endpoint.url}"`);
@@ -791,7 +792,6 @@ const methodKeys = [
791
792
  ];
792
793
 
793
794
  function Operation({ type = 'operation', path, method, ctx, hasHead, headingLevel = 2 }) {
794
- const { baseUrls } = ctx;
795
795
  const body = method.requestBody;
796
796
  const security = method.security ?? ctx.document.security;
797
797
  let headNode = null;
@@ -906,7 +906,6 @@ function Operation({ type = 'operation', path, method, ctx, hasHead, headingLeve
906
906
  head: headNode,
907
907
  method: method.method,
908
908
  route: path,
909
- baseUrls: type === 'operation' ? baseUrls : [],
910
909
  children: [
911
910
  type === 'operation' ? /*#__PURE__*/ jsx(Playground, {
912
911
  path: path,
@@ -1252,6 +1251,14 @@ const cache = new Map();
1252
1251
  return processed;
1253
1252
  }
1254
1253
 
1254
+ function getUrl(url, variables) {
1255
+ let out = url;
1256
+ for (const [key, value] of Object.entries(variables)){
1257
+ out = out.replaceAll(`{${key}}`, value);
1258
+ }
1259
+ return out;
1260
+ }
1261
+
1255
1262
  async function APIPage(props) {
1256
1263
  const { operations, hasHead = true, webhooks, disableCache = process.env.NODE_ENV === 'development' } = props;
1257
1264
  const processed = await processDocument(props.document, disableCache);
@@ -1259,6 +1266,7 @@ async function APIPage(props) {
1259
1266
  const { document } = processed;
1260
1267
  return /*#__PURE__*/ jsxs(ctx.renderer.Root, {
1261
1268
  baseUrl: ctx.baseUrl,
1269
+ servers: ctx.servers,
1262
1270
  children: [
1263
1271
  operations?.map((item)=>{
1264
1272
  const pathItem = document.paths?.[item.path];
@@ -1294,6 +1302,12 @@ async function APIPage(props) {
1294
1302
  });
1295
1303
  }
1296
1304
  async function getContext({ document, dereferenceMap }, options = {}) {
1305
+ const servers = document.servers && document.servers.length > 0 ? document.servers : [
1306
+ {
1307
+ url: 'https://example.com'
1308
+ }
1309
+ ];
1310
+ const server = servers[0];
1297
1311
  return {
1298
1312
  document: document,
1299
1313
  dereferenceMap,
@@ -1305,8 +1319,11 @@ async function getContext({ document, dereferenceMap }, options = {}) {
1305
1319
  shikiOptions: options.shikiOptions,
1306
1320
  generateTypeScriptSchema: options.generateTypeScriptSchema,
1307
1321
  generateCodeSamples: options.generateCodeSamples,
1308
- baseUrl: document.servers?.[0].url ?? 'https://example.com',
1309
- baseUrls: document.servers?.map((s)=>s.url) ?? [],
1322
+ baseUrl: getUrl(server.url, server.variables ? Object.fromEntries(Object.entries(server.variables).map(([k, v])=>[
1323
+ k,
1324
+ v.default
1325
+ ])) : {}),
1326
+ servers,
1310
1327
  slugger: new Slugger()
1311
1328
  };
1312
1329
  }