fumadocs-openapi 6.0.1 → 6.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.
Files changed (155) hide show
  1. package/dist/build-routes.d.ts +15 -0
  2. package/dist/build-routes.d.ts.map +1 -0
  3. package/dist/build-routes.js +38 -0
  4. package/dist/generate-file.d.ts +38 -0
  5. package/dist/generate-file.d.ts.map +1 -0
  6. package/dist/generate-file.js +118 -0
  7. package/dist/generate.d.ts +48 -0
  8. package/dist/generate.d.ts.map +1 -0
  9. package/dist/generate.js +129 -0
  10. package/dist/index.d.ts +4 -274
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +3 -389
  13. package/dist/render/codeblock.d.ts +9 -0
  14. package/dist/render/codeblock.d.ts.map +1 -0
  15. package/dist/render/codeblock.js +13 -0
  16. package/dist/render/heading.d.ts +4 -0
  17. package/dist/render/heading.d.ts.map +1 -0
  18. package/dist/render/heading.js +6 -0
  19. package/dist/render/markdown.d.ts +5 -0
  20. package/dist/render/markdown.d.ts.map +1 -0
  21. package/dist/render/markdown.js +25 -0
  22. package/dist/render/operation.d.ts +17 -0
  23. package/dist/render/operation.d.ts.map +1 -0
  24. package/dist/render/operation.js +230 -0
  25. package/dist/render/playground.d.ts +66 -0
  26. package/dist/render/playground.d.ts.map +1 -0
  27. package/dist/render/playground.js +181 -0
  28. package/dist/render/renderer.d.ts +76 -0
  29. package/dist/render/renderer.d.ts.map +1 -0
  30. package/dist/render/renderer.js +23 -0
  31. package/dist/render/schema.d.ts +29 -0
  32. package/dist/render/schema.d.ts.map +1 -0
  33. package/dist/render/schema.js +151 -0
  34. package/dist/requests/curl.d.ts +3 -0
  35. package/dist/requests/curl.d.ts.map +1 -0
  36. package/dist/requests/curl.js +33 -0
  37. package/dist/requests/go.d.ts +3 -0
  38. package/dist/requests/go.d.ts.map +1 -0
  39. package/dist/requests/go.js +54 -0
  40. package/dist/requests/javascript.d.ts +3 -0
  41. package/dist/requests/javascript.d.ts.map +1 -0
  42. package/dist/requests/javascript.js +49 -0
  43. package/dist/requests/python.d.ts +3 -0
  44. package/dist/requests/python.d.ts.map +1 -0
  45. package/dist/requests/python.js +45 -0
  46. package/dist/scalar/client.d.ts +6 -0
  47. package/dist/scalar/client.d.ts.map +1 -0
  48. package/dist/scalar/client.js +25 -0
  49. package/dist/scalar/index.d.ts +4 -173
  50. package/dist/scalar/index.d.ts.map +1 -0
  51. package/dist/scalar/index.js +4 -11
  52. package/dist/server/api-page.d.ts +33 -0
  53. package/dist/server/api-page.d.ts.map +1 -0
  54. package/dist/server/api-page.js +59 -0
  55. package/dist/server/create-method.d.ts +7 -0
  56. package/dist/server/create-method.d.ts.map +1 -0
  57. package/dist/server/create-method.js +12 -0
  58. package/dist/server/create.d.ts +16 -0
  59. package/dist/server/create.d.ts.map +1 -0
  60. package/dist/server/create.js +11 -0
  61. package/dist/server/index.d.ts +3 -221
  62. package/dist/server/index.d.ts.map +1 -0
  63. package/dist/server/index.js +2 -1493
  64. package/dist/server/proxy.d.ts +8 -0
  65. package/dist/server/proxy.d.ts.map +1 -0
  66. package/dist/server/proxy.js +53 -0
  67. package/dist/server/source-api.d.ts +8 -0
  68. package/dist/server/source-api.d.ts.map +1 -0
  69. package/dist/server/source-api.js +34 -0
  70. package/dist/types.d.ts +60 -0
  71. package/dist/types.d.ts.map +1 -0
  72. package/dist/types.js +1 -0
  73. package/dist/ui/client.d.ts +22 -0
  74. package/dist/ui/client.d.ts.map +1 -0
  75. package/dist/ui/client.js +10 -0
  76. package/dist/ui/components/input.d.ts +6 -0
  77. package/dist/ui/components/input.d.ts.map +1 -0
  78. package/dist/ui/components/input.js +10 -0
  79. package/dist/ui/components/method-label.d.ts +5 -0
  80. package/dist/ui/components/method-label.d.ts.map +1 -0
  81. package/dist/ui/components/method-label.js +33 -0
  82. package/dist/ui/components/select.d.ts +14 -0
  83. package/dist/ui/components/select.d.ts.map +1 -0
  84. package/dist/ui/components/select.js +24 -0
  85. package/dist/ui/components/variants.d.ts +6 -0
  86. package/dist/ui/components/variants.d.ts.map +1 -0
  87. package/dist/ui/components/variants.js +26 -0
  88. package/dist/ui/contexts/api.d.ts +28 -0
  89. package/dist/ui/contexts/api.d.ts.map +1 -0
  90. package/dist/ui/contexts/api.js +74 -0
  91. package/dist/ui/contexts/schema.d.ts +17 -0
  92. package/dist/ui/contexts/schema.d.ts.map +1 -0
  93. package/dist/ui/contexts/schema.js +8 -0
  94. package/dist/ui/index.d.ts +12 -302
  95. package/dist/ui/index.d.ts.map +1 -0
  96. package/dist/ui/index.js +18 -98
  97. package/dist/ui/playground/fetcher.d.ts +34 -0
  98. package/dist/ui/playground/fetcher.d.ts.map +1 -0
  99. package/dist/ui/{fetcher-CsHhplmD.js → playground/fetcher.js} +45 -44
  100. package/dist/ui/playground/get-default-values.d.ts +4 -0
  101. package/dist/ui/playground/get-default-values.d.ts.map +1 -0
  102. package/dist/ui/playground/get-default-values.js +24 -0
  103. package/dist/ui/playground/index.d.ts +44 -0
  104. package/dist/ui/playground/index.d.ts.map +1 -0
  105. package/dist/ui/playground/index.js +187 -0
  106. package/dist/ui/playground/inputs.d.ts +23 -0
  107. package/dist/ui/playground/inputs.d.ts.map +1 -0
  108. package/dist/ui/playground/inputs.js +172 -0
  109. package/dist/ui/playground/resolve.d.ts +6 -0
  110. package/dist/ui/playground/resolve.d.ts.map +1 -0
  111. package/dist/ui/playground/resolve.js +14 -0
  112. package/dist/ui/playground/status-info.d.ts +8 -0
  113. package/dist/ui/playground/status-info.d.ts.map +1 -0
  114. package/dist/ui/playground/status-info.js +40 -0
  115. package/dist/ui/server-select.d.ts +3 -0
  116. package/dist/ui/server-select.d.ts.map +1 -0
  117. package/dist/ui/server-select.js +27 -0
  118. package/dist/utils/combine-schema.d.ts +6 -0
  119. package/dist/utils/combine-schema.d.ts.map +1 -0
  120. package/dist/utils/combine-schema.js +46 -0
  121. package/dist/utils/generate-document.d.ts +20 -0
  122. package/dist/utils/generate-document.d.ts.map +1 -0
  123. package/dist/utils/generate-document.js +82 -0
  124. package/dist/utils/generate-sample.d.ts +33 -0
  125. package/dist/utils/generate-sample.d.ts.map +1 -0
  126. package/dist/utils/generate-sample.js +97 -0
  127. package/dist/utils/get-security.d.ts +8 -0
  128. package/dist/utils/get-security.d.ts.map +1 -0
  129. package/dist/utils/get-security.js +23 -0
  130. package/dist/utils/get-typescript-schema.d.ts +4 -0
  131. package/dist/utils/get-typescript-schema.d.ts.map +1 -0
  132. package/dist/utils/get-typescript-schema.js +18 -0
  133. package/dist/utils/id-to-title.d.ts +2 -0
  134. package/dist/utils/id-to-title.d.ts.map +1 -0
  135. package/dist/utils/id-to-title.js +17 -0
  136. package/dist/utils/input-to-string.d.ts +5 -0
  137. package/dist/utils/input-to-string.d.ts.map +1 -0
  138. package/dist/utils/input-to-string.js +21 -0
  139. package/dist/utils/process-document.d.ts +14 -0
  140. package/dist/utils/process-document.d.ts.map +1 -0
  141. package/dist/utils/process-document.js +32 -0
  142. package/dist/utils/schema.d.ts +9 -0
  143. package/dist/utils/schema.d.ts.map +1 -0
  144. package/dist/utils/schema.js +16 -0
  145. package/dist/utils/server-url.d.ts +2 -0
  146. package/dist/utils/server-url.d.ts.map +1 -0
  147. package/dist/utils/server-url.js +7 -0
  148. package/dist/utils/use-query.d.ts +6 -0
  149. package/dist/utils/use-query.d.ts.map +1 -0
  150. package/dist/utils/use-query.js +22 -0
  151. package/package.json +7 -7
  152. package/dist/scalar/client-client-BXAjVueF.js +0 -93
  153. package/dist/ui/client-client-CYO00OiB.js +0 -107
  154. package/dist/ui/index-client-BUeWwFWK.js +0 -1116
  155. package/dist/ui/server-select-client-Ct_HJ46K.js +0 -86
@@ -0,0 +1,151 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { isNullable } from '../utils/schema';
3
+ import { combineSchema } from '../utils/combine-schema';
4
+ import { Markdown } from './markdown';
5
+ const keys = {
6
+ default: 'Default',
7
+ minimum: 'Minimum',
8
+ maximum: 'Maximum',
9
+ minLength: 'Minimum length',
10
+ maxLength: 'Maximum length',
11
+ pattern: 'Pattern',
12
+ format: 'Format',
13
+ };
14
+ function isObject(schema) {
15
+ return (schema.type === 'object' ||
16
+ schema.properties !== undefined ||
17
+ schema.additionalProperties !== undefined);
18
+ }
19
+ export function Schema({ name, schema, ctx, }) {
20
+ if ((schema.readOnly === true && !ctx.readOnly) ||
21
+ (schema.writeOnly === true && !ctx.writeOnly))
22
+ return null;
23
+ const parseObject = ctx.parseObject ?? true;
24
+ const stack = ctx.stack ?? [];
25
+ const { renderer } = ctx.render;
26
+ // object type
27
+ if (isObject(schema) &&
28
+ parseObject &&
29
+ (schema.additionalProperties || schema.properties)) {
30
+ let body = null;
31
+ let footer = null;
32
+ const { additionalProperties, properties } = schema;
33
+ if (additionalProperties === true) {
34
+ footer = _jsx(renderer.Property, { name: "[key: string]", type: "any" });
35
+ }
36
+ else if (additionalProperties) {
37
+ footer = (_jsx(Schema, { name: "[key: string]", schema: additionalProperties, ctx: {
38
+ ...ctx,
39
+ required: false,
40
+ parseObject: false,
41
+ } }));
42
+ }
43
+ if (properties) {
44
+ body = Object.entries(properties).map(([key, value]) => {
45
+ return (_jsx(Schema, { name: key, schema: value, ctx: {
46
+ ...ctx,
47
+ required: schema.required?.includes(key) ?? false,
48
+ parseObject: false,
49
+ } }, key));
50
+ });
51
+ }
52
+ return (_jsxs("div", { className: "flex flex-col gap-4", children: [body, footer] }));
53
+ }
54
+ if (schema.allOf && parseObject) {
55
+ return (_jsx(Schema, { name: name, schema: combineSchema(schema.allOf), ctx: ctx }));
56
+ }
57
+ let footer = null;
58
+ const fields = [];
59
+ for (const [key, value] of Object.entries(keys)) {
60
+ if (key in schema) {
61
+ fields.push({
62
+ key: value,
63
+ value: JSON.stringify(schema[key]),
64
+ });
65
+ }
66
+ }
67
+ if (schema.enum) {
68
+ fields.push({
69
+ key: 'Value in',
70
+ value: schema.enum.map((value) => JSON.stringify(value)).join(' | '),
71
+ });
72
+ }
73
+ if (isObject(schema) && !parseObject && !stack.includes(schema)) {
74
+ footer = (_jsx(renderer.ObjectCollapsible, { name: "Show Attributes", children: _jsx(Schema, { name: name, schema: schema, ctx: {
75
+ ...ctx,
76
+ parseObject: true,
77
+ required: false,
78
+ stack: [schema, ...stack],
79
+ } }) }));
80
+ }
81
+ else {
82
+ const mentionedObjectTypes = [
83
+ ...(schema.anyOf ?? schema.oneOf ?? []),
84
+ ...(schema.not ? [schema.not] : []),
85
+ ...(schema.type === 'array' ? [schema.items] : []),
86
+ ].filter((s) => isComplexType(s) && !stack.includes(s));
87
+ footer = mentionedObjectTypes.map((s, idx) => {
88
+ return (_jsx(renderer.ObjectCollapsible, { name: s.title ??
89
+ (mentionedObjectTypes.length === 1
90
+ ? 'Show Attributes'
91
+ : `Object ${idx + 1}`), children: _jsx(Schema, { name: "element", schema: s, ctx: {
92
+ ...ctx,
93
+ stack: [schema, ...stack],
94
+ parseObject: true,
95
+ required: false,
96
+ } }) }, idx));
97
+ });
98
+ }
99
+ return (_jsxs(renderer.Property, { name: name, type: getSchemaType(schema, ctx), required: ctx.required, deprecated: schema.deprecated, children: [schema.description ? _jsx(Markdown, { text: schema.description }) : null, fields.length > 0 ? (_jsx("div", { className: "flex flex-col gap-2", children: fields.map((field) => (_jsxs("span", { children: [field.key, ": ", _jsx("code", { children: field.value })] }, field.key))) })) : null, footer] }));
100
+ }
101
+ /**
102
+ * Check if the schema needs another collapsible to explain
103
+ */
104
+ function isComplexType(schema) {
105
+ if (schema.anyOf ?? schema.oneOf ?? schema.allOf)
106
+ return true;
107
+ return isObject(schema) || schema.type === 'array';
108
+ }
109
+ function getSchemaType(schema, ctx, isRoot = true) {
110
+ if (isNullable(schema) && isRoot) {
111
+ const type = getSchemaType(schema, ctx, false);
112
+ // null if schema only contains `nullable`
113
+ return type === 'unknown' ? 'null' : `${type} | null`;
114
+ }
115
+ if (schema.title)
116
+ return schema.title;
117
+ if (schema.type === 'array')
118
+ return `array<${getSchemaType(schema.items, ctx)}>`;
119
+ if (schema.oneOf)
120
+ return schema.oneOf
121
+ .map((one) => getSchemaType(one, ctx, false))
122
+ .filter((v) => v !== 'unknown')
123
+ .join(' | ');
124
+ if (schema.allOf) {
125
+ return schema.allOf
126
+ .map((one) => getSchemaType(one, ctx, false))
127
+ .filter((v) => v !== 'unknown')
128
+ .join(' & ');
129
+ }
130
+ if (schema.not)
131
+ return `not ${getSchemaType(schema.not, ctx, false)}`;
132
+ if (schema.anyOf) {
133
+ return `Any properties in ${schema.anyOf
134
+ .map((one) => getSchemaType(one, ctx, false))
135
+ .filter((v) => v !== 'unknown')
136
+ .join(', ')}`;
137
+ }
138
+ if (schema.type === 'string' && schema.format === 'binary' && ctx.allowFile)
139
+ return 'file';
140
+ if (schema.type && Array.isArray(schema.type)) {
141
+ const nonNullTypes = schema.type.filter((v) => v !== 'null');
142
+ if (nonNullTypes.length > 0)
143
+ return nonNullTypes.join(' | ');
144
+ }
145
+ else if (schema.type && schema.type !== 'null') {
146
+ return schema.type;
147
+ }
148
+ if (isObject(schema))
149
+ return 'object';
150
+ return 'unknown';
151
+ }
@@ -0,0 +1,3 @@
1
+ import { type EndpointSample } from '../utils/generate-sample';
2
+ export declare function getSampleRequest(endpoint: EndpointSample): string;
3
+ //# sourceMappingURL=curl.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,33 @@
1
+ import { inputToString } from '../utils/input-to-string';
2
+ export function getSampleRequest(endpoint) {
3
+ const s = [];
4
+ s.push(`curl -X ${endpoint.method} "${endpoint.url}"`);
5
+ for (const param of endpoint.parameters) {
6
+ if (param.in === 'header') {
7
+ const header = `${param.name}: ${param.sample}`;
8
+ s.push(`-H "${header}"`);
9
+ }
10
+ if (param.in === 'cookie') {
11
+ const cookie = JSON.stringify(`${param.name}=${param.sample}`);
12
+ s.push(`--cookie ${cookie}`);
13
+ }
14
+ }
15
+ if (endpoint.body?.mediaType === 'multipart/form-data') {
16
+ const sample = endpoint.body.sample;
17
+ if (sample && typeof sample === 'object') {
18
+ for (const [key, value] of Object.entries(sample)) {
19
+ s.push(`-F ${key}=${inputToString(value)}`);
20
+ }
21
+ }
22
+ }
23
+ else if (endpoint.body) {
24
+ s.push(`-H "Content-Type: ${endpoint.body.mediaType}"`);
25
+ s.push(`-d ${inputToString(endpoint.body.sample, endpoint.body.mediaType, 'single-quote')}`);
26
+ }
27
+ return s
28
+ .flatMap((v, i) => v
29
+ .split('\n')
30
+ .map((line) => (i > 0 ? ` ${line}` : line))
31
+ .join('\n'))
32
+ .join(' \\\n');
33
+ }
@@ -0,0 +1,3 @@
1
+ import { type EndpointSample } from '../utils/generate-sample';
2
+ export declare function getSampleRequest(endpoint: EndpointSample): string;
3
+ //# sourceMappingURL=go.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,54 @@
1
+ import { inputToString } from '../utils/input-to-string';
2
+ export function getSampleRequest(endpoint) {
3
+ const imports = ['fmt', 'net/http', 'io/ioutil'];
4
+ const headers = new Map();
5
+ const variables = new Map();
6
+ // additional lines before initializing request
7
+ const additional = [];
8
+ for (const p of endpoint.parameters) {
9
+ if (p.in === 'header')
10
+ headers.set(p.name, JSON.stringify(p.sample));
11
+ }
12
+ const cookies = endpoint.parameters.filter((p) => p.in === 'cookie');
13
+ variables.set('url', JSON.stringify(endpoint.url));
14
+ if (cookies.length > 0)
15
+ headers.set('Cookie', JSON.stringify(cookies.map((p) => `${p.name}=${p.sample}`).join('; ')));
16
+ if (endpoint.body) {
17
+ headers.set('Content-Type', `"${endpoint.body.mediaType}"`);
18
+ if (endpoint.body.mediaType === 'multipart/form-data' &&
19
+ typeof endpoint.body.sample === 'object') {
20
+ imports.push('mime/multipart', 'bytes');
21
+ variables.set('payload', `new(bytes.Buffer)`);
22
+ variables.set('mp', 'multipart.NewWriter(payload)');
23
+ for (const [key, value] of Object.entries(endpoint.body.sample ?? {})) {
24
+ additional.push(`mp.WriteField("${key}", ${inputToString(value, undefined, 'backtick')})`);
25
+ }
26
+ }
27
+ else {
28
+ imports.push('strings');
29
+ variables.set('payload', `strings.NewReader(${inputToString(endpoint.body.sample, endpoint.body.mediaType, 'backtick').replaceAll('\n', '\n ')})`);
30
+ }
31
+ }
32
+ return `package main
33
+
34
+ import (
35
+ ${imports.map((v) => ` "${v}"`).join('\n')}
36
+ )
37
+
38
+ func main() {
39
+ ${Array.from(variables.entries())
40
+ .map(([k, v]) => ` ${k} := ${v}`)
41
+ .join('\n')}
42
+ ${additional.join('\n ')}
43
+ req, _ := http.NewRequest("${endpoint.method}", url, ${variables.has('payload') ? 'payload' : 'nil'})
44
+ ${Array.from(headers.entries())
45
+ .map(([key, value]) => `req.Header.Add("${key}", ${value})`)
46
+ .join('\n ')}
47
+ res, _ := http.DefaultClient.Do(req)
48
+ defer res.Body.Close()
49
+ body, _ := ioutil.ReadAll(res.Body)
50
+
51
+ fmt.Println(res)
52
+ fmt.Println(string(body))
53
+ }`;
54
+ }
@@ -0,0 +1,3 @@
1
+ import { type EndpointSample } from '../utils/generate-sample';
2
+ export declare function getSampleRequest(endpoint: EndpointSample): string;
3
+ //# sourceMappingURL=javascript.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,49 @@
1
+ import { inputToString } from '../utils/input-to-string';
2
+ export function getSampleRequest(endpoint) {
3
+ const s = [];
4
+ const options = new Map();
5
+ const headers = new Map();
6
+ const cookies = new Map();
7
+ for (const param of endpoint.parameters) {
8
+ if (param.in === 'header') {
9
+ headers.set(param.name, param.sample);
10
+ }
11
+ if (param.in === 'cookie') {
12
+ cookies.set(param.name, param.sample);
13
+ }
14
+ }
15
+ if (cookies.size > 0) {
16
+ headers.set('cookie', Array.from(cookies.entries())
17
+ .map(([key, value]) => `${key}=${value}`)
18
+ .join('; '));
19
+ }
20
+ if (headers.size > 0) {
21
+ options.set('headers', JSON.stringify(Object.fromEntries(headers.entries()), null, 2).replaceAll('\n', '\n '));
22
+ }
23
+ if (endpoint.body?.mediaType === 'multipart/form-data' &&
24
+ typeof endpoint.body.sample === 'object' &&
25
+ endpoint.body.sample) {
26
+ s.push(`const formData = new FormData();`);
27
+ for (const [key, value] of Object.entries(endpoint.body.sample))
28
+ s.push(`formData.set(${key}, ${inputToString(value)})`);
29
+ options.set('body', 'formData');
30
+ }
31
+ else if (endpoint.body) {
32
+ let code;
33
+ if (endpoint.body.mediaType === 'application/json') {
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)})`;
38
+ }
39
+ else {
40
+ code = inputToString(endpoint.body.sample, endpoint.body.mediaType, 'backtick');
41
+ }
42
+ options.set('body', code.replaceAll('\n', '\n '));
43
+ }
44
+ const optionsStr = Array.from(options.entries())
45
+ .map(([k, v]) => ` ${k}: ${v}`)
46
+ .join(',\n');
47
+ s.push(`fetch(${JSON.stringify(endpoint.url)}, {\n${optionsStr}\n});`);
48
+ return s.join('\n\n');
49
+ }
@@ -0,0 +1,3 @@
1
+ import { type EndpointSample } from '../utils/generate-sample';
2
+ export declare function getSampleRequest(endpoint: EndpointSample): string;
3
+ //# sourceMappingURL=python.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,45 @@
1
+ import { inputToString } from '../utils/input-to-string';
2
+ export function getSampleRequest(endpoint) {
3
+ const headers = new Map();
4
+ const cookies = new Map();
5
+ const variables = new Map();
6
+ for (const param of endpoint.parameters) {
7
+ if (param.in === 'header')
8
+ headers.set(param.name, param.sample);
9
+ if (param.in === 'cookie')
10
+ cookies.set(param.name, param.sample);
11
+ }
12
+ if (endpoint.body) {
13
+ switch (endpoint.body.mediaType) {
14
+ case 'application/json':
15
+ variables.set('json', JSON.stringify(endpoint.body.sample, null, 2));
16
+ break;
17
+ case 'multipart/form-data':
18
+ headers.set('Content-Type', endpoint.body.mediaType);
19
+ variables.set('data', JSON.stringify(endpoint.body.sample, null, 2));
20
+ break;
21
+ default:
22
+ headers.set('Content-Type', endpoint.body.mediaType);
23
+ variables.set('data', inputToString(endpoint.body.sample, endpoint.body.mediaType, 'backtick'));
24
+ }
25
+ }
26
+ if (headers.size > 0) {
27
+ variables.set('headers', JSON.stringify(Object.fromEntries(headers.entries()), null, 2));
28
+ }
29
+ if (cookies.size > 0) {
30
+ variables.set('cookies', JSON.stringify(Object.fromEntries(cookies.entries()), null, 2));
31
+ }
32
+ return `import requests
33
+
34
+ url = ${JSON.stringify(endpoint.url)}
35
+ ${Array.from(variables.entries())
36
+ .map(([k, v]) => `${k} = ${v}`)
37
+ .join('\n')}
38
+ response = requests.request("${endpoint.method}", url${variables.size > 0
39
+ ? `, ${Array.from(variables.keys())
40
+ .map((k) => `${k}=${k}`)
41
+ .join(', ')}`
42
+ : ''})
43
+
44
+ print(response.text)`;
45
+ }
@@ -0,0 +1,6 @@
1
+ export default function ScalarPlayground({ path, method, spec, }: {
2
+ spec: object;
3
+ path: string;
4
+ method: string;
5
+ }): import("react/jsx-runtime").JSX.Element;
6
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/scalar/client.tsx"],"names":[],"mappings":"AAYA,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EACvC,IAAI,EACJ,MAAM,EACN,IAAI,GACL,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB,2CA+BA"}
@@ -0,0 +1,25 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { cn } from 'fumadocs-ui/components/api';
4
+ import { buttonVariants } from 'fumadocs-ui/components/ui/button';
5
+ import { ApiClientModalProvider, useApiClientModal, } from '@scalar/api-client-react';
6
+ import { MethodLabel } from '../ui/components/method-label';
7
+ import { useTheme } from 'next-themes';
8
+ import { useEffect, useState } from 'react';
9
+ export default function ScalarPlayground({ path, method, spec, }) {
10
+ const { resolvedTheme } = useTheme();
11
+ const [mounted, setMounted] = useState(false);
12
+ useEffect(() => {
13
+ setMounted(true);
14
+ }, []);
15
+ return (_jsxs("div", { className: cn('flex flex-row items-center gap-2.5 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose', mounted ? `${resolvedTheme}-mode` : null), children: [_jsx(MethodLabel, { className: "text-xs", children: method }), _jsx("code", { className: "flex-1 overflow-auto text-nowrap text-[13px] text-fd-muted-foreground", children: path }), _jsx(ApiClientModalProvider, { configuration: {
16
+ themeId: 'moon',
17
+ spec: {
18
+ content: spec,
19
+ },
20
+ }, children: _jsx(Trigger, { path: path, method: method }) })] }));
21
+ }
22
+ function Trigger({ path, method }) {
23
+ const client = useApiClientModal();
24
+ return (_jsx("button", { type: "submit", className: cn(buttonVariants({ color: 'primary', size: 'sm' }), 'px-3 py-1.5'), onClick: () => client?.open({ path, method: method }), children: "Test" }));
25
+ }
@@ -1,176 +1,7 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { OpenAPIV3_1 } from 'openapi-types';
3
- import Slugger from 'github-slugger';
4
- import { ComponentType, ReactNode } from 'react';
5
- import { CodeToHastOptionsCommon, CodeOptionsThemes, BuiltinTheme } from 'shiki';
6
-
7
- type NoReference<T> = T extends (infer I)[] ? NoReference<I>[] : T extends ReferenceObject ? Exclude<T, ReferenceObject> : T extends object ? {
8
- [K in keyof T]: NoReference<T[K]>;
9
- } : T;
10
- type ParsedSchema = OpenAPIV3_1.SchemaObject;
11
-
12
- interface ResponsesProps {
13
- items: string[];
14
- children: ReactNode;
15
- }
16
- interface ResponseProps {
17
- value: string;
18
- children: ReactNode;
19
- }
20
- interface APIInfoProps {
21
- method: string;
22
- route: string;
23
- head: ReactNode;
24
- children: ReactNode;
25
- }
26
- interface PropertyProps {
27
- name: string;
28
- type: string;
29
- required?: boolean;
30
- deprecated?: boolean;
31
- children?: ReactNode;
32
- }
33
- interface ObjectCollapsibleProps {
34
- name: string;
35
- children: ReactNode;
36
- }
37
- interface RequestProps {
38
- language: string;
39
- name: string;
40
- code: string;
41
- }
42
- interface ResponseTypeProps {
43
- lang: string;
44
- code: string;
45
- label: string;
46
- }
47
- interface RootProps {
48
- baseUrl?: string;
49
- servers: ServerObject[];
50
- children: ReactNode;
51
- }
52
- interface Renderer {
53
- Root: ComponentType<RootProps>;
54
- API: ComponentType<{
55
- children: ReactNode;
56
- }>;
57
- APIInfo: ComponentType<APIInfoProps>;
58
- APIExample: ComponentType<{
59
- children: ReactNode;
60
- }>;
61
- Responses: ComponentType<ResponsesProps>;
62
- Response: ComponentType<ResponseProps>;
63
- Requests: ComponentType<{
64
- items: string[];
65
- children: ReactNode;
66
- }>;
67
- Request: ComponentType<RequestProps>;
68
- ResponseTypes: ComponentType<{
69
- children: ReactNode;
70
- }>;
71
- ResponseType: ComponentType<ResponseTypeProps>;
72
- /**
73
- * Collapsible to show object schemas
74
- */
75
- ObjectCollapsible: ComponentType<ObjectCollapsibleProps>;
76
- Property: ComponentType<PropertyProps>;
77
- APIPlayground: ComponentType<{
78
- path: string;
79
- method: MethodInformation;
80
- ctx: RenderContext;
81
- }>;
82
- }
83
-
84
- /**
85
- * Sample info of endpoint
86
- */
87
- interface EndpointSample {
88
- /**
89
- * Request URL, including path and query parameters
90
- */
91
- url: string;
92
- method: string;
93
- body?: {
94
- schema: ParsedSchema;
95
- mediaType: string;
96
- sample: unknown;
97
- };
98
- responses: Record<string, ResponseSample>;
99
- parameters: ParameterSample[];
100
- }
101
- interface ResponseSample {
102
- mediaType: string;
103
- sample: unknown;
104
- schema: ParsedSchema;
105
- }
106
- interface ParameterSample {
107
- name: string;
108
- in: string;
109
- schema: ParsedSchema;
110
- sample: unknown;
111
- }
112
-
113
- interface CodeSample {
114
- lang: string;
115
- label: string;
116
- source: string | ((endpoint: EndpointSample) => string | undefined) | false;
117
- }
118
-
119
- type ProcessedDocument = {
120
- document: NoReference<Document>;
121
- dereferenceMap: DereferenceMap;
122
- downloaded: Document;
123
- };
124
-
125
- type Document = OpenAPIV3_1.Document;
126
- type OperationObject = OpenAPIV3_1.OperationObject;
127
- type ReferenceObject = OpenAPIV3_1.ReferenceObject;
128
- type ServerObject = NoReference<OpenAPIV3_1.ServerObject>;
129
- type MethodInformation = NoReference<OperationObject> & {
130
- method: string;
131
- };
132
- type Awaitable<T> = T | Promise<T>;
133
- /**
134
- * Dereferenced value and its original `$ref` value
135
- */
136
- type DereferenceMap = Map<unknown, string>;
137
- interface RenderContext {
138
- /**
139
- * The url of proxy to avoid CORS issues
140
- */
141
- proxyUrl?: string;
142
- renderer: Renderer;
143
- baseUrl: string;
144
- servers: ServerObject[];
145
- slugger: Slugger;
146
- /**
147
- * dereferenced schema
148
- */
149
- schema: ProcessedDocument;
150
- /**
151
- * Generate TypeScript definitions from response schema.
152
- *
153
- * Pass `false` to disable it.
154
- *
155
- * @param endpoint - the API endpoint
156
- * @param code - status code
157
- */
158
- generateTypeScriptSchema?: ((endpoint: EndpointSample, code: string) => Awaitable<string>) | false;
159
- /**
160
- * Generate code samples for endpoint.
161
- */
162
- generateCodeSamples?: (endpoint: EndpointSample) => Awaitable<CodeSample[]>;
163
- shikiOptions?: Omit<CodeToHastOptionsCommon, 'lang'> & CodeOptionsThemes<BuiltinTheme>;
164
- /**
165
- * Show full response schema instead of only example response & Typescript definitions
166
- */
167
- showResponseSchema?: boolean;
168
- }
169
-
170
- declare function APIPlayground({ path, method, ctx, }: {
1
+ import type { MethodInformation, RenderContext } from '../types';
2
+ export declare function APIPlayground({ path, method, ctx, }: {
171
3
  path: string;
172
4
  method: MethodInformation;
173
5
  ctx: RenderContext;
174
- }): react_jsx_runtime.JSX.Element;
175
-
176
- export { APIPlayground };
6
+ }): import("react/jsx-runtime").JSX.Element;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scalar/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAKhE,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,MAAM,EACN,GAAG,GACJ,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;CACpB,2CAIA"}
@@ -1,13 +1,6 @@
1
- import { jsx } from 'react/jsx-runtime';
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import dynamic from 'next/dynamic';
3
-
4
- const Client = dynamic(()=>import('./client-client-BXAjVueF.js'));
5
- function APIPlayground({ path, method, ctx }) {
6
- return /*#__PURE__*/ jsx(Client, {
7
- method: method.method,
8
- path: path,
9
- spec: ctx.schema.downloaded
10
- });
3
+ const Client = dynamic(() => import('./client'));
4
+ export function APIPlayground({ path, method, ctx, }) {
5
+ return (_jsx(Client, { method: method.method, path: path, spec: ctx.schema.downloaded }));
11
6
  }
12
-
13
- export { APIPlayground };
@@ -0,0 +1,33 @@
1
+ import type { RenderContext } from '../types';
2
+ import { type Renderer } from '../render/renderer';
3
+ import type { OpenAPIV3_1 } from 'openapi-types';
4
+ import { type DocumentInput, type ProcessedDocument } from '../utils/process-document';
5
+ type ApiPageContextProps = Pick<Partial<RenderContext>, 'shikiOptions' | 'generateTypeScriptSchema' | 'generateCodeSamples' | 'proxyUrl' | 'showResponseSchema'>;
6
+ export interface ApiPageProps extends ApiPageContextProps {
7
+ document: DocumentInput;
8
+ hasHead: boolean;
9
+ renderer?: Partial<Renderer>;
10
+ /**
11
+ * An array of operations
12
+ */
13
+ operations?: OperationItem[];
14
+ webhooks?: WebhookItem[];
15
+ /**
16
+ * By default, it is disabled on dev mode
17
+ */
18
+ disableCache?: boolean;
19
+ }
20
+ export interface WebhookItem {
21
+ name: string;
22
+ method: OpenAPIV3_1.HttpMethods;
23
+ }
24
+ export interface OperationItem {
25
+ path: string;
26
+ method: OpenAPIV3_1.HttpMethods;
27
+ }
28
+ export declare function APIPage(props: ApiPageProps): Promise<import("react/jsx-runtime").JSX.Element>;
29
+ export declare function getContext(schema: ProcessedDocument, options?: ApiPageContextProps & {
30
+ renderer?: Partial<Renderer>;
31
+ }): Promise<RenderContext>;
32
+ export {};
33
+ //# sourceMappingURL=api-page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-page.d.ts","sourceRoot":"","sources":["../../src/server/api-page.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EAAiB,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAGlC,KAAK,mBAAmB,GAAG,IAAI,CAC7B,OAAO,CAAC,aAAa,CAAC,EACpB,cAAc,GACd,0BAA0B,GAC1B,qBAAqB,GACrB,UAAU,GACV,oBAAoB,CACvB,CAAC;AAEF,MAAM,WAAW,YAAa,SAAQ,mBAAmB;IACvD,QAAQ,EAAE,aAAa,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IAEjB,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE7B;;OAEG;IACH,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAE7B,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IAEzB;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC;CACjC;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC;CACjC;AAED,wBAAsB,OAAO,CAAC,KAAK,EAAE,YAAY,oDA0DhD;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,iBAAiB,EACzB,OAAO,GAAE,mBAAmB,GAAG;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;CACzB,GACL,OAAO,CAAC,aAAa,CAAC,CA8BxB"}