zudoku 0.37.1 → 0.39.0

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 (260) hide show
  1. package/dist/app/main.js +2 -0
  2. package/dist/app/main.js.map +1 -1
  3. package/dist/app/tailwind.js +14 -0
  4. package/dist/app/tailwind.js.map +1 -1
  5. package/dist/config/validators/common.d.ts +287 -18
  6. package/dist/config/validators/common.js +2 -0
  7. package/dist/config/validators/common.js.map +1 -1
  8. package/dist/config/validators/validate.d.ts +107 -7
  9. package/dist/lib/authentication/authentication.d.ts +1 -0
  10. package/dist/lib/authentication/providers/clerk.js +19 -0
  11. package/dist/lib/authentication/providers/clerk.js.map +1 -1
  12. package/dist/lib/authentication/providers/openid.d.ts +1 -0
  13. package/dist/lib/authentication/providers/openid.js +5 -0
  14. package/dist/lib/authentication/providers/openid.js.map +1 -1
  15. package/dist/lib/authentication/providers/supabase.js +5 -0
  16. package/dist/lib/authentication/providers/supabase.js.map +1 -1
  17. package/dist/lib/authentication/state.d.ts +0 -26
  18. package/dist/lib/authentication/state.js +1 -16
  19. package/dist/lib/authentication/state.js.map +1 -1
  20. package/dist/lib/components/Heading.d.ts +1 -1
  21. package/dist/lib/components/Layout.js +5 -10
  22. package/dist/lib/components/Layout.js.map +1 -1
  23. package/dist/lib/components/Main.js +3 -1
  24. package/dist/lib/components/Main.js.map +1 -1
  25. package/dist/lib/components/Pagination.d.ts +10 -0
  26. package/dist/lib/components/Pagination.js +10 -0
  27. package/dist/lib/components/Pagination.js.map +1 -0
  28. package/dist/lib/components/TopNavigation.js +18 -2
  29. package/dist/lib/components/TopNavigation.js.map +1 -1
  30. package/dist/lib/components/navigation/SidebarItem.d.ts +1 -0
  31. package/dist/lib/components/navigation/SidebarItem.js +7 -3
  32. package/dist/lib/components/navigation/SidebarItem.js.map +1 -1
  33. package/dist/lib/{plugins/markdown → components/navigation}/Toc.js +5 -7
  34. package/dist/lib/components/navigation/Toc.js.map +1 -0
  35. package/dist/lib/core/ZudokuContext.d.ts +7 -0
  36. package/dist/lib/core/ZudokuContext.js +8 -3
  37. package/dist/lib/core/ZudokuContext.js.map +1 -1
  38. package/dist/lib/core/plugins.d.ts +1 -1
  39. package/dist/lib/oas/graphql/index.d.ts +2 -1
  40. package/dist/lib/oas/graphql/index.js +74 -14
  41. package/dist/lib/oas/graphql/index.js.map +1 -1
  42. package/dist/lib/oas/parser/dereference/index.js +2 -0
  43. package/dist/lib/oas/parser/dereference/index.js.map +1 -1
  44. package/dist/lib/oas/parser/index.d.ts +5 -3
  45. package/dist/lib/oas/parser/index.js +0 -22
  46. package/dist/lib/oas/parser/index.js.map +1 -1
  47. package/dist/lib/plugins/api-catalog/index.js +19 -17
  48. package/dist/lib/plugins/api-catalog/index.js.map +1 -1
  49. package/dist/lib/plugins/markdown/MdxPage.js +3 -9
  50. package/dist/lib/plugins/markdown/MdxPage.js.map +1 -1
  51. package/dist/lib/plugins/openapi/ColorizedParam.js +1 -1
  52. package/dist/lib/plugins/openapi/ColorizedParam.js.map +1 -1
  53. package/dist/lib/plugins/openapi/Endpoint.js +1 -1
  54. package/dist/lib/plugins/openapi/Endpoint.js.map +1 -1
  55. package/dist/lib/plugins/openapi/OperationList.d.ts +1 -1
  56. package/dist/lib/plugins/openapi/OperationList.js +29 -9
  57. package/dist/lib/plugins/openapi/OperationList.js.map +1 -1
  58. package/dist/lib/plugins/openapi/OperationListItem.js +1 -1
  59. package/dist/lib/plugins/openapi/OperationListItem.js.map +1 -1
  60. package/dist/lib/plugins/openapi/ParameterListItem.js +2 -1
  61. package/dist/lib/plugins/openapi/ParameterListItem.js.map +1 -1
  62. package/dist/lib/plugins/openapi/SchemaList.d.ts +1 -0
  63. package/dist/lib/plugins/openapi/SchemaList.js +52 -0
  64. package/dist/lib/plugins/openapi/SchemaList.js.map +1 -0
  65. package/dist/lib/plugins/openapi/Sidecar.js +29 -5
  66. package/dist/lib/plugins/openapi/Sidecar.js.map +1 -1
  67. package/dist/lib/plugins/openapi/client/GraphQLClient.d.ts +1 -1
  68. package/dist/lib/plugins/openapi/client/GraphQLClient.js +1 -1
  69. package/dist/lib/plugins/openapi/client/GraphQLClient.js.map +1 -1
  70. package/dist/lib/plugins/openapi/client/useCreateQuery.d.ts +6 -2
  71. package/dist/lib/plugins/openapi/client/useCreateQuery.js +5 -5
  72. package/dist/lib/plugins/openapi/client/useCreateQuery.js.map +1 -1
  73. package/dist/lib/plugins/openapi/components/EnumValues.js +1 -1
  74. package/dist/lib/plugins/openapi/components/EnumValues.js.map +1 -1
  75. package/dist/lib/plugins/openapi/graphql/gql.d.ts +6 -2
  76. package/dist/lib/plugins/openapi/graphql/gql.js +3 -2
  77. package/dist/lib/plugins/openapi/graphql/gql.js.map +1 -1
  78. package/dist/lib/plugins/openapi/graphql/graphql.d.ts +67 -11
  79. package/dist/lib/plugins/openapi/graphql/graphql.js +34 -5
  80. package/dist/lib/plugins/openapi/graphql/graphql.js.map +1 -1
  81. package/dist/lib/plugins/openapi/index.js +12 -0
  82. package/dist/lib/plugins/openapi/index.js.map +1 -1
  83. package/dist/lib/plugins/openapi/interfaces.d.ts +26 -0
  84. package/dist/lib/plugins/openapi/playground/Playground.js +1 -1
  85. package/dist/lib/plugins/openapi/playground/Playground.js.map +1 -1
  86. package/dist/lib/plugins/openapi/playground/result-panel/ResultPanel.js +2 -2
  87. package/dist/lib/plugins/openapi/playground/result-panel/ResultPanel.js.map +1 -1
  88. package/dist/lib/plugins/openapi/schema/LogicalGroup/LogicalGroup.d.ts +1 -2
  89. package/dist/lib/plugins/openapi/schema/LogicalGroup/LogicalGroup.js +2 -2
  90. package/dist/lib/plugins/openapi/schema/LogicalGroup/LogicalGroup.js.map +1 -1
  91. package/dist/lib/plugins/openapi/schema/LogicalGroup/LogicalGroupItem.d.ts +0 -1
  92. package/dist/lib/plugins/openapi/schema/LogicalGroup/LogicalGroupItem.js +1 -1
  93. package/dist/lib/plugins/openapi/schema/LogicalGroup/LogicalGroupItem.js.map +1 -1
  94. package/dist/lib/plugins/openapi/schema/SchemaExampleAndDefault.d.ts +4 -0
  95. package/dist/lib/plugins/openapi/schema/SchemaExampleAndDefault.js +12 -0
  96. package/dist/lib/plugins/openapi/schema/SchemaExampleAndDefault.js.map +1 -0
  97. package/dist/lib/plugins/openapi/schema/SchemaPropertyItem.d.ts +2 -4
  98. package/dist/lib/plugins/openapi/schema/SchemaPropertyItem.js +12 -9
  99. package/dist/lib/plugins/openapi/schema/SchemaPropertyItem.js.map +1 -1
  100. package/dist/lib/plugins/openapi/schema/SchemaView.d.ts +1 -2
  101. package/dist/lib/plugins/openapi/schema/SchemaView.js +30 -52
  102. package/dist/lib/plugins/openapi/schema/SchemaView.js.map +1 -1
  103. package/dist/lib/plugins/openapi/schema/utils.d.ts +1 -0
  104. package/dist/lib/plugins/openapi/schema/utils.js +3 -1
  105. package/dist/lib/plugins/openapi/schema/utils.js.map +1 -1
  106. package/dist/lib/plugins/openapi/state.d.ts +25 -0
  107. package/dist/lib/plugins/openapi/state.js +18 -0
  108. package/dist/lib/plugins/openapi/state.js.map +1 -0
  109. package/dist/lib/plugins/openapi/util/getRoutes.js +9 -3
  110. package/dist/lib/plugins/openapi/util/getRoutes.js.map +1 -1
  111. package/dist/lib/plugins/search-pagefind/PagefindSearch.js +13 -4
  112. package/dist/lib/plugins/search-pagefind/PagefindSearch.js.map +1 -1
  113. package/dist/lib/plugins/search-pagefind/ResultList.js +19 -12
  114. package/dist/lib/plugins/search-pagefind/ResultList.js.map +1 -1
  115. package/dist/lib/plugins/search-pagefind/get-results.d.ts +8 -1
  116. package/dist/lib/plugins/search-pagefind/get-results.js +9 -4
  117. package/dist/lib/plugins/search-pagefind/get-results.js.map +1 -1
  118. package/dist/lib/util/traverse.d.ts +2 -8
  119. package/dist/lib/util/traverse.js.map +1 -1
  120. package/dist/lib/util/types.d.ts +7 -0
  121. package/dist/lib/util/types.js +2 -0
  122. package/dist/lib/util/types.js.map +1 -0
  123. package/dist/lib/util/useOnScreen.d.ts +3 -2
  124. package/dist/lib/util/useOnScreen.js +3 -3
  125. package/dist/lib/util/useOnScreen.js.map +1 -1
  126. package/dist/lib/util/useScrollToAnchor.js +18 -12
  127. package/dist/lib/util/useScrollToAnchor.js.map +1 -1
  128. package/dist/vite/api/schema-codegen.js +2 -2
  129. package/dist/vite/api/schema-codegen.js.map +1 -1
  130. package/dist/vite/api/schema-codegen.test.js +5 -0
  131. package/dist/vite/api/schema-codegen.test.js.map +1 -1
  132. package/dist/vite/plugin-api.js +12 -8
  133. package/dist/vite/plugin-api.js.map +1 -1
  134. package/lib/{AuthenticationPlugin-Cij2tPWa.js → AuthenticationPlugin-foqdvvkf.js} +3 -3
  135. package/lib/{AuthenticationPlugin-Cij2tPWa.js.map → AuthenticationPlugin-foqdvvkf.js.map} +1 -1
  136. package/lib/{Callout-B2vsR09t.js → Callout-D5frCCJ0.js} +2 -2
  137. package/lib/{Callout-B2vsR09t.js.map → Callout-D5frCCJ0.js.map} +1 -1
  138. package/lib/{Dialog-sbgekbjb.js → Dialog-Dv6WG8RN.js} +5 -5
  139. package/lib/{Dialog-sbgekbjb.js.map → Dialog-Dv6WG8RN.js.map} +1 -1
  140. package/lib/{Markdown-DT5Rrq8_.js → Markdown-aF5FdsNi.js} +1945 -1937
  141. package/lib/{Markdown-DT5Rrq8_.js.map → Markdown-aF5FdsNi.js.map} +1 -1
  142. package/lib/MdxPage-ZW1StNhp.js +83 -0
  143. package/lib/MdxPage-ZW1StNhp.js.map +1 -0
  144. package/lib/{OasProvider-DdEBf2qS.js → OasProvider-Cld9RAMQ.js} +4 -4
  145. package/lib/{OasProvider-DdEBf2qS.js.map → OasProvider-Cld9RAMQ.js.map} +1 -1
  146. package/lib/OperationList-D-OfzJm6.js +5065 -0
  147. package/lib/OperationList-D-OfzJm6.js.map +1 -0
  148. package/lib/Pagination-CYB3nVYx.js +46 -0
  149. package/lib/Pagination-CYB3nVYx.js.map +1 -0
  150. package/lib/SchemaList-Ci1WxRh0.js +148 -0
  151. package/lib/SchemaList-Ci1WxRh0.js.map +1 -0
  152. package/lib/SchemaView-Brn-YxHY.js +345 -0
  153. package/lib/SchemaView-Brn-YxHY.js.map +1 -0
  154. package/lib/{Select-z1Lwl0-J.js → Select-DVFRKf1R.js} +8 -8
  155. package/lib/{Select-z1Lwl0-J.js.map → Select-DVFRKf1R.js.map} +1 -1
  156. package/lib/{SlotletProvider-D8OBnr77.js → SlotletProvider-DXvc0aY6.js} +4 -4
  157. package/lib/{SlotletProvider-D8OBnr77.js.map → SlotletProvider-DXvc0aY6.js.map} +1 -1
  158. package/lib/Toc-YBsgI72s.js +92 -0
  159. package/lib/Toc-YBsgI72s.js.map +1 -0
  160. package/lib/{chunk-HA7DTUK3-ZGg2W6yV.js → chunk-HA7DTUK3-C4gP41vD.js} +5 -5
  161. package/lib/{chunk-HA7DTUK3-ZGg2W6yV.js.map → chunk-HA7DTUK3-C4gP41vD.js.map} +1 -1
  162. package/lib/{createServer-DjgKDpGV.js → createServer-mMau3eV_.js} +1732 -1664
  163. package/lib/{createServer-DjgKDpGV.js.map → createServer-mMau3eV_.js.map} +1 -1
  164. package/lib/hook-CqpVYDqN.js +1483 -0
  165. package/lib/hook-CqpVYDqN.js.map +1 -0
  166. package/lib/index-Bt7MKhZq.js +2514 -0
  167. package/lib/index-Bt7MKhZq.js.map +1 -0
  168. package/lib/{index-DdQSV2RF.js → index-CjPMxpOV.js} +809 -750
  169. package/lib/index-CjPMxpOV.js.map +1 -0
  170. package/lib/{mutation-_Z5C2wFZ.js → mutation-8LjrN7uz.js} +2 -2
  171. package/lib/{mutation-_Z5C2wFZ.js.map → mutation-8LjrN7uz.js.map} +1 -1
  172. package/lib/post-processors/traverse.js.map +1 -1
  173. package/lib/ui/Command.js +1 -1
  174. package/lib/{useExposedProps-BslIn-FE.js → useExposedProps-B9qXJedG.js} +2 -2
  175. package/lib/{useExposedProps-BslIn-FE.js.map → useExposedProps-B9qXJedG.js.map} +1 -1
  176. package/lib/zudoku.auth-auth0.js +1 -1
  177. package/lib/zudoku.auth-clerk.js +59 -41
  178. package/lib/zudoku.auth-clerk.js.map +1 -1
  179. package/lib/zudoku.auth-openid.js +76 -73
  180. package/lib/zudoku.auth-openid.js.map +1 -1
  181. package/lib/zudoku.components.js +31 -1440
  182. package/lib/zudoku.components.js.map +1 -1
  183. package/lib/zudoku.hooks.js +1 -1
  184. package/lib/zudoku.plugin-api-catalog.js +81 -79
  185. package/lib/zudoku.plugin-api-catalog.js.map +1 -1
  186. package/lib/zudoku.plugin-api-keys.js +15 -16
  187. package/lib/zudoku.plugin-api-keys.js.map +1 -1
  188. package/lib/zudoku.plugin-custom-pages.js +2 -2
  189. package/lib/zudoku.plugin-markdown.js +1 -1
  190. package/lib/zudoku.plugin-openapi.js +5 -6
  191. package/lib/zudoku.plugin-openapi.js.map +1 -1
  192. package/lib/zudoku.plugin-redirect.js +1 -1
  193. package/lib/zudoku.plugin-search-pagefind.js +133 -98
  194. package/lib/zudoku.plugin-search-pagefind.js.map +1 -1
  195. package/lib/zudoku.plugins.js.map +1 -1
  196. package/package.json +4 -3
  197. package/src/app/main.tsx +2 -0
  198. package/src/app/tailwind.ts +14 -0
  199. package/src/lib/authentication/authentication.ts +2 -0
  200. package/src/lib/authentication/providers/clerk.tsx +20 -0
  201. package/src/lib/authentication/providers/openid.tsx +6 -0
  202. package/src/lib/authentication/providers/supabase.tsx +6 -0
  203. package/src/lib/authentication/state.ts +1 -35
  204. package/src/lib/components/Layout.tsx +17 -17
  205. package/src/lib/components/Main.tsx +3 -1
  206. package/src/lib/components/Pagination.tsx +47 -0
  207. package/src/lib/components/TopNavigation.tsx +29 -2
  208. package/src/lib/components/navigation/SidebarItem.tsx +10 -4
  209. package/src/lib/{plugins/markdown → components/navigation}/Toc.tsx +5 -14
  210. package/src/lib/core/ZudokuContext.ts +13 -6
  211. package/src/lib/core/plugins.ts +1 -1
  212. package/src/lib/oas/graphql/index.ts +118 -45
  213. package/src/lib/oas/parser/dereference/index.ts +2 -0
  214. package/src/lib/oas/parser/index.ts +7 -29
  215. package/src/lib/plugins/api-catalog/index.tsx +40 -35
  216. package/src/lib/plugins/markdown/MdxPage.tsx +6 -43
  217. package/src/lib/plugins/openapi/ColorizedParam.tsx +1 -1
  218. package/src/lib/plugins/openapi/Endpoint.tsx +1 -1
  219. package/src/lib/plugins/openapi/OperationList.tsx +37 -16
  220. package/src/lib/plugins/openapi/OperationListItem.tsx +7 -2
  221. package/src/lib/plugins/openapi/ParameterListItem.tsx +2 -0
  222. package/src/lib/plugins/openapi/SchemaList.tsx +151 -0
  223. package/src/lib/plugins/openapi/Sidecar.tsx +36 -7
  224. package/src/lib/plugins/openapi/client/GraphQLClient.tsx +1 -1
  225. package/src/lib/plugins/openapi/client/useCreateQuery.ts +12 -5
  226. package/src/lib/plugins/openapi/components/EnumValues.tsx +1 -1
  227. package/src/lib/plugins/openapi/graphql/gql.ts +15 -6
  228. package/src/lib/plugins/openapi/graphql/graphql.ts +104 -15
  229. package/src/lib/plugins/openapi/index.tsx +13 -0
  230. package/src/lib/plugins/openapi/interfaces.ts +29 -0
  231. package/src/lib/plugins/openapi/playground/Playground.tsx +1 -1
  232. package/src/lib/plugins/openapi/playground/result-panel/ResultPanel.tsx +2 -1
  233. package/src/lib/plugins/openapi/schema/LogicalGroup/LogicalGroup.tsx +1 -8
  234. package/src/lib/plugins/openapi/schema/LogicalGroup/LogicalGroupItem.tsx +1 -2
  235. package/src/lib/plugins/openapi/schema/SchemaExampleAndDefault.tsx +36 -0
  236. package/src/lib/plugins/openapi/schema/SchemaPropertyItem.tsx +20 -21
  237. package/src/lib/plugins/openapi/schema/SchemaView.tsx +69 -141
  238. package/src/lib/plugins/openapi/schema/utils.ts +7 -1
  239. package/src/lib/plugins/openapi/state.ts +36 -0
  240. package/src/lib/plugins/openapi/util/getRoutes.tsx +9 -6
  241. package/src/lib/plugins/search-pagefind/PagefindSearch.tsx +26 -4
  242. package/src/lib/plugins/search-pagefind/ResultList.tsx +59 -47
  243. package/src/lib/plugins/search-pagefind/get-results.tsx +31 -10
  244. package/src/lib/util/traverse.ts +2 -6
  245. package/src/lib/util/types.ts +7 -0
  246. package/src/lib/util/useOnScreen.ts +6 -4
  247. package/src/lib/util/useScrollToAnchor.ts +20 -12
  248. package/dist/lib/plugins/markdown/Toc.js.map +0 -1
  249. package/lib/MdxPage-D2rD1vC4.js +0 -200
  250. package/lib/MdxPage-D2rD1vC4.js.map +0 -1
  251. package/lib/OperationList-DT4-gm_S.js +0 -5363
  252. package/lib/OperationList-DT4-gm_S.js.map +0 -1
  253. package/lib/hook-DzQC8PzJ.js +0 -355
  254. package/lib/hook-DzQC8PzJ.js.map +0 -1
  255. package/lib/index-DdQSV2RF.js.map +0 -1
  256. package/lib/index.esm-CltAN0Tf.js +0 -711
  257. package/lib/index.esm-CltAN0Tf.js.map +0 -1
  258. package/lib/joinUrl-BjDooT-T.js +0 -1154
  259. package/lib/joinUrl-BjDooT-T.js.map +0 -1
  260. /package/dist/lib/{plugins/markdown → components/navigation}/Toc.d.ts +0 -0
@@ -2,7 +2,8 @@ import { useSuspenseQuery } from "@tanstack/react-query";
2
2
  import { HTTPSnippet } from "@zudoku/httpsnippet";
3
3
  import { useMemo, useState, useTransition } from "react";
4
4
  import { useSearchParams } from "react-router";
5
- import { useSelectedServer } from "../../authentication/state.js";
5
+ import { useZudoku } from "zudoku/components";
6
+ import { useAuthState } from "../../authentication/state.js";
6
7
  import { PathRenderer } from "../../components/PathRenderer.js";
7
8
  import type { SchemaObject } from "../../oas/parser/index.js";
8
9
  import { SyntaxHighlight } from "../../ui/SyntaxHighlight.js";
@@ -19,6 +20,7 @@ import { RequestBodySidecarBox } from "./RequestBodySidecarBox.js";
19
20
  import { ResponsesSidecarBox } from "./ResponsesSidecarBox.js";
20
21
  import * as SidecarBox from "./SidecarBox.js";
21
22
  import { SimpleSelect } from "./SimpleSelect.js";
23
+ import { useSelectedServer } from "./state.js";
22
24
  import { generateSchemaExample } from "./util/generateSchemaExample.js";
23
25
  import { methodForColor } from "./util/methodToColor.js";
24
26
 
@@ -101,8 +103,10 @@ export const Sidecar = ({
101
103
  onSelectResponse: (response: string) => void;
102
104
  }) => {
103
105
  const { input, type, options } = useOasConfig();
106
+ const auth = useAuthState();
104
107
  const query = useCreateQuery(GetServerQuery, { input, type });
105
108
  const result = useSuspenseQuery(query);
109
+ const context = useZudoku();
106
110
 
107
111
  const methodTextColor = methodForColor(operation.method);
108
112
 
@@ -115,6 +119,17 @@ export const Sidecar = ({
115
119
 
116
120
  const requestBodyContent = operation.requestBody?.content;
117
121
 
122
+ const transformedRequestBodyContent =
123
+ requestBodyContent && options?.transformExamples
124
+ ? options.transformExamples({
125
+ auth,
126
+ type: "request",
127
+ operation,
128
+ content: requestBodyContent,
129
+ context,
130
+ })
131
+ : requestBodyContent;
132
+
118
133
  const path = (
119
134
  <PathRenderer
120
135
  path={operation.path}
@@ -136,8 +151,10 @@ export const Sidecar = ({
136
151
  const code = useMemo(() => {
137
152
  const example =
138
153
  selectedExample ??
139
- (requestBodyContent?.[0]?.schema
140
- ? generateSchemaExample(requestBodyContent[0].schema as SchemaObject)
154
+ (transformedRequestBodyContent?.[0]?.schema
155
+ ? generateSchemaExample(
156
+ transformedRequestBodyContent[0].schema as SchemaObject,
157
+ )
141
158
  : undefined);
142
159
 
143
160
  const snippet = new HTTPSnippet({
@@ -162,7 +179,7 @@ export const Sidecar = ({
162
179
  return getConverted(snippet, selectedLang);
163
180
  }, [
164
181
  selectedExample,
165
- requestBodyContent,
182
+ transformedRequestBodyContent,
166
183
  operation.method,
167
184
  operation.path,
168
185
  selectedServer,
@@ -232,9 +249,9 @@ export const Sidecar = ({
232
249
  </>
233
250
  )}
234
251
  </SidecarBox.Root>
235
- {isOnScreen && requestBodyContent && (
252
+ {isOnScreen && transformedRequestBodyContent && (
236
253
  <RequestBodySidecarBox
237
- content={requestBodyContent}
254
+ content={transformedRequestBodyContent}
238
255
  onExampleChange={setSelectedExample}
239
256
  />
240
257
  )}
@@ -242,7 +259,19 @@ export const Sidecar = ({
242
259
  <ResponsesSidecarBox
243
260
  selectedResponse={selectedResponse}
244
261
  onSelectResponse={onSelectResponse}
245
- responses={operation.responses}
262
+ responses={operation.responses.map((response) => ({
263
+ ...response,
264
+ content:
265
+ response.content && options?.transformExamples
266
+ ? options.transformExamples({
267
+ auth,
268
+ type: "response",
269
+ context,
270
+ operation,
271
+ content: response.content,
272
+ })
273
+ : response.content,
274
+ }))}
246
275
  />
247
276
  )}
248
277
  </aside>
@@ -43,7 +43,7 @@ export class GraphQLClient {
43
43
 
44
44
  fetch = async <TResult, TVariables>(
45
45
  query: TypedDocumentString<TResult, TVariables>,
46
- ...[variables]: TVariables extends Record<string, never> ? [] : [TVariables]
46
+ variables?: TVariables,
47
47
  ): Promise<TResult> => {
48
48
  const operationName = query.match(/query (\w+)/)?.[1];
49
49
 
@@ -1,19 +1,26 @@
1
1
  import { stripIgnoredCharacters } from "graphql";
2
- import { useContext } from "react";
2
+ import { use } from "react";
3
3
  import type { TypedDocumentString } from "../graphql/graphql.js";
4
4
  import { GraphQLContext } from "./GraphQLContext.js";
5
5
 
6
+ type NoExtraProps<T, U extends T = T> = U & {
7
+ [K in Exclude<keyof U, keyof T>]?: never;
8
+ };
9
+
6
10
  export const useCreateQuery = <TResult, TVariables>(
7
11
  query: TypedDocumentString<TResult, TVariables>,
8
- ...variables: TVariables extends Record<string, never> ? [] : [TVariables]
12
+ ...[variables]: TVariables extends Record<string, never>
13
+ ? []
14
+ : [NoExtraProps<TVariables>]
9
15
  ) => {
10
- const graphQLClient = useContext(GraphQLContext);
16
+ const graphQLClient = use(GraphQLContext);
17
+
11
18
  if (graphQLClient === undefined) {
12
19
  throw new Error("useGraphQL must be used within a GraphQLProvider");
13
20
  }
14
21
 
15
22
  return {
16
- queryFn: () => graphQLClient.fetch(query, ...variables),
17
- queryKey: [stripIgnoredCharacters(query.toString()), variables[0]],
23
+ queryFn: () => graphQLClient.fetch(query, variables),
24
+ queryKey: [stripIgnoredCharacters(query.toString()), variables],
18
25
  } as const;
19
26
  };
@@ -26,7 +26,7 @@ export const EnumValues = ({
26
26
  <span className="text-muted-foreground">Enum values: </span>
27
27
  {visibleValues.map((value) => (
28
28
  <div key={value}>
29
- <SelectOnClick className="border rounded px-1 font-mono cursor-pointer">
29
+ <SelectOnClick className="border rounded px-1 font-mono">
30
30
  {value}
31
31
  </SelectOnClick>
32
32
  </div>
@@ -16,9 +16,10 @@ type Documents = {
16
16
  "\n query ServersQuery($input: JSON!, $type: SchemaType!) {\n schema(input: $input, type: $type) {\n url\n servers {\n url\n }\n }\n }\n": typeof types.ServersQueryDocument;
17
17
  "\n fragment OperationsFragment on OperationItem {\n slug\n summary\n method\n description\n operationId\n contentTypes\n path\n deprecated\n extensions\n parameters {\n name\n in\n description\n required\n schema\n style\n explode\n examples {\n name\n description\n externalValue\n value\n summary\n }\n }\n requestBody {\n content {\n mediaType\n encoding {\n name\n }\n examples {\n name\n description\n externalValue\n value\n summary\n }\n schema\n }\n description\n required\n }\n responses {\n statusCode\n links\n description\n content {\n examples {\n name\n description\n externalValue\n value\n summary\n }\n mediaType\n encoding {\n name\n }\n schema\n }\n }\n }\n": typeof types.OperationsFragmentFragmentDoc;
18
18
  "\n query SchemaWarmup($input: JSON!, $type: SchemaType!) {\n schema(input: $input, type: $type) {\n openapi\n }\n }\n": typeof types.SchemaWarmupDocument;
19
- "\n query OperationsForTag(\n $input: JSON!\n $type: SchemaType!\n $tag: String\n $untagged: Boolean\n ) {\n schema(input: $input, type: $type) {\n servers {\n url\n }\n description\n summary\n title\n url\n version\n tags(name: $tag) {\n name\n description\n }\n operations(tag: $tag, untagged: $untagged) {\n slug\n ...OperationsFragment\n }\n }\n }\n": typeof types.OperationsForTagDocument;
19
+ "\n query OperationsForTag(\n $input: JSON!\n $type: SchemaType!\n $tag: String\n $untagged: Boolean\n ) {\n schema(input: $input, type: $type) {\n servers {\n url\n }\n description\n summary\n title\n url\n version\n tag(slug: $tag, untagged: $untagged) {\n name\n description\n operations {\n slug\n ...OperationsFragment\n }\n next {\n name\n slug\n }\n prev {\n name\n slug\n }\n }\n }\n }\n": typeof types.OperationsForTagDocument;
20
+ "\n query GetSchemas($input: JSON!, $type: SchemaType!) {\n schema(input: $input, type: $type) {\n title\n description\n summary\n components {\n schemas {\n name\n schema\n extensions\n }\n }\n }\n }\n": typeof types.GetSchemasDocument;
20
21
  "\n query getServerQuery($input: JSON!, $type: SchemaType!) {\n schema(input: $input, type: $type) {\n url\n servers {\n url\n }\n }\n }\n": typeof types.GetServerQueryDocument;
21
- "\n query GetSidebarOperations($input: JSON!, $type: SchemaType!) {\n schema(input: $input, type: $type) {\n tags {\n slug\n name\n extensions\n operations {\n summary\n slug\n method\n operationId\n path\n }\n }\n }\n }\n": typeof types.GetSidebarOperationsDocument;
22
+ "\n query GetSidebarOperations($input: JSON!, $type: SchemaType!) {\n schema(input: $input, type: $type) {\n tags {\n slug\n name\n extensions\n operations {\n summary\n slug\n method\n operationId\n path\n }\n }\n components {\n schemas {\n __typename\n }\n }\n }\n }\n": typeof types.GetSidebarOperationsDocument;
22
23
  };
23
24
  const documents: Documents = {
24
25
  "\n query ServersQuery($input: JSON!, $type: SchemaType!) {\n schema(input: $input, type: $type) {\n url\n servers {\n url\n }\n }\n }\n":
@@ -27,11 +28,13 @@ const documents: Documents = {
27
28
  types.OperationsFragmentFragmentDoc,
28
29
  "\n query SchemaWarmup($input: JSON!, $type: SchemaType!) {\n schema(input: $input, type: $type) {\n openapi\n }\n }\n":
29
30
  types.SchemaWarmupDocument,
30
- "\n query OperationsForTag(\n $input: JSON!\n $type: SchemaType!\n $tag: String\n $untagged: Boolean\n ) {\n schema(input: $input, type: $type) {\n servers {\n url\n }\n description\n summary\n title\n url\n version\n tags(name: $tag) {\n name\n description\n }\n operations(tag: $tag, untagged: $untagged) {\n slug\n ...OperationsFragment\n }\n }\n }\n":
31
+ "\n query OperationsForTag(\n $input: JSON!\n $type: SchemaType!\n $tag: String\n $untagged: Boolean\n ) {\n schema(input: $input, type: $type) {\n servers {\n url\n }\n description\n summary\n title\n url\n version\n tag(slug: $tag, untagged: $untagged) {\n name\n description\n operations {\n slug\n ...OperationsFragment\n }\n next {\n name\n slug\n }\n prev {\n name\n slug\n }\n }\n }\n }\n":
31
32
  types.OperationsForTagDocument,
33
+ "\n query GetSchemas($input: JSON!, $type: SchemaType!) {\n schema(input: $input, type: $type) {\n title\n description\n summary\n components {\n schemas {\n name\n schema\n extensions\n }\n }\n }\n }\n":
34
+ types.GetSchemasDocument,
32
35
  "\n query getServerQuery($input: JSON!, $type: SchemaType!) {\n schema(input: $input, type: $type) {\n url\n servers {\n url\n }\n }\n }\n":
33
36
  types.GetServerQueryDocument,
34
- "\n query GetSidebarOperations($input: JSON!, $type: SchemaType!) {\n schema(input: $input, type: $type) {\n tags {\n slug\n name\n extensions\n operations {\n summary\n slug\n method\n operationId\n path\n }\n }\n }\n }\n":
37
+ "\n query GetSidebarOperations($input: JSON!, $type: SchemaType!) {\n schema(input: $input, type: $type) {\n tags {\n slug\n name\n extensions\n operations {\n summary\n slug\n method\n operationId\n path\n }\n }\n components {\n schemas {\n __typename\n }\n }\n }\n }\n":
35
38
  types.GetSidebarOperationsDocument,
36
39
  };
37
40
 
@@ -57,8 +60,14 @@ export function graphql(
57
60
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
58
61
  */
59
62
  export function graphql(
60
- source: "\n query OperationsForTag(\n $input: JSON!\n $type: SchemaType!\n $tag: String\n $untagged: Boolean\n ) {\n schema(input: $input, type: $type) {\n servers {\n url\n }\n description\n summary\n title\n url\n version\n tags(name: $tag) {\n name\n description\n }\n operations(tag: $tag, untagged: $untagged) {\n slug\n ...OperationsFragment\n }\n }\n }\n",
63
+ source: "\n query OperationsForTag(\n $input: JSON!\n $type: SchemaType!\n $tag: String\n $untagged: Boolean\n ) {\n schema(input: $input, type: $type) {\n servers {\n url\n }\n description\n summary\n title\n url\n version\n tag(slug: $tag, untagged: $untagged) {\n name\n description\n operations {\n slug\n ...OperationsFragment\n }\n next {\n name\n slug\n }\n prev {\n name\n slug\n }\n }\n }\n }\n",
61
64
  ): typeof import("./graphql.js").OperationsForTagDocument;
65
+ /**
66
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
67
+ */
68
+ export function graphql(
69
+ source: "\n query GetSchemas($input: JSON!, $type: SchemaType!) {\n schema(input: $input, type: $type) {\n title\n description\n summary\n components {\n schemas {\n name\n schema\n extensions\n }\n }\n }\n }\n",
70
+ ): typeof import("./graphql.js").GetSchemasDocument;
62
71
  /**
63
72
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
64
73
  */
@@ -69,7 +78,7 @@ export function graphql(
69
78
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
70
79
  */
71
80
  export function graphql(
72
- source: "\n query GetSidebarOperations($input: JSON!, $type: SchemaType!) {\n schema(input: $input, type: $type) {\n tags {\n slug\n name\n extensions\n operations {\n summary\n slug\n method\n operationId\n path\n }\n }\n }\n }\n",
81
+ source: "\n query GetSidebarOperations($input: JSON!, $type: SchemaType!) {\n schema(input: $input, type: $type) {\n tags {\n slug\n name\n extensions\n operations {\n summary\n slug\n method\n operationId\n path\n }\n }\n components {\n schemas {\n __typename\n }\n }\n }\n }\n",
73
82
  ): typeof import("./graphql.js").GetSidebarOperationsDocument;
74
83
 
75
84
  export function graphql(source: string) {
@@ -35,6 +35,11 @@ export type Scalars = {
35
35
  JSONSchema: { input: any; output: any };
36
36
  };
37
37
 
38
+ export type Components = {
39
+ __typename?: "Components";
40
+ schemas?: Maybe<Array<SchemaItem>>;
41
+ };
42
+
38
43
  export type EncodingItem = {
39
44
  __typename?: "EncodingItem";
40
45
  allowReserved?: Maybe<Scalars["Boolean"]["output"]>;
@@ -132,6 +137,7 @@ export type ResponseItem = {
132
137
 
133
138
  export type Schema = {
134
139
  __typename?: "Schema";
140
+ components?: Maybe<Components>;
135
141
  description?: Maybe<Scalars["String"]["output"]>;
136
142
  extensions?: Maybe<Scalars["JSONObject"]["output"]>;
137
143
  openapi: Scalars["String"]["output"];
@@ -139,6 +145,7 @@ export type Schema = {
139
145
  paths: Array<PathItem>;
140
146
  servers: Array<Server>;
141
147
  summary?: Maybe<Scalars["String"]["output"]>;
148
+ tag?: Maybe<SchemaTag>;
142
149
  tags: Array<SchemaTag>;
143
150
  title: Scalars["String"]["output"];
144
151
  url?: Maybe<Scalars["String"]["output"]>;
@@ -153,16 +160,28 @@ export type SchemaOperationsArgs = {
153
160
  untagged?: InputMaybe<Scalars["Boolean"]["input"]>;
154
161
  };
155
162
 
156
- export type SchemaTagsArgs = {
163
+ export type SchemaTagArgs = {
157
164
  name?: InputMaybe<Scalars["String"]["input"]>;
165
+ slug?: InputMaybe<Scalars["String"]["input"]>;
166
+ untagged?: InputMaybe<Scalars["Boolean"]["input"]>;
167
+ };
168
+
169
+ export type SchemaItem = {
170
+ __typename?: "SchemaItem";
171
+ extensions?: Maybe<Scalars["JSONObject"]["output"]>;
172
+ name: Scalars["String"]["output"];
173
+ schema: Scalars["JSONSchema"]["output"];
158
174
  };
159
175
 
160
176
  export type SchemaTag = {
161
177
  __typename?: "SchemaTag";
162
178
  description?: Maybe<Scalars["String"]["output"]>;
163
179
  extensions?: Maybe<Scalars["JSONObject"]["output"]>;
180
+ isUntagged: Scalars["Boolean"]["output"];
164
181
  name?: Maybe<Scalars["String"]["output"]>;
182
+ next?: Maybe<SchemaTag>;
165
183
  operations: Array<OperationItem>;
184
+ prev?: Maybe<SchemaTag>;
166
185
  slug?: Maybe<Scalars["String"]["output"]>;
167
186
  };
168
187
 
@@ -292,18 +311,52 @@ export type OperationsForTagQuery = {
292
311
  url?: string | null;
293
312
  version: string;
294
313
  servers: Array<{ __typename?: "Server"; url: string }>;
295
- tags: Array<{
314
+ tag?: {
296
315
  __typename?: "SchemaTag";
297
316
  name?: string | null;
298
317
  description?: string | null;
299
- }>;
300
- operations: Array<
301
- { __typename?: "OperationItem"; slug: string } & {
302
- " $fragmentRefs"?: {
303
- OperationsFragmentFragment: OperationsFragmentFragment;
304
- };
305
- }
306
- >;
318
+ operations: Array<
319
+ { __typename?: "OperationItem"; slug: string } & {
320
+ " $fragmentRefs"?: {
321
+ OperationsFragmentFragment: OperationsFragmentFragment;
322
+ };
323
+ }
324
+ >;
325
+ next?: {
326
+ __typename?: "SchemaTag";
327
+ name?: string | null;
328
+ slug?: string | null;
329
+ } | null;
330
+ prev?: {
331
+ __typename?: "SchemaTag";
332
+ name?: string | null;
333
+ slug?: string | null;
334
+ } | null;
335
+ } | null;
336
+ };
337
+ };
338
+
339
+ export type GetSchemasQueryVariables = Exact<{
340
+ input: Scalars["JSON"]["input"];
341
+ type: SchemaType;
342
+ }>;
343
+
344
+ export type GetSchemasQuery = {
345
+ __typename?: "Query";
346
+ schema: {
347
+ __typename?: "Schema";
348
+ title: string;
349
+ description?: string | null;
350
+ summary?: string | null;
351
+ components?: {
352
+ __typename?: "Components";
353
+ schemas?: Array<{
354
+ __typename?: "SchemaItem";
355
+ name: string;
356
+ schema: any;
357
+ extensions?: any | null;
358
+ }> | null;
359
+ } | null;
307
360
  };
308
361
  };
309
362
 
@@ -344,6 +397,10 @@ export type GetSidebarOperationsQuery = {
344
397
  path: string;
345
398
  }>;
346
399
  }>;
400
+ components?: {
401
+ __typename?: "Components";
402
+ schemas?: Array<{ __typename: "SchemaItem" }> | null;
403
+ } | null;
347
404
  };
348
405
  };
349
406
 
@@ -468,13 +525,21 @@ export const OperationsForTagDocument = new TypedDocumentString(`
468
525
  title
469
526
  url
470
527
  version
471
- tags(name: $tag) {
528
+ tag(slug: $tag, untagged: $untagged) {
472
529
  name
473
530
  description
474
- }
475
- operations(tag: $tag, untagged: $untagged) {
476
- slug
477
- ...OperationsFragment
531
+ operations {
532
+ slug
533
+ ...OperationsFragment
534
+ }
535
+ next {
536
+ name
537
+ slug
538
+ }
539
+ prev {
540
+ name
541
+ slug
542
+ }
478
543
  }
479
544
  }
480
545
  }
@@ -545,6 +610,25 @@ export const OperationsForTagDocument = new TypedDocumentString(`
545
610
  OperationsForTagQuery,
546
611
  OperationsForTagQueryVariables
547
612
  >;
613
+ export const GetSchemasDocument = new TypedDocumentString(`
614
+ query GetSchemas($input: JSON!, $type: SchemaType!) {
615
+ schema(input: $input, type: $type) {
616
+ title
617
+ description
618
+ summary
619
+ components {
620
+ schemas {
621
+ name
622
+ schema
623
+ extensions
624
+ }
625
+ }
626
+ }
627
+ }
628
+ `) as unknown as TypedDocumentString<
629
+ GetSchemasQuery,
630
+ GetSchemasQueryVariables
631
+ >;
548
632
  export const GetServerQueryDocument = new TypedDocumentString(`
549
633
  query getServerQuery($input: JSON!, $type: SchemaType!) {
550
634
  schema(input: $input, type: $type) {
@@ -573,6 +657,11 @@ export const GetSidebarOperationsDocument = new TypedDocumentString(`
573
657
  path
574
658
  }
575
659
  }
660
+ components {
661
+ schemas {
662
+ __typename
663
+ }
664
+ }
576
665
  }
577
666
  }
578
667
  `) as unknown as TypedDocumentString<
@@ -29,6 +29,11 @@ const GetSidebarOperationsQuery = graphql(`
29
29
  path
30
30
  }
31
31
  }
32
+ components {
33
+ schemas {
34
+ __typename
35
+ }
36
+ }
32
37
  }
33
38
  }
34
39
  `);
@@ -168,6 +173,14 @@ export const openApiPlugin = (config: OasPluginConfig): ZudokuPlugin => {
168
173
  );
169
174
  }
170
175
 
176
+ if (data.schema.components?.schemas?.length) {
177
+ categories.push({
178
+ type: "link" as const,
179
+ label: "Schemas",
180
+ href: joinUrl(basePath, versionParam, "~schemas"),
181
+ });
182
+ }
183
+
171
184
  return categories;
172
185
  } catch {
173
186
  return [];
@@ -1,4 +1,7 @@
1
+ import { AuthState } from "../../authentication/state.js";
2
+ import { ZudokuContext } from "../../core/ZudokuContext.js";
1
3
  import type { SchemaImports } from "../../oas/graphql/index.js";
4
+ import { OperationListItemResult } from "./OperationList.js";
2
5
 
3
6
  type DynamicInput = () => Promise<unknown>;
4
7
 
@@ -12,6 +15,31 @@ export type ContextOasSource =
12
15
  | { type: "file"; input: DynamicInput }
13
16
  | { type: "raw"; input: string };
14
17
 
18
+ type Example = {
19
+ name: string;
20
+ description?: string | null;
21
+ externalValue?: string | null;
22
+ value?: any | null;
23
+ summary?: string | null;
24
+ };
25
+
26
+ type Content = {
27
+ mediaType: string;
28
+ schema?: any | null;
29
+ encoding?: Array<{
30
+ name: string;
31
+ }> | null;
32
+ examples?: Array<Example> | null;
33
+ };
34
+
35
+ export type transformExamples = (options: {
36
+ content: Content[];
37
+ context: ZudokuContext;
38
+ auth: AuthState;
39
+ operation: OperationListItemResult;
40
+ type: "request" | "response";
41
+ }) => Content[];
42
+
15
43
  type BaseOasConfig = {
16
44
  server?: string;
17
45
  navigationId?: string;
@@ -23,6 +51,7 @@ type BaseOasConfig = {
23
51
  disablePlayground?: boolean;
24
52
  showVersionSelect?: "always" | "if-available" | "hide";
25
53
  expandAllTags?: boolean;
54
+ transformExamples?: transformExamples;
26
55
  };
27
56
  };
28
57
 
@@ -13,7 +13,6 @@ import {
13
13
  SelectValue,
14
14
  } from "zudoku/ui/Select.js";
15
15
  import { Textarea } from "zudoku/ui/Textarea.js";
16
- import { useSelectedServer } from "../../../authentication/state.js";
17
16
  import { useApiIdentities } from "../../../components/context/ZudokuContext.js";
18
17
  import { Tabs, TabsContent, TabsList, TabsTrigger } from "../../../ui/Tabs.js";
19
18
  import { cn } from "../../../util/cn.js";
@@ -21,6 +20,7 @@ import { objectEntries } from "../../../util/objectEntries.js";
21
20
  import { useLatest } from "../../../util/useLatest.js";
22
21
  import { ColorizedParam } from "../ColorizedParam.js";
23
22
  import { type Content } from "../SidecarExamples.js";
23
+ import { useSelectedServer } from "../state.js";
24
24
  import { createUrl } from "./createUrl.js";
25
25
  import ExamplesDropdown from "./ExamplesDropdown.js";
26
26
  import { Headers } from "./Headers.js";
@@ -32,7 +32,7 @@ export const ResultPanel = ({
32
32
  }) => {
33
33
  const status = ((queryMutation.data?.status ?? 0) / 100).toFixed(0);
34
34
  return (
35
- <div className="min-w-0 p-4 bg-muted/50">
35
+ <div className="min-w-0 p-4 py-8 bg-muted/50">
36
36
  {queryMutation.error ? (
37
37
  <div className="flex flex-col gap-2">
38
38
  {showPathParamsWarning && (
@@ -99,6 +99,7 @@ export const ResultPanel = ({
99
99
  >
100
100
  Looks like the request is taking longer than expected.
101
101
  <Button
102
+ type="button"
102
103
  onClick={onCancel}
103
104
  size="sm"
104
105
  className="w-fit"
@@ -15,14 +15,12 @@ export const LogicalGroup = ({
15
15
  schemas,
16
16
  type,
17
17
  isOpen,
18
- level,
19
18
  toggleOpen,
20
19
  }: {
21
20
  schemas: SchemaObject[];
22
21
  type: LogicalGroupType;
23
22
  isOpen: boolean;
24
23
  toggleOpen: () => void;
25
- level: number;
26
24
  }) => (
27
25
  <Collapsible.Root open={isOpen} onOpenChange={toggleOpen} asChild>
28
26
  <Card className="px-6">
@@ -34,12 +32,7 @@ export const LogicalGroup = ({
34
32
  <Collapsible.Content className="pb-4">
35
33
  {schemas.map((subSchema, index) => (
36
34
  // eslint-disable-next-line react/no-array-index-key
37
- <LogicalGroupItem
38
- key={index}
39
- type={type}
40
- schema={subSchema}
41
- level={level}
42
- />
35
+ <LogicalGroupItem key={index} type={type} schema={subSchema} />
43
36
  ))}
44
37
  </Collapsible.Content>
45
38
  </Card>
@@ -8,7 +8,6 @@ import { LogicalGroupConnector } from "./LogicalGroupConnector.js";
8
8
  export const LogicalGroupItem = (props: {
9
9
  type: LogicalGroupType;
10
10
  schema: SchemaObject;
11
- level: number;
12
11
  }) => {
13
12
  const [isOpen, setIsOpen] = useState(true);
14
13
 
@@ -23,7 +22,7 @@ export const LogicalGroupItem = (props: {
23
22
  </Collapsible.Trigger>
24
23
  {!isOpen && <div className="wavy-line bg-border translate-y-1" />}
25
24
  <Collapsible.Content>
26
- <SchemaView schema={props.schema} level={props.level + 1} />
25
+ <SchemaView schema={props.schema} />
27
26
  </Collapsible.Content>
28
27
  </Collapsible.Root>
29
28
  );
@@ -0,0 +1,36 @@
1
+ import type { SchemaObject } from "../../../oas/parser/index.js";
2
+ import { SelectOnClick } from "../components/SelectOnClick.js";
3
+
4
+ export const SchemaExampleAndDefault = ({
5
+ schema,
6
+ }: {
7
+ schema: SchemaObject;
8
+ }) => {
9
+ const example = schema.examples?.at(0);
10
+ const defaultValue = schema.default;
11
+
12
+ if (!example && !defaultValue) return null;
13
+
14
+ return (
15
+ <div className="flex flex-col gap-1 text-xs">
16
+ {example && (
17
+ <div>
18
+ <span className="text-muted-foreground">Example: </span>
19
+ <SelectOnClick className="border rounded px-1 font-mono">
20
+ {typeof example === "object" ? JSON.stringify(example) : example}
21
+ </SelectOnClick>
22
+ </div>
23
+ )}
24
+ {defaultValue && (
25
+ <div>
26
+ <span className="text-muted-foreground">Default: </span>
27
+ <SelectOnClick className="border rounded px-1 font-mono">
28
+ {typeof defaultValue === "object"
29
+ ? JSON.stringify(defaultValue)
30
+ : defaultValue}
31
+ </SelectOnClick>
32
+ </div>
33
+ )}
34
+ </div>
35
+ );
36
+ };