fumadocs-openapi 6.0.4 → 6.0.6

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 (45) hide show
  1. package/dist/render/operation/api-example.d.ts +15 -0
  2. package/dist/render/operation/api-example.d.ts.map +1 -0
  3. package/dist/render/operation/api-example.js +131 -0
  4. package/dist/render/operation.d.ts +1 -1
  5. package/dist/render/operation.d.ts.map +1 -1
  6. package/dist/render/operation.js +2 -106
  7. package/dist/render/renderer.d.ts +16 -0
  8. package/dist/render/renderer.d.ts.map +1 -1
  9. package/dist/render/renderer.js +3 -0
  10. package/dist/requests/curl.d.ts +1 -1
  11. package/dist/requests/curl.d.ts.map +1 -1
  12. package/dist/requests/curl.js +3 -3
  13. package/dist/requests/go.d.ts +1 -1
  14. package/dist/requests/go.d.ts.map +1 -1
  15. package/dist/requests/go.js +4 -4
  16. package/dist/requests/javascript.d.ts +1 -1
  17. package/dist/requests/javascript.d.ts.map +1 -1
  18. package/dist/requests/javascript.js +8 -8
  19. package/dist/requests/python.d.ts +1 -1
  20. package/dist/requests/python.d.ts.map +1 -1
  21. package/dist/requests/python.js +4 -4
  22. package/dist/server/source-api.d.ts.map +1 -1
  23. package/dist/server/source-api.js +2 -15
  24. package/dist/ui/client.d.ts +9 -13
  25. package/dist/ui/client.d.ts.map +1 -1
  26. package/dist/ui/client.js +2 -6
  27. package/dist/ui/components/method-label.d.ts +6 -0
  28. package/dist/ui/components/method-label.d.ts.map +1 -1
  29. package/dist/ui/components/method-label.js +9 -5
  30. package/dist/ui/components/select.js +1 -1
  31. package/dist/ui/contexts/api.d.ts.map +1 -1
  32. package/dist/ui/contexts/api.js +1 -0
  33. package/dist/ui/index.d.ts +3 -2
  34. package/dist/ui/index.d.ts.map +1 -1
  35. package/dist/ui/index.js +7 -3
  36. package/dist/ui/sample-select.d.ts +4 -0
  37. package/dist/ui/sample-select.d.ts.map +1 -0
  38. package/dist/ui/sample-select.js +19 -0
  39. package/dist/utils/generate-sample.d.ts +9 -1
  40. package/dist/utils/generate-sample.d.ts.map +1 -1
  41. package/dist/utils/generate-sample.js +7 -1
  42. package/package.json +8 -8
  43. package/dist/ui/components/variants.d.ts +0 -6
  44. package/dist/ui/components/variants.d.ts.map +0 -1
  45. package/dist/ui/components/variants.js +0 -26
@@ -0,0 +1,15 @@
1
+ import type { MethodInformation, RenderContext } from '../../types.js';
2
+ import type { EndpointSample } from '../../utils/generate-sample.js';
3
+ import { type CodeSample } from '../../render/operation.js';
4
+ interface CustomProperty {
5
+ 'x-codeSamples'?: CodeSample[];
6
+ 'x-selectedCodeSample'?: string;
7
+ 'x-exclusiveCodeSample'?: string;
8
+ }
9
+ export declare function APIExample({ method, endpoint, ctx, }: {
10
+ method: MethodInformation & CustomProperty;
11
+ endpoint: EndpointSample;
12
+ ctx: RenderContext;
13
+ }): Promise<import("react/jsx-runtime").JSX.Element>;
14
+ export {};
15
+ //# sourceMappingURL=api-example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-example.d.ts","sourceRoot":"","sources":["../../../src/render/operation/api-example.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AA2BrD,UAAU,cAAc;IACtB,eAAe,CAAC,EAAE,UAAU,EAAE,CAAC;IAC/B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC;AAcD,wBAAsB,UAAU,CAAC,EAC/B,MAAM,EACN,QAAQ,EACR,GAAG,GACJ,EAAE;IACD,MAAM,EAAE,iBAAiB,GAAG,cAAc,CAAC;IAC3C,QAAQ,EAAE,cAAc,CAAC;IACzB,GAAG,EAAE,aAAa,CAAC;CACpB,oDA2FA"}
@@ -0,0 +1,131 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import * as CURL from '../../requests/curl.js';
3
+ import * as JS from '../../requests/javascript.js';
4
+ import * as Go from '../../requests/go.js';
5
+ import * as Python from '../../requests/python.js';
6
+ import { Markdown } from '../../render/markdown.js';
7
+ import { getTypescriptSchema } from '../../utils/get-typescript-schema.js';
8
+ const defaultSamples = [
9
+ {
10
+ label: 'cURL',
11
+ source: CURL.getSampleRequest,
12
+ lang: 'bash',
13
+ },
14
+ {
15
+ label: 'JavaScript',
16
+ source: JS.getSampleRequest,
17
+ lang: 'js',
18
+ },
19
+ {
20
+ label: 'Go',
21
+ source: Go.getSampleRequest,
22
+ lang: 'go',
23
+ },
24
+ {
25
+ label: 'Python',
26
+ source: Python.getSampleRequest,
27
+ lang: 'python',
28
+ },
29
+ ];
30
+ export async function APIExample({ method, endpoint, ctx, }) {
31
+ const renderer = ctx.renderer;
32
+ const samples = new Map();
33
+ let children;
34
+ for (const [key, sample] of Object.entries(endpoint.body?.samples ?? {
35
+ // fallback for methods that have no request body, we also want to show examples for
36
+ _default: {},
37
+ })) {
38
+ samples.set(key, {
39
+ title: sample?.summary ?? key,
40
+ description: sample?.description,
41
+ samples: dedupe([
42
+ ...defaultSamples,
43
+ ...(ctx.generateCodeSamples
44
+ ? await ctx.generateCodeSamples(endpoint)
45
+ : []),
46
+ ...(method['x-codeSamples'] ?? []),
47
+ ]).flatMap((sample) => {
48
+ if (sample.source === false)
49
+ return [];
50
+ const result = typeof sample.source === 'function'
51
+ ? sample.source(endpoint, key)
52
+ : sample.source;
53
+ if (result === undefined)
54
+ return [];
55
+ return {
56
+ ...sample,
57
+ source: result,
58
+ };
59
+ }),
60
+ });
61
+ }
62
+ function renderRequest(sample) {
63
+ return (_jsx(renderer.Requests, { items: sample.samples.map((s) => s.label), children: sample.samples.map((s) => (_jsx(renderer.Request, { name: s.label, code: s.source, language: s.lang }, s.label))) }));
64
+ }
65
+ if ((samples.size === 1 && samples.has('_default')) ||
66
+ (method['x-exclusiveCodeSample'] &&
67
+ samples.has(method['x-exclusiveCodeSample']))) {
68
+ // if exclusiveSampleKey is present, we don't use tabs
69
+ // if only the fallback or non described openapi legacy example is present, we don't use tabs
70
+ children = renderRequest(samples.get(method['x-exclusiveCodeSample'] ?? '_default'));
71
+ }
72
+ else if (samples.size > 0) {
73
+ const entries = Array.from(samples.entries());
74
+ children = (_jsx(renderer.Samples, { items: entries.map(([key, sample]) => ({
75
+ title: sample.title,
76
+ description: sample.description ? (_jsx(Markdown, { text: sample.description })) : null,
77
+ value: key,
78
+ })), defaultValue: method['x-selectedCodeSample'], children: entries.map(([key, sample]) => (_jsx(renderer.Sample, { value: key, children: renderRequest(sample) }, key))) }));
79
+ }
80
+ return (_jsxs(renderer.APIExample, { children: [children, _jsx(ResponseTabs, { operation: method, ctx: ctx, endpoint: endpoint })] }));
81
+ }
82
+ /**
83
+ * Remove duplicated labels
84
+ */
85
+ function dedupe(samples) {
86
+ const set = new Set();
87
+ const out = [];
88
+ for (let i = samples.length - 1; i >= 0; i--) {
89
+ if (set.has(samples[i].label))
90
+ continue;
91
+ set.add(samples[i].label);
92
+ out.unshift(samples[i]);
93
+ }
94
+ return out;
95
+ }
96
+ function ResponseTabs({ endpoint, operation, ctx: { renderer, generateTypeScriptSchema, schema }, }) {
97
+ if (!operation.responses)
98
+ return null;
99
+ async function renderResponse(code) {
100
+ const types = [];
101
+ let description = operation.responses?.[code].description;
102
+ if (!description && code in endpoint.responses)
103
+ description = endpoint.responses[code].schema.description ?? '';
104
+ if (code in endpoint.responses) {
105
+ types.push({
106
+ lang: 'json',
107
+ label: 'Response',
108
+ code: JSON.stringify(endpoint.responses[code].sample, null, 2),
109
+ });
110
+ }
111
+ let ts;
112
+ if (generateTypeScriptSchema) {
113
+ ts = await generateTypeScriptSchema(endpoint, code);
114
+ }
115
+ else if (generateTypeScriptSchema === undefined) {
116
+ ts = await getTypescriptSchema(endpoint, code, schema.dereferenceMap);
117
+ }
118
+ if (ts) {
119
+ types.push({
120
+ code: ts,
121
+ lang: 'ts',
122
+ label: 'TypeScript',
123
+ });
124
+ }
125
+ return (_jsxs(renderer.Response, { value: code, children: [description ? _jsx(Markdown, { text: description }) : null, types.length > 0 ? (_jsx(renderer.ResponseTypes, { children: types.map((type) => (_jsx(renderer.ResponseType, { ...type }, type.lang))) })) : null] }));
126
+ }
127
+ const codes = Object.keys(operation.responses);
128
+ if (codes.length === 0)
129
+ return null;
130
+ return (_jsx(renderer.Responses, { items: codes, children: codes.map((code) => renderResponse(code)) }));
131
+ }
@@ -4,7 +4,7 @@ import type { MethodInformation, RenderContext } from '../types.js';
4
4
  export interface CodeSample {
5
5
  lang: string;
6
6
  label: string;
7
- source: string | ((endpoint: EndpointSample) => string | undefined) | false;
7
+ source: string | ((endpoint: EndpointSample, exampleKey: string) => string | undefined) | false;
8
8
  }
9
9
  export declare function Operation({ type, path, method, ctx, hasHead, headingLevel, }: {
10
10
  type?: 'webhook' | 'operation';
@@ -1 +1 @@
1
- {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/render/operation.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AACpE,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAK9E,OAAO,KAAK,EAEV,iBAAiB,EAEjB,aAAa,EAEd,MAAM,SAAS,CAAC;AAgBjB,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,cAAc,KAAK,MAAM,GAAG,SAAS,CAAC,GAAG,KAAK,CAAC;CAC7E;AAQD,wBAAgB,SAAS,CAAC,EACxB,IAAkB,EAClB,IAAI,EACJ,MAAM,EACN,GAAG,EACH,OAAO,EACP,YAAgB,GACjB,EAAE;IACD,IAAI,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;IAEnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,YAAY,CAoLf"}
1
+ {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/render/operation.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AACpE,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,KAAK,EAEV,iBAAiB,EAEjB,aAAa,EAEd,MAAM,SAAS,CAAC;AAWjB,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EACF,MAAM,GACN,CAAC,CAAC,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,GACtE,KAAK,CAAC;CACX;AAED,wBAAgB,SAAS,CAAC,EACxB,IAAkB,EAClB,IAAI,EACJ,MAAM,EACN,GAAG,EACH,OAAO,EACP,YAAgB,GACjB,EAAE;IACD,IAAI,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;IAEnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,YAAY,CAoLf"}
@@ -1,12 +1,7 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Fragment } from 'react';
3
3
  import { generateSample } from '../utils/generate-sample.js';
4
- import * as CURL from '../requests/curl.js';
5
- import * as JS from '../requests/javascript.js';
6
- import * as Go from '../requests/go.js';
7
- import * as Python from '../requests/python.js';
8
4
  import { getPreferredType } from '../utils/schema.js';
9
- import { getTypescriptSchema } from '../utils/get-typescript-schema.js';
10
5
  import { getSecurities, getSecurityPrefix } from '../utils/get-security.js';
11
6
  import { idToTitle } from '../utils/id-to-title.js';
12
7
  import { Markdown } from './markdown.js';
@@ -14,6 +9,7 @@ import { heading } from './heading.js';
14
9
  import { Schema } from './schema.js';
15
10
  import { createMethod } from '../server/create-method.js';
16
11
  import { methodKeys } from '../build-routes.js';
12
+ import { APIExample } from '../render/operation/api-example.js';
17
13
  export function Operation({ type = 'operation', path, method, ctx, hasHead, headingLevel = 2, }) {
18
14
  const body = method.requestBody;
19
15
  const security = method.security ?? ctx.schema.document.security;
@@ -87,7 +83,7 @@ export function Operation({ type = 'operation', path, method, ctx, hasHead, head
87
83
  if (method.callbacks) {
88
84
  callbacksNode = (_jsxs(_Fragment, { children: [heading(headingLevel, 'Webhooks', ctx), Object.entries(method.callbacks).map(([name, callback]) => (_jsx(WebhookCallback, { callback: callback, ctx: ctx, headingLevel: headingLevel }, name)))] }));
89
85
  }
90
- const info = (_jsxs(ctx.renderer.APIInfo, { head: headNode, method: method.method, route: path, children: [type === 'operation' ? (_jsx(ctx.renderer.APIPlayground, { path: path, method: method, ctx: ctx })) : null, security ? (_jsxs(_Fragment, { children: [heading(headingLevel, 'Authorization', ctx), _jsx(AuthSection, { requirements: security, ctx: ctx })] })) : null, bodyNode, Array.from(parameterGroups.entries()).map(([group, params]) => {
86
+ const info = (_jsxs(ctx.renderer.APIInfo, { head: headNode, method: method.method, route: path, children: [type === 'operation' ? (_jsx(ctx.renderer.APIPlayground, { path: path, method: method, ctx: ctx })) : null, security && Object.keys(security).length > 0 ? (_jsxs(_Fragment, { children: [heading(headingLevel, 'Authorization', ctx), _jsx(AuthSection, { requirements: security, ctx: ctx })] })) : null, bodyNode, Array.from(parameterGroups.entries()).map(([group, params]) => {
91
87
  return (_jsxs(Fragment, { children: [heading(headingLevel, group, ctx), params] }, group));
92
88
  }), responseNode, callbacksNode] }));
93
89
  if (type === 'operation') {
@@ -97,54 +93,6 @@ export function Operation({ type = 'operation', path, method, ctx, hasHead, head
97
93
  return info;
98
94
  }
99
95
  }
100
- const defaultSamples = [
101
- {
102
- label: 'cURL',
103
- source: CURL.getSampleRequest,
104
- lang: 'bash',
105
- },
106
- {
107
- label: 'JavaScript',
108
- source: JS.getSampleRequest,
109
- lang: 'js',
110
- },
111
- {
112
- label: 'Go',
113
- source: Go.getSampleRequest,
114
- lang: 'go',
115
- },
116
- {
117
- label: 'Python',
118
- source: Python.getSampleRequest,
119
- lang: 'python',
120
- },
121
- ];
122
- async function APIExample({ method, endpoint, ctx, }) {
123
- const renderer = ctx.renderer;
124
- const children = [];
125
- const samples = dedupe([
126
- ...defaultSamples,
127
- ...(ctx.generateCodeSamples ? await ctx.generateCodeSamples(endpoint) : []),
128
- ...(method['x-codeSamples'] ?? []),
129
- ]).flatMap((sample) => {
130
- if (sample.source === false)
131
- return [];
132
- const result = typeof sample.source === 'function'
133
- ? sample.source(endpoint)
134
- : sample.source;
135
- if (result === undefined)
136
- return [];
137
- return {
138
- ...sample,
139
- source: result,
140
- };
141
- });
142
- if (samples.length > 0) {
143
- children.push(_jsx(renderer.Requests, { items: samples.map((s) => s.label), children: samples.map((s) => (_jsx(renderer.Request, { name: s.label, code: s.source, language: s.lang }, s.label))) }, "requests"));
144
- }
145
- children.push(_jsx(ResponseTabs, { operation: method, ctx: ctx, endpoint: endpoint }, "responses"));
146
- return _jsx(renderer.APIExample, { children: children });
147
- }
148
96
  function WebhookCallback({ callback, ctx, headingLevel, }) {
149
97
  return Object.entries(callback).map(([path, pathItem]) => {
150
98
  const pathNodes = methodKeys.map((method) => {
@@ -156,20 +104,6 @@ function WebhookCallback({ callback, ctx, headingLevel, }) {
156
104
  return _jsx(Fragment, { children: pathNodes }, path);
157
105
  });
158
106
  }
159
- /**
160
- * Remove duplicated labels
161
- */
162
- function dedupe(samples) {
163
- const set = new Set();
164
- const out = [];
165
- for (let i = samples.length - 1; i >= 0; i--) {
166
- if (set.has(samples[i].label))
167
- continue;
168
- set.add(samples[i].label);
169
- out.unshift(samples[i]);
170
- }
171
- return out;
172
- }
173
107
  function AuthSection({ ctx: { schema: { document }, renderer, }, requirements, }) {
174
108
  let id = 0;
175
109
  const info = [];
@@ -190,41 +124,3 @@ function AuthSection({ ctx: { schema: { document }, renderer, }, requirements, }
190
124
  }
191
125
  return info;
192
126
  }
193
- async function ResponseTabs({ endpoint, operation, ctx: { renderer, generateTypeScriptSchema, schema }, }) {
194
- const items = [];
195
- const children = [];
196
- if (!operation.responses)
197
- return null;
198
- for (const code of Object.keys(operation.responses)) {
199
- const types = [];
200
- let description = operation.responses[code].description;
201
- if (!description && code in endpoint.responses)
202
- description = endpoint.responses[code].schema.description ?? '';
203
- if (code in endpoint.responses) {
204
- types.push({
205
- lang: 'json',
206
- label: 'Response',
207
- code: JSON.stringify(endpoint.responses[code].sample, null, 2),
208
- });
209
- }
210
- let ts;
211
- if (generateTypeScriptSchema) {
212
- ts = await generateTypeScriptSchema(endpoint, code);
213
- }
214
- else if (generateTypeScriptSchema === undefined) {
215
- ts = await getTypescriptSchema(endpoint, code, schema.dereferenceMap);
216
- }
217
- if (ts) {
218
- types.push({
219
- code: ts,
220
- lang: 'ts',
221
- label: 'TypeScript',
222
- });
223
- }
224
- items.push(code);
225
- children.push(_jsxs(renderer.Response, { value: code, children: [_jsx(Markdown, { text: description }), types.length > 0 ? (_jsx(renderer.ResponseTypes, { children: types.map((type) => (_jsx(renderer.ResponseType, { ...type }, type.lang))) })) : null] }, code));
226
- }
227
- if (items.length === 0)
228
- return null;
229
- return _jsx(renderer.Responses, { items: items, children: children });
230
- }
@@ -30,6 +30,19 @@ export interface RequestProps {
30
30
  name: string;
31
31
  code: string;
32
32
  }
33
+ export interface SampleProps {
34
+ value: string;
35
+ children: ReactNode;
36
+ }
37
+ export interface SamplesProps {
38
+ items: {
39
+ title: string;
40
+ description?: ReactNode;
41
+ value: string;
42
+ }[];
43
+ children: ReactNode;
44
+ defaultValue?: string;
45
+ }
33
46
  export interface ResponseTypeProps {
34
47
  lang: string;
35
48
  code: string;
@@ -37,6 +50,7 @@ export interface ResponseTypeProps {
37
50
  }
38
51
  export interface RootProps {
39
52
  baseUrl?: string;
53
+ shikiOptions?: RenderContext['shikiOptions'];
40
54
  servers: ServerObject[];
41
55
  children: ReactNode;
42
56
  }
@@ -51,6 +65,8 @@ export interface Renderer {
51
65
  }>;
52
66
  Responses: ComponentType<ResponsesProps>;
53
67
  Response: ComponentType<ResponseProps>;
68
+ Sample: ComponentType<SampleProps>;
69
+ Samples: ComponentType<SamplesProps>;
54
70
  Requests: ComponentType<{
55
71
  items: string[];
56
72
  children: ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/render/renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAYtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG9E,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IAEd,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAA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a,CAAC;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;IAClE,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACrC,aAAa,EAAE,aAAa,CAAC;QAAE,QAAQ,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;IACtD,YAAY,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAE/C;;OAEG;IACH,iBAAiB,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;IACzD,QAAQ,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;IACvC,aAAa,EAAE,aAAa,CAAC;QAC3B,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,iBAAiB,CAAC;QAC1B,GAAG,EAAE,aAAa,CAAC;KACpB,CAAC,CAAC;CACJ;AAED,YAAY,EACV,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAE7B,wBAAgB,aAAa,CAC3B,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,GAC1C,QAAQ,CAkDV"}
@@ -4,6 +4,7 @@ import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
4
4
  import { CodeBlock } from '../render/codeblock.js';
5
5
  import { API, Root, APIInfo, APIExample, Property, ObjectCollapsible, } from '../ui/index.js';
6
6
  import { Playground } from '../render/playground.js';
7
+ import { Sample, Samples } from '../ui/client.js';
7
8
  export function createRenders(shikiOptions) {
8
9
  return {
9
10
  Root: (props) => (_jsx(Root, { shikiOptions: shikiOptions, ...props, children: props.children })),
@@ -17,6 +18,8 @@ export function createRenders(shikiOptions) {
17
18
  Property,
18
19
  ObjectCollapsible,
19
20
  Requests: (props) => (_jsx(Tabs, { groupId: "fumadocs_openapi_requests", ...props })),
21
+ Samples,
22
+ Sample,
20
23
  Request: (props) => (_jsx(Tab, { value: props.name, children: _jsx(CodeBlock, { lang: props.language, code: props.code, options: shikiOptions }) })),
21
24
  APIPlayground: Playground,
22
25
  };
@@ -1,3 +1,3 @@
1
1
  import { type EndpointSample } from '../utils/generate-sample.js';
2
- export declare function getSampleRequest(endpoint: EndpointSample): string;
2
+ export declare function getSampleRequest(endpoint: EndpointSample, sampleKey: string): string;
3
3
  //# sourceMappingURL=curl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../src/requests/curl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CA0CjE"}
1
+ {"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../src/requests/curl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,cAAc,EACxB,SAAS,EAAE,MAAM,GAChB,MAAM,CA0CR"}
@@ -1,5 +1,5 @@
1
1
  import { inputToString } from '../utils/input-to-string.js';
2
- export function getSampleRequest(endpoint) {
2
+ export function getSampleRequest(endpoint, sampleKey) {
3
3
  const s = [];
4
4
  s.push(`curl -X ${endpoint.method} "${endpoint.url}"`);
5
5
  for (const param of endpoint.parameters) {
@@ -13,7 +13,7 @@ export function getSampleRequest(endpoint) {
13
13
  }
14
14
  }
15
15
  if (endpoint.body?.mediaType === 'multipart/form-data') {
16
- const sample = endpoint.body.sample;
16
+ const sample = endpoint.body.samples[sampleKey]?.value;
17
17
  if (sample && typeof sample === 'object') {
18
18
  for (const [key, value] of Object.entries(sample)) {
19
19
  s.push(`-F ${key}=${inputToString(value)}`);
@@ -22,7 +22,7 @@ export function getSampleRequest(endpoint) {
22
22
  }
23
23
  else if (endpoint.body) {
24
24
  s.push(`-H "Content-Type: ${endpoint.body.mediaType}"`);
25
- s.push(`-d ${inputToString(endpoint.body.sample, endpoint.body.mediaType, 'single-quote')}`);
25
+ s.push(`-d ${inputToString(endpoint.body.samples[sampleKey]?.value ?? '', endpoint.body.mediaType, 'single-quote')}`);
26
26
  }
27
27
  return s
28
28
  .flatMap((v, i) => v
@@ -1,3 +1,3 @@
1
1
  import { type EndpointSample } from '../utils/generate-sample.js';
2
- export declare function getSampleRequest(endpoint: EndpointSample): string;
2
+ export declare function getSampleRequest(endpoint: EndpointSample, sampleKey: string): string;
3
3
  //# sourceMappingURL=go.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"go.d.ts","sourceRoot":"","sources":["../../src/requests/go.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CA0EjE"}
1
+ {"version":3,"file":"go.d.ts","sourceRoot":"","sources":["../../src/requests/go.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,cAAc,EACxB,SAAS,EAAE,MAAM,GAChB,MAAM,CA4ER"}
@@ -1,5 +1,5 @@
1
1
  import { inputToString } from '../utils/input-to-string.js';
2
- export function getSampleRequest(endpoint) {
2
+ export function getSampleRequest(endpoint, sampleKey) {
3
3
  const imports = ['fmt', 'net/http', 'io/ioutil'];
4
4
  const headers = new Map();
5
5
  const variables = new Map();
@@ -16,17 +16,17 @@ export function getSampleRequest(endpoint) {
16
16
  if (endpoint.body) {
17
17
  headers.set('Content-Type', `"${endpoint.body.mediaType}"`);
18
18
  if (endpoint.body.mediaType === 'multipart/form-data' &&
19
- typeof endpoint.body.sample === 'object') {
19
+ typeof endpoint.body.samples[sampleKey]?.value === 'object') {
20
20
  imports.push('mime/multipart', 'bytes');
21
21
  variables.set('payload', `new(bytes.Buffer)`);
22
22
  variables.set('mp', 'multipart.NewWriter(payload)');
23
- for (const [key, value] of Object.entries(endpoint.body.sample ?? {})) {
23
+ for (const [key, value] of Object.entries(endpoint.body.samples[sampleKey]?.value ?? {})) {
24
24
  additional.push(`mp.WriteField("${key}", ${inputToString(value, undefined, 'backtick')})`);
25
25
  }
26
26
  }
27
27
  else {
28
28
  imports.push('strings');
29
- variables.set('payload', `strings.NewReader(${inputToString(endpoint.body.sample, endpoint.body.mediaType, 'backtick').replaceAll('\n', '\n ')})`);
29
+ variables.set('payload', `strings.NewReader(${inputToString(endpoint.body.samples[sampleKey]?.value ?? '', endpoint.body.mediaType, 'backtick').replaceAll('\n', '\n ')})`);
30
30
  }
31
31
  }
32
32
  return `package main
@@ -1,3 +1,3 @@
1
1
  import { type EndpointSample } from '../utils/generate-sample.js';
2
- export declare function getSampleRequest(endpoint: EndpointSample): string;
2
+ export declare function getSampleRequest(endpoint: EndpointSample, sampleKey: string): string;
3
3
  //# sourceMappingURL=javascript.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/requests/javascript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CA4EjE"}
1
+ {"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/requests/javascript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,cAAc,EACxB,SAAS,EAAE,MAAM,GAChB,MAAM,CA8ER"}
@@ -1,5 +1,5 @@
1
1
  import { inputToString } from '../utils/input-to-string.js';
2
- export function getSampleRequest(endpoint) {
2
+ export function getSampleRequest(endpoint, sampleKey) {
3
3
  const s = [];
4
4
  const options = new Map();
5
5
  const headers = new Map();
@@ -21,10 +21,10 @@ export function getSampleRequest(endpoint) {
21
21
  options.set('headers', JSON.stringify(Object.fromEntries(headers.entries()), null, 2).replaceAll('\n', '\n '));
22
22
  }
23
23
  if (endpoint.body?.mediaType === 'multipart/form-data' &&
24
- typeof endpoint.body.sample === 'object' &&
25
- endpoint.body.sample) {
24
+ typeof endpoint.body.samples[sampleKey]?.value === 'object' &&
25
+ endpoint.body.samples[sampleKey]?.value) {
26
26
  s.push(`const formData = new FormData();`);
27
- for (const [key, value] of Object.entries(endpoint.body.sample))
27
+ for (const [key, value] of Object.entries(endpoint.body.samples[sampleKey]?.value))
28
28
  s.push(`formData.set(${key}, ${inputToString(value)})`);
29
29
  options.set('body', 'formData');
30
30
  }
@@ -32,12 +32,12 @@ export function getSampleRequest(endpoint) {
32
32
  let code;
33
33
  if (endpoint.body.mediaType === 'application/json') {
34
34
  code =
35
- typeof endpoint.body.sample === 'string'
36
- ? inputToString(endpoint.body.sample, endpoint.body.mediaType, 'backtick')
37
- : `JSON.stringify(${JSON.stringify(endpoint.body.sample, null, 2)})`;
35
+ typeof endpoint.body.samples[sampleKey]?.value === 'string'
36
+ ? inputToString(endpoint.body.samples[sampleKey]?.value, endpoint.body.mediaType, 'backtick')
37
+ : `JSON.stringify(${JSON.stringify(endpoint.body.samples[sampleKey]?.value, null, 2)})`;
38
38
  }
39
39
  else {
40
- code = inputToString(endpoint.body.sample, endpoint.body.mediaType, 'backtick');
40
+ code = inputToString(endpoint.body.samples[sampleKey]?.value ?? '', endpoint.body.mediaType, 'backtick');
41
41
  }
42
42
  options.set('body', code.replaceAll('\n', '\n '));
43
43
  }
@@ -1,3 +1,3 @@
1
1
  import { type EndpointSample } from '../utils/generate-sample.js';
2
- export declare function getSampleRequest(endpoint: EndpointSample): string;
2
+ export declare function getSampleRequest(endpoint: EndpointSample, sampleKey: string): string;
3
3
  //# sourceMappingURL=python.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../src/requests/python.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CA8DjE"}
1
+ {"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../src/requests/python.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,cAAc,EACxB,SAAS,EAAE,MAAM,GAChB,MAAM,CA4ER"}
@@ -1,5 +1,5 @@
1
1
  import { inputToString } from '../utils/input-to-string.js';
2
- export function getSampleRequest(endpoint) {
2
+ export function getSampleRequest(endpoint, sampleKey) {
3
3
  const headers = new Map();
4
4
  const cookies = new Map();
5
5
  const variables = new Map();
@@ -12,15 +12,15 @@ export function getSampleRequest(endpoint) {
12
12
  if (endpoint.body) {
13
13
  switch (endpoint.body.mediaType) {
14
14
  case 'application/json':
15
- variables.set('json', JSON.stringify(endpoint.body.sample, null, 2));
15
+ variables.set('json', JSON.stringify(endpoint.body.samples[sampleKey]?.value ?? {}, null, 2));
16
16
  break;
17
17
  case 'multipart/form-data':
18
18
  headers.set('Content-Type', endpoint.body.mediaType);
19
- variables.set('data', JSON.stringify(endpoint.body.sample, null, 2));
19
+ variables.set('data', JSON.stringify(endpoint.body.samples[sampleKey]?.value ?? {}, null, 2));
20
20
  break;
21
21
  default:
22
22
  headers.set('Content-Type', endpoint.body.mediaType);
23
- variables.set('data', inputToString(endpoint.body.sample, endpoint.body.mediaType, 'backtick'));
23
+ variables.set('data', inputToString(endpoint.body.samples[sampleKey]?.value ?? '', endpoint.body.mediaType, 'backtick'));
24
24
  }
25
25
  }
26
26
  if (headers.size > 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"source-api.d.ts","sourceRoot":"","sources":["../../src/server/source-api.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAIjE;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,oBAAoB,CAAC,YAAY,CA6BzD,CAAC"}
1
+ {"version":3,"file":"source-api.d.ts","sourceRoot":"","sources":["../../src/server/source-api.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAGjE;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,oBAAoB,CAAC,YAAY,CAyBzD,CAAC"}
@@ -1,6 +1,5 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { cva } from 'class-variance-authority';
3
- import { getBadgeColor } from '../ui/components/variants.js';
2
+ import { MethodLabel } from '../ui/components/method-label.js';
4
3
  /**
5
4
  * Source API Integration
6
5
  *
@@ -16,19 +15,7 @@ export const attachFile = (node, file) => {
16
15
  method = meta.method;
17
16
  }
18
17
  if (method) {
19
- const color = getBadgeColor(method);
20
- node.name = (_jsxs(_Fragment, { children: [node.name, ' ', _jsx("span", { className: badgeVariants({ className: 'ms-auto text-nowrap', color }), children: method })] }));
18
+ node.name = (_jsxs(_Fragment, { children: [node.name, ' ', _jsx(MethodLabel, { className: "ms-auto text-xs text-nowrap", children: method })] }));
21
19
  }
22
20
  return node;
23
21
  };
24
- const badgeVariants = cva('rounded-full border px-1.5 text-xs font-medium', {
25
- variants: {
26
- color: {
27
- green: 'bg-green-400/20 text-green-600 dark:text-green-400',
28
- yellow: 'bg-yellow-400/20 text-yellow-600 dark:text-yellow-400',
29
- red: 'bg-red-400/20 text-red-600 dark:text-red-400',
30
- blue: 'bg-blue-400/20 text-blue-600 dark:text-blue-400',
31
- orange: 'bg-orange-400/20 text-orange-600 dark:text-orange-400',
32
- },
33
- },
34
- });
@@ -1,22 +1,18 @@
1
- import { type HTMLAttributes, type ReactNode } from 'react';
2
- import { type RootProps } from '../render/renderer.js';
3
- import type { RenderContext } from '../types.js';
4
- export declare const APIPlayground: import("react").ComponentType<import("../render/renderer.js").APIPlaygroundProps & {
1
+ export declare const APIPlayground: import("react").ComponentType<import("../render/playground.js").APIPlaygroundProps & {
5
2
  fields?: {
6
- auth?: import("./playground/index.js").CustomField<"authorization", import("../render/renderer.js").RequestSchema>;
7
- path?: import("./playground/index.js").CustomField<`path.${string}`, import("../render/renderer.js").PrimitiveRequestField>;
8
- query?: import("./playground/index.js").CustomField<`query.${string}`, import("../render/renderer.js").PrimitiveRequestField>;
9
- header?: import("./playground/index.js").CustomField<`header.${string}`, import("../render/renderer.js").PrimitiveRequestField>;
10
- body?: import("./playground/index.js").CustomField<"body", import("../render/renderer.js").RequestSchema>;
3
+ auth?: import("./playground/index.js").CustomField<"authorization", import("../render/playground.js").RequestSchema>;
4
+ path?: import("./playground/index.js").CustomField<`path.${string}`, import("../render/playground.js").PrimitiveRequestField>;
5
+ query?: import("./playground/index.js").CustomField<`query.${string}`, import("../render/playground.js").PrimitiveRequestField>;
6
+ header?: import("./playground/index.js").CustomField<`header.${string}`, import("../render/playground.js").PrimitiveRequestField>;
7
+ body?: import("./playground/index.js").CustomField<"body", import("../render/playground.js").RequestSchema>;
11
8
  };
12
9
  components?: Partial<{
13
10
  ResultDisplay: import("react").FC<{
14
11
  data: import("./playground/fetcher.js").FetchResult;
15
12
  }>;
16
13
  }>;
17
- } & HTMLAttributes<HTMLFormElement>>;
18
- export declare function Root({ children, baseUrl, className, shikiOptions, servers, ...props }: RootProps & {
19
- shikiOptions: RenderContext['shikiOptions'];
20
- } & HTMLAttributes<HTMLDivElement>): ReactNode;
14
+ } & import("react").HTMLAttributes<HTMLFormElement>>;
15
+ export declare const Samples: import("react").ComponentType<import("../render/renderer.js").SamplesProps>;
16
+ export declare const Sample: import("react").ComponentType<import("../render/renderer.js").SampleProps>;
21
17
  export { useSchemaContext } from './contexts/schema.js';
22
18
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/ui/client.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAI5D,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,eAAO,MAAM,aAAa;;YAkCy4C,CAAC;YAAuD,CAAC;aAAiE,CAAC;cAAmE,CAAC;YAAkE,CAAC;;;;;;;oCAhCpqD,CAAC;AAEF,wBAAgB,IAAI,CAAC,EACnB,QAAQ,EACR,OAAO,EACP,SAAS,EACT,YAAY,EACZ,OAAO,EACP,GAAG,KAAK,EACT,EAAE,SAAS,GAAG;IACb,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;CAC7C,GAAG,cAAc,CAAC,cAAc,CAAC,GAAG,SAAS,CAkB7C;AAED,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/ui/client.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa;;YAa8+D,CAAC;YAAuD,CAAC;aAAiE,CAAC;cAAmE,CAAC;YAAkE,CAAC;;;;;;;oDAXzwE,CAAC;AAEF,eAAO,MAAM,OAAO,0EAEnB,CAAC;AAEF,eAAO,MAAM,MAAM,yEAElB,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/ui/client.js CHANGED
@@ -1,10 +1,6 @@
1
1
  'use client';
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { cn } from 'fumadocs-ui/components/api';
4
2
  import dynamic from 'next/dynamic';
5
- import { ApiProvider } from '../ui/contexts/api.js';
6
3
  export const APIPlayground = dynamic(() => import('./playground/index.js').then((mod) => mod.APIPlayground));
7
- export function Root({ children, baseUrl, className, shikiOptions, servers, ...props }) {
8
- return (_jsx("div", { className: cn('flex flex-col gap-24 text-sm text-fd-muted-foreground', className), ...props, children: _jsx(ApiProvider, { servers: servers, shikiOptions: shikiOptions, defaultBaseUrl: baseUrl, children: children }) }));
9
- }
4
+ export const Samples = dynamic(() => import('./sample-select.js').then((mod) => mod.Samples));
5
+ export const Sample = dynamic(() => import('./sample-select.js').then((mod) => mod.Sample));
10
6
  export { useSchemaContext } from './contexts/schema.js';
@@ -1,4 +1,10 @@
1
+ import { type VariantProps } from 'class-variance-authority';
1
2
  import type { HTMLAttributes } from 'react';
3
+ export declare const badgeVariants: (props?: ({
4
+ color?: "red" | "green" | "yellow" | "blue" | "orange" | null | undefined;
5
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
6
+ export declare function getBadgeColor(method: string): VariantProps<typeof badgeVariants>['color'];
7
+ export declare function Badge({ className, color, ...props }: Omit<HTMLAttributes<HTMLSpanElement>, 'color'> & VariantProps<typeof badgeVariants>): import("react/jsx-runtime").JSX.Element;
2
8
  export declare function MethodLabel({ children, ...props }: Omit<HTMLAttributes<HTMLSpanElement>, 'children'> & {
3
9
  children: string;
4
10
  }): import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"method-label.d.ts","sourceRoot":"","sources":["../../../src/ui/components/method-label.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AA8B5C,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE,UAAU,CAAC,GAAG;IACrD,QAAQ,EAAE,MAAM,CAAC;CAClB,2CAcA"}
1
+ {"version":3,"file":"method-label.d.ts","sourceRoot":"","sources":["../../../src/ui/components/method-label.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAG5C,eAAO,MAAM,aAAa;;8EAUxB,CAAC;AAEH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,GACb,YAAY,CAAC,OAAO,aAAa,CAAC,CAAC,OAAO,CAAC,CAa7C;AAED,wBAAgB,KAAK,CAAC,EACpB,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EACT,EAAE,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC,GAC/C,YAAY,CAAC,OAAO,aAAa,CAAC,2CAcnC;AAED,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE,UAAU,CAAC,GAAG;IACrD,QAAQ,EAAE,MAAM,CAAC;CAClB,2CAMA"}
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { cva } from 'class-variance-authority';
3
3
  import { cn } from 'fumadocs-ui/components/api';
4
- const variants = cva('font-mono font-medium', {
4
+ export const badgeVariants = cva('font-mono font-medium', {
5
5
  variants: {
6
6
  color: {
7
7
  green: 'text-green-600 dark:text-green-400',
@@ -12,7 +12,7 @@ const variants = cva('font-mono font-medium', {
12
12
  },
13
13
  },
14
14
  });
15
- function getBadgeColor(method) {
15
+ export function getBadgeColor(method) {
16
16
  switch (method.toUpperCase()) {
17
17
  case 'PUT':
18
18
  return 'yellow';
@@ -26,8 +26,12 @@ function getBadgeColor(method) {
26
26
  return 'green';
27
27
  }
28
28
  }
29
+ export function Badge({ className, color, ...props }) {
30
+ return (_jsx("span", { className: cn(badgeVariants({
31
+ color,
32
+ className,
33
+ })), ...props, children: props.children }));
34
+ }
29
35
  export function MethodLabel({ children, ...props }) {
30
- return (_jsx("span", { ...props, className: cn(variants({
31
- color: getBadgeColor(children),
32
- }), props.className), children: children.toUpperCase() }));
36
+ return (_jsx(Badge, { ...props, color: getBadgeColor(children), children: children.toUpperCase() }));
33
37
  }
@@ -6,7 +6,7 @@ import { cn } from 'fumadocs-ui/components/api';
6
6
  const Select = SelectPrimitive.Root;
7
7
  const SelectGroup = SelectPrimitive.Group;
8
8
  const SelectValue = SelectPrimitive.Value;
9
- const SelectTrigger = forwardRef(({ className, children, ...props }, ref) => (_jsxs(SelectPrimitive.Trigger, { ref: ref, className: cn('flex h-10 items-center w-full rounded-md border px-3 py-2 text-start text-[13px] text-fd-foreground hover:bg-fd-accent focus:outline-none focus:ring-2 focus:ring-fd-ring disabled:cursor-not-allowed disabled:opacity-50', className), ...props, children: [children, _jsx(SelectPrimitive.Icon, { asChild: true, children: _jsx(ChevronDown, { className: "ms-auto size-4 text-fd-muted-foreground" }) })] })));
9
+ const SelectTrigger = forwardRef(({ className, children, ...props }, ref) => (_jsxs(SelectPrimitive.Trigger, { ref: ref, className: cn('flex min-h-10 items-center w-full rounded-md border px-3 py-2 text-start text-[13px] text-fd-foreground hover:bg-fd-accent focus:outline-none focus:ring-2 focus:ring-fd-ring disabled:cursor-not-allowed disabled:opacity-50', className), ...props, children: [children, _jsx(SelectPrimitive.Icon, { asChild: true, children: _jsx(ChevronDown, { className: "ms-auto size-4 text-fd-muted-foreground" }) })] })));
10
10
  SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
11
11
  const SelectScrollUpButton = forwardRef(({ className, ...props }, ref) => (_jsx(SelectPrimitive.ScrollUpButton, { ref: ref, className: cn('flex items-center justify-center py-1', className), ...props, children: _jsx(ChevronUp, { className: "size-4" }) })));
12
12
  SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/api.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE3D,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,OAA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,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,UAAU,cACR,SAAQ,IAAI,CAAC,gBAAgB,EAAE,UAAU,GAAG,gBAAgB,CAAC;IAC7D,SAAS,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;CAC7C;AAED,UAAU,gBAAgB;IACxB,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CAC7D;AAOD,wBAAgB,aAAa,IAAI,cAAc,CAK9C;AAED,wBAAgB,sBAAsB,IAAI,gBAAgB,CAKzD;AAED,wBAAgB,WAAW,CAAC,EAC1B,cAAc,EACd,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,gBAAgB,2CA0ElB"}
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  import { jsx as _jsx } from "react/jsx-runtime";
2
3
  import { createContext, useContext, useEffect, useMemo, useRef, useState, } from 'react';
3
4
  const ApiContext = createContext(undefined);
@@ -1,6 +1,7 @@
1
1
  import { type HTMLAttributes, type ReactNode } from 'react';
2
- import type { PropertyProps } from '../render/renderer.js';
3
- export { Root, useSchemaContext, APIPlayground } from './client.js';
2
+ import type { PropertyProps, RootProps } from '../render/renderer.js';
3
+ export { useSchemaContext, APIPlayground } from './client.js';
4
+ export declare function Root({ children, baseUrl, className, shikiOptions, servers, ...props }: RootProps & HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
4
5
  export declare function APIInfo({ className, ...props }: HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
5
6
  export declare function API({ children, ...props }: HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
6
7
  export declare function Property({ name, type, required, deprecated, children, }: PropertyProps): import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAQvD,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEjE,wBAAgB,OAAO,CAAC,EACtB,SAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,cAAc,CAAC,2CAMhC;AAED,wBAAgB,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,CAAC,cAAc,CAAC,2CAmBzE;AAED,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE,aAAa,2CAoBf;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,CAAC,cAAc,CAAC,2CAY/D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAiBA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AASlE,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE3D,wBAAgB,IAAI,CAAC,EACnB,QAAQ,EACR,OAAO,EACP,SAAS,EACT,YAAY,EACZ,OAAO,EACP,GAAG,KAAK,EACT,EAAE,SAAS,GAAG,cAAc,CAAC,cAAc,CAAC,2CAkB5C;AAED,wBAAgB,OAAO,CAAC,EACtB,SAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,cAAc,CAAC,2CAMhC;AAED,wBAAgB,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,CAAC,cAAc,CAAC,2CAmBzE;AAED,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE,aAAa,2CAsBf;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,CAAC,cAAc,CAAC,2CAY/D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAiBA"}
package/dist/ui/index.js CHANGED
@@ -1,9 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { buttonVariants, cn } from 'fumadocs-ui/components/api';
3
- import { badgeVariants } from '../ui/components/variants.js';
3
+ import { Badge } from '../ui/components/method-label.js';
4
4
  import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from 'fumadocs-ui/components/ui/collapsible';
5
5
  import { ChevronDown } from 'lucide-react';
6
- export { Root, useSchemaContext, APIPlayground } from './client.js';
6
+ import { ApiProvider } from '../ui/contexts/api.js';
7
+ export { useSchemaContext, APIPlayground } from './client.js';
8
+ export function Root({ children, baseUrl, className, shikiOptions, servers, ...props }) {
9
+ return (_jsx("div", { className: cn('flex flex-col gap-24 text-sm text-fd-muted-foreground', className), ...props, children: _jsx(ApiProvider, { servers: servers, shikiOptions: shikiOptions, defaultBaseUrl: baseUrl, children: children }) }));
10
+ }
7
11
  export function APIInfo({ className, ...props }) {
8
12
  return (_jsx("div", { className: cn('min-w-0 flex-1', className), ...props, children: props.children }));
9
13
  }
@@ -14,7 +18,7 @@ export function API({ children, ...props }) {
14
18
  }, children: children }));
15
19
  }
16
20
  export function Property({ name, type, required, deprecated, children, }) {
17
- return (_jsxs("div", { className: "rounded-xl border bg-fd-card p-3 prose-no-margin", children: [_jsxs("div", { className: "flex flex-row flex-wrap items-center gap-4", children: [_jsx("code", { children: name }), required ? (_jsx("div", { className: cn(badgeVariants({ color: 'red' })), children: "Required" })) : null, deprecated ? (_jsx("div", { className: cn(badgeVariants({ color: 'yellow' })), children: "Deprecated" })) : null, _jsx("span", { className: "ms-auto text-xs font-mono text-fd-muted-foreground", children: type })] }), children] }));
21
+ return (_jsxs("div", { className: "rounded-xl border bg-fd-card p-3 prose-no-margin", children: [_jsxs("div", { className: "flex flex-row flex-wrap items-center gap-4", children: [_jsx("code", { children: name }), required ? (_jsx(Badge, { color: "red", className: "text-xs", children: "Required" })) : null, deprecated ? (_jsx(Badge, { color: "yellow", className: "text-xs", children: "Deprecated" })) : null, _jsx("span", { className: "ms-auto text-xs font-mono text-fd-muted-foreground", children: type })] }), children] }));
18
22
  }
19
23
  export function APIExample(props) {
20
24
  return (_jsx("div", { ...props, className: cn('prose-no-margin md:sticky md:top-[var(--fd-api-info-top)] xl:w-[400px]', props.className), children: props.children }));
@@ -0,0 +1,4 @@
1
+ import type { SampleProps, SamplesProps } from '../render/renderer.js';
2
+ export declare function Samples({ items, defaultValue, children, }: SamplesProps): import("react/jsx-runtime").JSX.Element;
3
+ export declare function Sample({ value, children }: SampleProps): import("react").ReactNode;
4
+ //# sourceMappingURL=sample-select.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-select.d.ts","sourceRoot":"","sources":["../../src/ui/sample-select.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAWnE,wBAAgB,OAAO,CAAC,EACtB,KAAK,EACL,YAA6B,EAC7B,QAAQ,GACT,EAAE,YAAY,2CA0Bd;AAWD,wBAAgB,MAAM,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,WAAW,6BAKtD"}
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { createContext, use, useState } from 'react';
3
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../ui/components/select.js';
4
+ const ActiveSampleContext = createContext('');
5
+ export function Samples({ items, defaultValue = items[0].value, children, }) {
6
+ const [value, setValue] = useState('');
7
+ const active = value === '' ? defaultValue : value;
8
+ const defaultItem = items.find((item) => item.value === defaultValue);
9
+ return (_jsxs(_Fragment, { children: [_jsxs(Select, { value: value, onValueChange: setValue, children: [_jsx(SelectTrigger, { className: "not-prose", children: _jsx(SelectValue, { placeholder: defaultItem ? _jsx(SelectDisplay, { ...defaultItem }) : null }) }), _jsx(SelectContent, { children: items.map((item) => (_jsx(SelectItem, { value: item.value, children: _jsx(SelectDisplay, { ...item }) }, item.value))) })] }), _jsx(ActiveSampleContext, { value: active, children: children })] }));
10
+ }
11
+ function SelectDisplay(item) {
12
+ return (_jsxs(_Fragment, { children: [_jsx("span", { className: "font-medium text-sm", children: item.title }), _jsx("span", { className: "text-fd-muted-foreground", children: item.description })] }));
13
+ }
14
+ export function Sample({ value, children }) {
15
+ const active = use(ActiveSampleContext);
16
+ if (value !== active)
17
+ return;
18
+ return children;
19
+ }
@@ -1,5 +1,13 @@
1
1
  import type { MethodInformation, RenderContext } from '../types.js';
2
2
  import { type ParsedSchema } from '../utils/schema.js';
3
+ export interface EndpointSamples {
4
+ [key: string]: {
5
+ value?: unknown;
6
+ description?: string;
7
+ summary?: string;
8
+ externalValue?: string;
9
+ };
10
+ }
3
11
  /**
4
12
  * Sample info of endpoint
5
13
  */
@@ -12,7 +20,7 @@ export interface EndpointSample {
12
20
  body?: {
13
21
  schema: ParsedSchema;
14
22
  mediaType: string;
15
- sample: unknown;
23
+ samples: EndpointSamples;
16
24
  };
17
25
  responses: Record<string, ResponseSample>;
18
26
  parameters: ParameterSample[];
@@ -1 +1 @@
1
- {"version":3,"file":"generate-sample.d.ts","sourceRoot":"","sources":["../../src/utils/generate-sample.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAEL,KAAK,YAAY,EAElB,MAAM,gBAAgB,CAAC;AAGxB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE;QACL,MAAM,EAAE,YAAY,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,OAAO,CAAC;KACjB,CAAC;IACF,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC1C,UAAU,EAAE,eAAe,EAAE,CAAC;CAC/B;AAED,UAAU,cAAc;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,YAAY,CAAC;CACtB;AAED,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,aAAa,GAC/C,cAAc,CAoHhB"}
1
+ {"version":3,"file":"generate-sample.d.ts","sourceRoot":"","sources":["../../src/utils/generate-sample.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAEL,KAAK,YAAY,EAElB,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,eAAe;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;CACH;AACD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE;QACL,MAAM,EAAE,YAAY,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,eAAe,CAAC;KAC1B,CAAC;IACF,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC1C,UAAU,EAAE,eAAe,EAAE,CAAC;CAC/B;AAED,UAAU,cAAc;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,YAAY,CAAC;CACtB;AAED,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,aAAa,GAC/C,cAAc,CA0HhB"}
@@ -55,7 +55,13 @@ export function generateSample(path, method, { baseUrl, schema: { document } })
55
55
  bodyOutput = {
56
56
  schema,
57
57
  mediaType: type,
58
- sample: body[type].example ?? generateBody(method.method, schema),
58
+ samples: body[type].examples
59
+ ? body[type].examples
60
+ : {
61
+ _default: {
62
+ value: body[type].example ?? generateBody(method.method, schema),
63
+ },
64
+ },
59
65
  };
60
66
  }
61
67
  for (const [code, response] of Object.entries(method.responses ?? {})) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "6.0.4",
3
+ "version": "6.0.6",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -36,8 +36,8 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "@fumari/json-schema-to-typescript": "^1.1.2",
39
- "@radix-ui/react-select": "^2.1.5",
40
- "@radix-ui/react-slot": "^1.1.1",
39
+ "@radix-ui/react-select": "^2.1.6",
40
+ "@radix-ui/react-slot": "^1.1.2",
41
41
  "@scalar/openapi-parser": "0.10.4",
42
42
  "ajv-draft-04": "^1.0.0",
43
43
  "class-variance-authority": "^0.7.1",
@@ -51,15 +51,15 @@
51
51
  "react-hook-form": "^7.54.2",
52
52
  "remark": "^15.0.1",
53
53
  "remark-rehype": "^11.1.1",
54
- "shiki": "^2.2.0",
54
+ "shiki": "^2.3.1",
55
55
  "xml-js": "^1.6.11",
56
- "fumadocs-core": "15.0.3",
57
- "fumadocs-ui": "15.0.3"
56
+ "fumadocs-core": "15.0.5",
57
+ "fumadocs-ui": "15.0.5"
58
58
  },
59
59
  "devDependencies": {
60
- "@scalar/api-client-react": "^1.1.22",
60
+ "@scalar/api-client-react": "^1.1.24",
61
61
  "@types/js-yaml": "^4.0.9",
62
- "@types/node": "22.13.0",
62
+ "@types/node": "22.13.1",
63
63
  "@types/openapi-sampler": "^1.0.3",
64
64
  "@types/react": "^19.0.8",
65
65
  "next": "15.1.6",
@@ -1,6 +0,0 @@
1
- import { type VariantProps } from 'class-variance-authority';
2
- export declare const badgeVariants: (props?: ({
3
- color?: "red" | "green" | "yellow" | "blue" | "orange" | null | undefined;
4
- } & import("class-variance-authority/types").ClassProp) | undefined) => string;
5
- export declare function getBadgeColor(method: string): VariantProps<typeof badgeVariants>['color'];
6
- //# sourceMappingURL=variants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../src/ui/components/variants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAElE,eAAO,MAAM,aAAa;;8EAazB,CAAC;AAEF,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,GACb,YAAY,CAAC,OAAO,aAAa,CAAC,CAAC,OAAO,CAAC,CAa7C"}
@@ -1,26 +0,0 @@
1
- import { cva } from 'class-variance-authority';
2
- export const badgeVariants = cva('rounded-xl border px-1.5 py-1 text-xs font-medium leading-[12px]', {
3
- variants: {
4
- color: {
5
- green: 'bg-green-400/20 text-green-600 dark:text-green-400',
6
- yellow: 'bg-yellow-400/20 text-yellow-600 dark:text-yellow-400',
7
- red: 'bg-red-400/20 text-red-600 dark:text-red-400',
8
- blue: 'bg-blue-400/20 text-blue-600 dark:text-blue-400',
9
- orange: 'bg-orange-400/20 text-orange-600 dark:text-orange-400',
10
- },
11
- },
12
- });
13
- export function getBadgeColor(method) {
14
- switch (method) {
15
- case 'PUT':
16
- return 'yellow';
17
- case 'PATCH':
18
- return 'orange';
19
- case 'POST':
20
- return 'blue';
21
- case 'DELETE':
22
- return 'red';
23
- default:
24
- return 'green';
25
- }
26
- }