fumadocs-openapi 9.0.1 → 9.0.2

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.
@@ -65,7 +65,7 @@ export default function Client({ route, method = 'GET', authorization, parameter
65
65
  const value = _value;
66
66
  if (authorization && value.authorization) {
67
67
  authInfo.saveInfo(value.authorization);
68
- writeAuthHeader(authorization, value.authorization, value.header, value.query, value.cookie);
68
+ writeAuthInfo(authorization, value.authorization, value.header, value.query, value.cookie);
69
69
  }
70
70
  requestData.saveData(toRequestData(method, body?.mediaType, value));
71
71
  });
@@ -85,38 +85,61 @@ function FormBody({ authorization, parameters = [], fields = {}, body, }) {
85
85
  const params = useMemo(() => {
86
86
  return paramTypes.map((param) => parameters.filter((v) => v.in === param));
87
87
  }, [parameters]);
88
- function renderAuth() {
88
+ const auth = useMemo(() => {
89
89
  if (!authorization)
90
- return null;
91
- const schema = authorization.type === 'http' && authorization.scheme === 'basic'
92
- ? {
93
- type: 'object',
94
- required: ['username', 'password'],
95
- properties: {
96
- username: {
97
- type: 'string',
98
- },
99
- password: {
100
- type: 'string',
90
+ return;
91
+ if (authorization.type === 'http' && authorization.scheme === 'basic') {
92
+ return {
93
+ in: 'header',
94
+ field: {
95
+ type: 'object',
96
+ required: ['username', 'password'],
97
+ description: authorization.description,
98
+ properties: {
99
+ username: {
100
+ type: 'string',
101
+ },
102
+ password: {
103
+ type: 'string',
104
+ },
101
105
  },
102
106
  },
103
- }
104
- : {
105
- type: 'string',
106
- description: 'The Authorization access token',
107
107
  };
108
+ }
109
+ else if (authorization.type === 'http' ||
110
+ authorization.type === 'oauth2') {
111
+ return {
112
+ in: 'header',
113
+ field: {
114
+ type: 'string',
115
+ description: authorization.description ?? `The Authorization access token.`,
116
+ },
117
+ };
118
+ }
119
+ else if (authorization.type === 'apiKey') {
120
+ return {
121
+ in: authorization.in,
122
+ field: {
123
+ type: 'string',
124
+ description: authorization.description ?? 'The API key.',
125
+ },
126
+ };
127
+ }
128
+ // TODO: handle OpenID connect
129
+ }, [authorization]);
130
+ function renderAuth() {
131
+ if (!auth)
132
+ return null;
108
133
  if (fields?.auth)
109
- return renderCustomField('authorization', schema, fields.auth);
110
- return (_jsx(FieldSet, { fieldName: "authorization", name: "Authorization", field: schema, isRequired: true }));
134
+ return renderCustomField('authorization', auth.field, fields.auth);
135
+ return (_jsx(FieldSet, { fieldName: "authorization", name: "Authorization", field: auth.field, isRequired: true }));
111
136
  }
112
137
  return (_jsxs(_Fragment, { children: [params.map((param, i) => {
113
138
  const name = paramNames[i];
114
139
  const type = paramTypes[i];
115
- if (type !== 'header' && param.length === 0)
116
- return;
117
- if (type === 'header' && !authorization && param.length === 0)
140
+ if ((!auth || type !== auth.in) && param.length === 0)
118
141
  return;
119
- return (_jsxs(CollapsiblePanel, { title: name, children: [type === 'header' ? renderAuth() : null, param.map((field) => {
142
+ return (_jsxs(CollapsiblePanel, { title: name, children: [auth && type === auth.in ? renderAuth() : null, param.map((field) => {
120
143
  const fieldName = `${type}.${field.name}`;
121
144
  if (fields?.parameter) {
122
145
  return renderCustomField(fieldName, field.schema, fields.parameter, field.name);
@@ -209,7 +232,7 @@ function usePersistentAuthInfo(authorization) {
209
232
  function CollapsiblePanel({ title, children, ...props }) {
210
233
  return (_jsxs(Collapsible, { ...props, className: "border-b last:border-b-0", children: [_jsxs(CollapsibleTrigger, { className: "group w-full flex items-center gap-2 p-3 text-sm font-medium", children: [title, _jsx(ChevronDown, { className: "ms-auto size-3.5 text-fd-muted-foreground group-data-[state=open]:rotate-180" })] }), _jsx(CollapsibleContent, { children: _jsx("div", { className: "flex flex-col gap-3 p-3 pt-1", children: children }) })] }));
211
234
  }
212
- function writeAuthHeader(authorization, input, header, query, cookie) {
235
+ function writeAuthInfo(authorization, input, header, query, cookie) {
213
236
  if (authorization.type === 'apiKey') {
214
237
  if (authorization.in === 'header') {
215
238
  header[authorization.name] = input;
@@ -1 +1 @@
1
- {"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../src/playground/fetcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/B,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;CACvE;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GACrC,OAAO,CAyFT"}
1
+ {"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../src/playground/fetcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/B,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;CACvE;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GACrC,OAAO,CAkGT"}
@@ -13,23 +13,6 @@ export function createBrowserFetcher(adapters) {
13
13
  const proxyUrl = options.proxyUrl
14
14
  ? new URL(options.proxyUrl, window.location.origin)
15
15
  : null;
16
- if (typeof document !== 'undefined') {
17
- for (const key in options.cookie) {
18
- const value = options.cookie[key];
19
- if (!value)
20
- continue;
21
- document.cookie = [
22
- `${key}=${value}`,
23
- 'HttpOnly',
24
- proxyUrl &&
25
- proxyUrl.origin !== window.location.origin &&
26
- `domain=${proxyUrl.host}`,
27
- 'path=/',
28
- ]
29
- .filter(Boolean)
30
- .join(';');
31
- }
32
- }
33
16
  let url = getPathnameFromInput(route, options.path, options.query);
34
17
  if (proxyUrl) {
35
18
  proxyUrl.searchParams.append('url', url);
@@ -46,6 +29,29 @@ export function createBrowserFetcher(adapters) {
46
29
  };
47
30
  body = await adapter.encode(options);
48
31
  }
32
+ // cookies
33
+ for (const key in options.cookie) {
34
+ const value = options.cookie[key];
35
+ if (!value)
36
+ continue;
37
+ const cookie = {
38
+ [key]: value,
39
+ domain: proxyUrl && proxyUrl.origin !== window.location.origin
40
+ ? `domain=${proxyUrl.host}`
41
+ : undefined,
42
+ path: '/',
43
+ 'max-age': 30,
44
+ };
45
+ let str = '';
46
+ for (const [key, value] of Object.entries(cookie)) {
47
+ if (value) {
48
+ if (str.length > 0)
49
+ str += '; ';
50
+ str += `${key}=${value}`;
51
+ }
52
+ }
53
+ document.cookie = str;
54
+ }
49
55
  return fetch(url, {
50
56
  method: options.method,
51
57
  cache: 'no-cache',
@@ -81,7 +81,7 @@ function getAuthorizationField(method, { schema: { document } }) {
81
81
  item = requirements;
82
82
  }
83
83
  if (!item) {
84
- console.warn(`Cannot find suitable security scheme for API Playground from ${JSON.stringify(security, null, 2)}. Only schemes with one requirement are allowed.`);
84
+ console.warn(`Cannot find suitable security scheme for API Playground from ${JSON.stringify(security, null, 2)}. Only schemes with one requirement are allowed at the moment.`);
85
85
  return;
86
86
  }
87
87
  const scheme = getSecurities(item, document)[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "9.0.1",
3
+ "version": "9.0.2",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -63,8 +63,8 @@
63
63
  "shiki": "^3.4.2",
64
64
  "tinyglobby": "^0.2.13",
65
65
  "xml-js": "^1.6.11",
66
- "fumadocs-core": "15.4.0",
67
- "fumadocs-ui": "15.4.0"
66
+ "fumadocs-core": "15.4.1",
67
+ "fumadocs-ui": "15.4.1"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@scalar/api-client-react": "^1.3.3",
@@ -77,8 +77,8 @@
77
77
  "openapi-types": "^12.1.3",
78
78
  "tailwindcss": "^4.1.7",
79
79
  "tsc-alias": "^1.8.16",
80
- "tsconfig": "0.0.0",
81
- "eslint-config-custom": "0.0.0"
80
+ "eslint-config-custom": "0.0.0",
81
+ "tsconfig": "0.0.0"
82
82
  },
83
83
  "peerDependencies": {
84
84
  "@scalar/api-client-react": "*",