fumadocs-openapi 11.2.0 → 11.2.1

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.
@@ -1,29 +1,29 @@
1
1
  import { getPreferredType, pickExample } from "./schema.js";
2
2
  import { encodeRequestData } from "../requests/media/encode.js";
3
+ import { dereferenceShallow } from "@fumadocs/api-docs/schema/dereference";
4
+ import { getRaw } from "@scalar/json-magic/magic-proxy";
3
5
  import { sample } from "@fumadocs/api-docs/schema/sample";
4
6
  //#region src/utils/get-example-requests.ts
5
7
  function getExampleRequests({ path, method, ctx, operation, pathItem }) {
6
- const { resolve } = ctx.schema;
7
- const requestBody = resolve(operation.requestBody);
8
+ const requestBody = dereferenceShallow(operation.requestBody);
8
9
  const media = requestBody?.content ? getPreferredType(requestBody.content) : null;
9
- const bodyOfType = media ? resolve(requestBody.content[media]) : null;
10
- const parameters = [...operation.parameters ?? [], ...pathItem.parameters ?? []].map((param) => resolve(param));
10
+ const bodyOfType = media ? dereferenceShallow(requestBody.content[media]) : null;
11
+ const parameters = [...operation.parameters ?? [], ...pathItem.parameters ?? []].map(dereferenceShallow);
11
12
  if (bodyOfType?.examples) {
12
13
  const result = [];
13
14
  for (const [key, item] of Object.entries(bodyOfType.examples)) {
14
- const value = resolve(item);
15
+ const { summary, description } = dereferenceShallow(item);
15
16
  const data = getRequestData({
16
17
  path,
17
18
  body: requestBody,
18
19
  parameters,
19
20
  sampleKey: key,
20
- method,
21
- resolve
21
+ method
22
22
  });
23
23
  result.push({
24
24
  id: key,
25
- name: value.summary || key,
26
- description: value.description,
25
+ name: summary || key,
26
+ description,
27
27
  data,
28
28
  encoded: encodeRequestData(data, ctx.mediaAdapters, parameters)
29
29
  });
@@ -34,10 +34,9 @@ function getExampleRequests({ path, method, ctx, operation, pathItem }) {
34
34
  path,
35
35
  body: requestBody,
36
36
  method,
37
- parameters,
38
- resolve
37
+ parameters
39
38
  });
40
- const schema = bodyOfType ? resolve(bodyOfType.schema) : void 0;
39
+ const schema = dereferenceShallow(bodyOfType?.schema);
41
40
  return [{
42
41
  id: "_default",
43
42
  name: "Default",
@@ -46,7 +45,7 @@ function getExampleRequests({ path, method, ctx, operation, pathItem }) {
46
45
  encoded: encodeRequestData(data, ctx.mediaAdapters, parameters)
47
46
  }];
48
47
  }
49
- function getRequestData({ method, path, parameters, sampleKey, body, resolve }) {
48
+ function getRequestData({ method, path, parameters, sampleKey, body }) {
50
49
  const result = {
51
50
  path: {},
52
51
  cookie: {},
@@ -60,7 +59,7 @@ function getRequestData({ method, path, parameters, sampleKey, body, resolve })
60
59
  if (param.schema) value = sample(param.schema);
61
60
  else if (param.content) {
62
61
  const type = getPreferredType(param.content);
63
- const content = type ? resolve(param.content[type]) : void 0;
62
+ const content = type ? dereferenceShallow(param.content[type]) : void 0;
64
63
  if (!content || !content.schema) throw new Error(`Cannot find "${param.name}" parameter info for media type "${type}" in ${path} ${method}`);
65
64
  value = sample(content.schema);
66
65
  }
@@ -82,10 +81,10 @@ function getRequestData({ method, path, parameters, sampleKey, body, resolve })
82
81
  const type = getPreferredType(body.content);
83
82
  if (!type) throw new Error(`Cannot find body schema for ${path} ${method}: missing media type`);
84
83
  result.bodyMediaType = type;
85
- const bodyOfType = resolve(body.content[type]);
86
- if (bodyOfType.examples && sampleKey) result.body = resolve(bodyOfType.examples[sampleKey]).value;
87
- else if (bodyOfType.example) result.body = bodyOfType.example;
88
- else result.body = sample(resolve(bodyOfType?.schema) ?? {}, {
84
+ const bodyOfType = dereferenceShallow(body.content[type]);
85
+ if (bodyOfType.examples && sampleKey) result.body = getRaw(dereferenceShallow(bodyOfType.examples[sampleKey]).value);
86
+ else if (bodyOfType.example) result.body = getRaw(bodyOfType.example);
87
+ else result.body = sample(bodyOfType?.schema ?? {}, {
89
88
  skipReadOnly: method !== "get",
90
89
  skipWriteOnly: method === "get",
91
90
  skipNonRequired: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "11.2.0",
3
+ "version": "11.2.1",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "Docs",
@@ -56,8 +56,8 @@
56
56
  "remark-rehype": "^11.1.2",
57
57
  "shiki": "^4.3.1",
58
58
  "yaml": "^2.9.0",
59
- "@fumari/stf": "1.1.0",
60
- "@fumadocs/api-docs": "0.2.0"
59
+ "@fumadocs/api-docs": "0.2.0",
60
+ "@fumari/stf": "1.1.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@scalar/api-client-react": "^2.0.32",
@@ -69,9 +69,9 @@
69
69
  "json-schema-typed": "^8.0.2",
70
70
  "tsdown": "0.22.5",
71
71
  "xml-js": "^1.6.11",
72
- "fumadocs-ui": "npm:@fumadocs/base-ui@16.11.4",
73
72
  "tsconfig": "0.0.0",
74
- "fumadocs-core": "16.11.4"
73
+ "fumadocs-core": "16.11.5",
74
+ "fumadocs-ui": "npm:@fumadocs/base-ui@16.11.5"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "@scalar/api-client-react": "^2.0.20",