fumadocs-openapi 5.4.8 → 5.4.10

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
@@ -157,7 +157,7 @@ interface ParameterSample {
157
157
  interface CodeSample {
158
158
  lang: string;
159
159
  label: string;
160
- source?: string;
160
+ source: string | ((endpoint: EndpointSample) => string | undefined) | false;
161
161
  }
162
162
 
163
163
  interface RouteInformation {
@@ -158,7 +158,7 @@ interface ParameterSample {
158
158
  interface CodeSample {
159
159
  lang: string;
160
160
  label: string;
161
- source?: string;
161
+ source: string | ((endpoint: EndpointSample) => string | undefined) | false;
162
162
  }
163
163
 
164
164
  type Awaitable<T> = T | Promise<T>;
@@ -772,41 +772,54 @@ function Operation({ path, method, ctx, hasHead }) {
772
772
  ]
773
773
  });
774
774
  }
775
+ const defaultSamples = [
776
+ {
777
+ label: 'cURL',
778
+ source: getSampleRequest$3,
779
+ lang: 'bash'
780
+ },
781
+ {
782
+ label: 'JavaScript',
783
+ source: getSampleRequest$2,
784
+ lang: 'js'
785
+ },
786
+ {
787
+ label: 'Go',
788
+ source: getSampleRequest$1,
789
+ lang: 'go'
790
+ },
791
+ {
792
+ label: 'Python',
793
+ source: getSampleRequest,
794
+ lang: 'python'
795
+ }
796
+ ];
775
797
  async function APIExample({ method, endpoint, ctx }) {
776
798
  const renderer = ctx.renderer;
777
799
  const children = [];
778
800
  const samples = dedupe([
779
- {
780
- label: 'cURL',
781
- source: getSampleRequest$3(endpoint),
782
- lang: 'bash'
783
- },
784
- {
785
- label: 'JavaScript',
786
- source: getSampleRequest$2(endpoint),
787
- lang: 'js'
788
- },
789
- {
790
- label: 'Go',
791
- source: getSampleRequest$1(endpoint),
792
- lang: 'go'
793
- },
794
- {
795
- label: 'Python',
796
- source: getSampleRequest(endpoint),
797
- lang: 'python'
798
- },
801
+ ...defaultSamples,
799
802
  ...ctx.generateCodeSamples ? await ctx.generateCodeSamples(endpoint) : [],
800
803
  ...method['x-codeSamples'] ?? []
801
- ]).filter((item)=>item.source !== undefined);
802
- children.push(/*#__PURE__*/ jsx(renderer.Requests, {
803
- items: samples.map((s)=>s.label),
804
- children: samples.map((s)=>/*#__PURE__*/ jsx(renderer.Request, {
805
- name: s.label,
806
- code: s.source,
807
- language: s.lang
808
- }, s.label))
809
- }, "requests"));
804
+ ]).flatMap((sample)=>{
805
+ if (sample.source === false) return [];
806
+ const result = typeof sample.source === 'function' ? sample.source(endpoint) : sample.source;
807
+ if (result === undefined) return [];
808
+ return {
809
+ ...sample,
810
+ source: result
811
+ };
812
+ });
813
+ if (samples.length > 0) {
814
+ children.push(/*#__PURE__*/ jsx(renderer.Requests, {
815
+ items: samples.map((s)=>s.label),
816
+ children: samples.map((s)=>/*#__PURE__*/ jsx(renderer.Request, {
817
+ name: s.label,
818
+ code: s.source,
819
+ language: s.lang
820
+ }, s.label))
821
+ }, "requests"));
822
+ }
810
823
  children.push(/*#__PURE__*/ jsx(ResponseTabs, {
811
824
  operation: method,
812
825
  ctx: ctx,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "5.4.8",
3
+ "version": "5.4.10",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -53,23 +53,23 @@
53
53
  "github-slugger": "^2.0.0",
54
54
  "hast-util-to-jsx-runtime": "^2.3.0",
55
55
  "js-yaml": "^4.1.0",
56
- "lucide-react": "^0.437.0",
56
+ "lucide-react": "^0.438.0",
57
57
  "openapi-sampler": "^1.5.1",
58
58
  "react-hook-form": "^7.53.0",
59
59
  "remark": "^15.0.1",
60
60
  "remark-rehype": "^11.1.0",
61
- "shiki": "^1.15.2",
61
+ "shiki": "^1.16.2",
62
62
  "swr": "^2.2.5",
63
- "fumadocs-core": "13.4.4",
64
- "fumadocs-ui": "13.4.4"
63
+ "fumadocs-core": "13.4.6",
64
+ "fumadocs-ui": "13.4.6"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@types/js-yaml": "^4.0.9",
68
- "@types/node": "22.5.2",
68
+ "@types/node": "22.5.4",
69
69
  "@types/openapi-sampler": "^1.0.3",
70
70
  "@types/react": "^18.3.5",
71
71
  "bunchee": "^5.4.0",
72
- "next": "^14.2.7",
72
+ "next": "^14.2.8",
73
73
  "openapi-types": "^12.1.3",
74
74
  "eslint-config-custom": "0.0.0",
75
75
  "tsconfig": "0.0.0"