vocs 2.0.17 → 2.1.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 (306) hide show
  1. package/dist/config.d.ts +1 -0
  2. package/dist/config.d.ts.map +1 -1
  3. package/dist/config.js +1 -0
  4. package/dist/config.js.map +1 -1
  5. package/dist/globals.d.ts +16 -0
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/internal/config.d.ts +28 -0
  11. package/dist/internal/config.d.ts.map +1 -1
  12. package/dist/internal/config.js +10 -2
  13. package/dist/internal/config.js.map +1 -1
  14. package/dist/internal/llms.d.ts +21 -2
  15. package/dist/internal/llms.d.ts.map +1 -1
  16. package/dist/internal/llms.js +41 -1
  17. package/dist/internal/llms.js.map +1 -1
  18. package/dist/internal/markdown-negotiation.d.ts +36 -0
  19. package/dist/internal/markdown-negotiation.d.ts.map +1 -0
  20. package/dist/internal/markdown-negotiation.js +81 -0
  21. package/dist/internal/markdown-negotiation.js.map +1 -0
  22. package/dist/internal/markdown.d.ts.map +1 -1
  23. package/dist/internal/markdown.js +5 -0
  24. package/dist/internal/markdown.js.map +1 -1
  25. package/dist/internal/openapi/anchors.d.ts +25 -0
  26. package/dist/internal/openapi/anchors.d.ts.map +1 -0
  27. package/dist/internal/openapi/anchors.js +37 -0
  28. package/dist/internal/openapi/anchors.js.map +1 -0
  29. package/dist/internal/openapi/app.d.ts +89 -0
  30. package/dist/internal/openapi/app.d.ts.map +1 -0
  31. package/dist/internal/openapi/app.js +62 -0
  32. package/dist/internal/openapi/app.js.map +1 -0
  33. package/dist/internal/openapi/index.d.ts +8 -0
  34. package/dist/internal/openapi/index.d.ts.map +1 -0
  35. package/dist/internal/openapi/index.js +5 -0
  36. package/dist/internal/openapi/index.js.map +1 -0
  37. package/dist/internal/openapi/markdown.d.ts +42 -0
  38. package/dist/internal/openapi/markdown.d.ts.map +1 -0
  39. package/dist/internal/openapi/markdown.js +235 -0
  40. package/dist/internal/openapi/markdown.js.map +1 -0
  41. package/dist/internal/openapi/openapi.d.ts +187 -0
  42. package/dist/internal/openapi/openapi.d.ts.map +1 -0
  43. package/dist/internal/openapi/openapi.js +44 -0
  44. package/dist/internal/openapi/openapi.js.map +1 -0
  45. package/dist/internal/openapi/openrpc.d.ts +90 -0
  46. package/dist/internal/openapi/openrpc.d.ts.map +1 -0
  47. package/dist/internal/openapi/openrpc.js +213 -0
  48. package/dist/internal/openapi/openrpc.js.map +1 -0
  49. package/dist/internal/openapi/parser.d.ts +181 -0
  50. package/dist/internal/openapi/parser.d.ts.map +1 -0
  51. package/dist/internal/openapi/parser.js +329 -0
  52. package/dist/internal/openapi/parser.js.map +1 -0
  53. package/dist/internal/openapi/registry.d.ts +36 -0
  54. package/dist/internal/openapi/registry.d.ts.map +1 -0
  55. package/dist/internal/openapi/registry.js +79 -0
  56. package/dist/internal/openapi/registry.js.map +1 -0
  57. package/dist/internal/openapi/sample.d.ts +115 -0
  58. package/dist/internal/openapi/sample.d.ts.map +1 -0
  59. package/dist/internal/openapi/sample.js +434 -0
  60. package/dist/internal/openapi/sample.js.map +1 -0
  61. package/dist/internal/openapi/search.d.ts +19 -0
  62. package/dist/internal/openapi/search.d.ts.map +1 -0
  63. package/dist/internal/openapi/search.js +98 -0
  64. package/dist/internal/openapi/search.js.map +1 -0
  65. package/dist/internal/openapi/sidebar.d.ts +30 -0
  66. package/dist/internal/openapi/sidebar.d.ts.map +1 -0
  67. package/dist/internal/openapi/sidebar.js +67 -0
  68. package/dist/internal/openapi/sidebar.js.map +1 -0
  69. package/dist/internal/openapi/union.d.ts +36 -0
  70. package/dist/internal/openapi/union.d.ts.map +1 -0
  71. package/dist/internal/openapi/union.js +69 -0
  72. package/dist/internal/openapi/union.js.map +1 -0
  73. package/dist/internal/search.d.ts.map +1 -1
  74. package/dist/internal/search.js +20 -0
  75. package/dist/internal/search.js.map +1 -1
  76. package/dist/internal/vite-plugins.d.ts +12 -0
  77. package/dist/internal/vite-plugins.d.ts.map +1 -1
  78. package/dist/internal/vite-plugins.js +102 -11
  79. package/dist/internal/vite-plugins.js.map +1 -1
  80. package/dist/react/Badge.d.ts +2 -3
  81. package/dist/react/Badge.d.ts.map +1 -1
  82. package/dist/react/Layout.client.d.ts.map +1 -1
  83. package/dist/react/Layout.client.js +2 -2
  84. package/dist/react/Layout.client.js.map +1 -1
  85. package/dist/react/OpenApi.d.ts +6 -0
  86. package/dist/react/OpenApi.d.ts.map +1 -0
  87. package/dist/react/OpenApi.js +6 -0
  88. package/dist/react/OpenApi.js.map +1 -0
  89. package/dist/react/internal/CodeToHtml.client.d.ts +53 -2
  90. package/dist/react/internal/CodeToHtml.client.d.ts.map +1 -1
  91. package/dist/react/internal/CodeToHtml.client.js +154 -21
  92. package/dist/react/internal/CodeToHtml.client.js.map +1 -1
  93. package/dist/react/internal/Sidebar.d.ts.map +1 -1
  94. package/dist/react/internal/Sidebar.js +99 -2
  95. package/dist/react/internal/Sidebar.js.map +1 -1
  96. package/dist/react/internal/openapi/CodeSample.client.d.ts +21 -0
  97. package/dist/react/internal/openapi/CodeSample.client.d.ts.map +1 -0
  98. package/dist/react/internal/openapi/CodeSample.client.js +134 -0
  99. package/dist/react/internal/openapi/CodeSample.client.js.map +1 -0
  100. package/dist/react/internal/openapi/CollapsibleChildren.client.d.ts +17 -0
  101. package/dist/react/internal/openapi/CollapsibleChildren.client.d.ts.map +1 -0
  102. package/dist/react/internal/openapi/CollapsibleChildren.client.js +18 -0
  103. package/dist/react/internal/openapi/CollapsibleChildren.client.js.map +1 -0
  104. package/dist/react/internal/openapi/Disclosure.client.d.ts +28 -0
  105. package/dist/react/internal/openapi/Disclosure.client.d.ts.map +1 -0
  106. package/dist/react/internal/openapi/Disclosure.client.js +38 -0
  107. package/dist/react/internal/openapi/Disclosure.client.js.map +1 -0
  108. package/dist/react/internal/openapi/Endpoints.d.ts +26 -0
  109. package/dist/react/internal/openapi/Endpoints.d.ts.map +1 -0
  110. package/dist/react/internal/openapi/Endpoints.js +33 -0
  111. package/dist/react/internal/openapi/Endpoints.js.map +1 -0
  112. package/dist/react/internal/openapi/EndpointsView.d.ts +24 -0
  113. package/dist/react/internal/openapi/EndpointsView.d.ts.map +1 -0
  114. package/dist/react/internal/openapi/EndpointsView.js +26 -0
  115. package/dist/react/internal/openapi/EndpointsView.js.map +1 -0
  116. package/dist/react/internal/openapi/EnumValues.client.d.ts +14 -0
  117. package/dist/react/internal/openapi/EnumValues.client.d.ts.map +1 -0
  118. package/dist/react/internal/openapi/EnumValues.client.js +20 -0
  119. package/dist/react/internal/openapi/EnumValues.client.js.map +1 -0
  120. package/dist/react/internal/openapi/HeadingAnchor.d.ts +15 -0
  121. package/dist/react/internal/openapi/HeadingAnchor.d.ts.map +1 -0
  122. package/dist/react/internal/openapi/HeadingAnchor.js +12 -0
  123. package/dist/react/internal/openapi/HeadingAnchor.js.map +1 -0
  124. package/dist/react/internal/openapi/OpenApiPage.d.ts +79 -0
  125. package/dist/react/internal/openapi/OpenApiPage.d.ts.map +1 -0
  126. package/dist/react/internal/openapi/OpenApiPage.js +72 -0
  127. package/dist/react/internal/openapi/OpenApiPage.js.map +1 -0
  128. package/dist/react/internal/openapi/Operation.d.ts +25 -0
  129. package/dist/react/internal/openapi/Operation.d.ts.map +1 -0
  130. package/dist/react/internal/openapi/Operation.js +101 -0
  131. package/dist/react/internal/openapi/Operation.js.map +1 -0
  132. package/dist/react/internal/openapi/Playground.client.d.ts +33 -0
  133. package/dist/react/internal/openapi/Playground.client.d.ts.map +1 -0
  134. package/dist/react/internal/openapi/Playground.client.js +170 -0
  135. package/dist/react/internal/openapi/Playground.client.js.map +1 -0
  136. package/dist/react/internal/openapi/PropertyExample.client.d.ts +17 -0
  137. package/dist/react/internal/openapi/PropertyExample.client.d.ts.map +1 -0
  138. package/dist/react/internal/openapi/PropertyExample.client.js +21 -0
  139. package/dist/react/internal/openapi/PropertyExample.client.js.map +1 -0
  140. package/dist/react/internal/openapi/Reference.d.ts +55 -0
  141. package/dist/react/internal/openapi/Reference.d.ts.map +1 -0
  142. package/dist/react/internal/openapi/Reference.js +42 -0
  143. package/dist/react/internal/openapi/Reference.js.map +1 -0
  144. package/dist/react/internal/openapi/Schema.d.ts +110 -0
  145. package/dist/react/internal/openapi/Schema.d.ts.map +1 -0
  146. package/dist/react/internal/openapi/Schema.js +239 -0
  147. package/dist/react/internal/openapi/Schema.js.map +1 -0
  148. package/dist/react/internal/openapi/SchemaUnion.client.d.ts +25 -0
  149. package/dist/react/internal/openapi/SchemaUnion.client.d.ts.map +1 -0
  150. package/dist/react/internal/openapi/SchemaUnion.client.js +48 -0
  151. package/dist/react/internal/openapi/SchemaUnion.client.js.map +1 -0
  152. package/dist/react/internal/openapi/anchor-navigation.client.d.ts +47 -0
  153. package/dist/react/internal/openapi/anchor-navigation.client.d.ts.map +1 -0
  154. package/dist/react/internal/openapi/anchor-navigation.client.js +120 -0
  155. package/dist/react/internal/openapi/anchor-navigation.client.js.map +1 -0
  156. package/dist/react/internal/openapi/auth.d.ts +28 -0
  157. package/dist/react/internal/openapi/auth.d.ts.map +1 -0
  158. package/dist/react/internal/openapi/auth.js +75 -0
  159. package/dist/react/internal/openapi/auth.js.map +1 -0
  160. package/dist/react/useLayout.d.ts +2 -0
  161. package/dist/react/useLayout.d.ts.map +1 -1
  162. package/dist/react/useLayout.js +2 -0
  163. package/dist/react/useLayout.js.map +1 -1
  164. package/dist/server/handlers.d.ts +1 -1
  165. package/dist/server/handlers.d.ts.map +1 -1
  166. package/dist/server/handlers.js +26 -5
  167. package/dist/server/handlers.js.map +1 -1
  168. package/dist/server/og-assets.d.ts +5 -0
  169. package/dist/server/og-assets.d.ts.map +1 -0
  170. package/dist/server/og-assets.js +11 -0
  171. package/dist/server/og-assets.js.map +1 -0
  172. package/dist/server/openapi/assets.d.ts +33 -0
  173. package/dist/server/openapi/assets.d.ts.map +1 -0
  174. package/dist/server/openapi/assets.generated.d.ts +9 -0
  175. package/dist/server/openapi/assets.generated.d.ts.map +1 -0
  176. package/dist/server/openapi/assets.generated.js +1091 -0
  177. package/dist/server/openapi/assets.generated.js.map +1 -0
  178. package/dist/server/openapi/assets.js +32 -0
  179. package/dist/server/openapi/assets.js.map +1 -0
  180. package/dist/server/openapi/handler.d.ts +103 -0
  181. package/dist/server/openapi/handler.d.ts.map +1 -0
  182. package/dist/server/openapi/handler.js +198 -0
  183. package/dist/server/openapi/handler.js.map +1 -0
  184. package/dist/server/openapi/handler.test.d.ts +2 -0
  185. package/dist/server/openapi/handler.test.d.ts.map +1 -0
  186. package/dist/server/openapi/handler.test.js +203 -0
  187. package/dist/server/openapi/handler.test.js.map +1 -0
  188. package/dist/server/openapi/html.d.ts +16 -0
  189. package/dist/server/openapi/html.d.ts.map +1 -0
  190. package/dist/server/openapi/html.js +75 -0
  191. package/dist/server/openapi/html.js.map +1 -0
  192. package/dist/server/openapi/pages.d.ts +33 -0
  193. package/dist/server/openapi/pages.d.ts.map +1 -0
  194. package/dist/server/openapi/pages.js +130 -0
  195. package/dist/server/openapi/pages.js.map +1 -0
  196. package/dist/server/openapi/pages.test.d.ts +2 -0
  197. package/dist/server/openapi/pages.test.d.ts.map +1 -0
  198. package/dist/server/openapi/pages.test.js +94 -0
  199. package/dist/server/openapi/pages.test.js.map +1 -0
  200. package/dist/server/openapi/state.d.ts +42 -0
  201. package/dist/server/openapi/state.d.ts.map +1 -0
  202. package/dist/server/openapi/state.js +101 -0
  203. package/dist/server/openapi/state.js.map +1 -0
  204. package/dist/styles/index.css +16 -0
  205. package/dist/styles/markdown.css +9 -7
  206. package/dist/styles/openapi-playground.css +80 -0
  207. package/dist/styles/openapi.css +660 -0
  208. package/dist/vite.d.ts.map +1 -1
  209. package/dist/vite.js +1 -0
  210. package/dist/vite.js.map +1 -1
  211. package/dist/waku/internal/middleware/md-router.d.ts +0 -4
  212. package/dist/waku/internal/middleware/md-router.d.ts.map +1 -1
  213. package/dist/waku/internal/middleware/md-router.js +3 -48
  214. package/dist/waku/internal/middleware/md-router.js.map +1 -1
  215. package/dist/waku/internal/patches/adapters/vercel-build-enhancer.js +1 -1
  216. package/dist/waku/internal/patches/adapters/vercel-build-enhancer.js.map +1 -1
  217. package/dist/waku/internal/patches/router.d.ts.map +1 -1
  218. package/dist/waku/internal/patches/router.js +114 -1
  219. package/dist/waku/internal/patches/router.js.map +1 -1
  220. package/package.json +5 -1
  221. package/src/config.ts +1 -0
  222. package/src/globals.d.ts +16 -0
  223. package/src/index.ts +1 -0
  224. package/src/internal/config.ts +40 -1
  225. package/src/internal/llms.ts +51 -1
  226. package/src/internal/markdown-negotiation.test.ts +42 -0
  227. package/src/internal/markdown-negotiation.ts +95 -0
  228. package/src/internal/markdown.ts +5 -0
  229. package/src/internal/openapi/anchors.ts +44 -0
  230. package/src/internal/openapi/app.ts +127 -0
  231. package/src/internal/openapi/index.ts +24 -0
  232. package/src/internal/openapi/markdown.test.ts +115 -0
  233. package/src/internal/openapi/markdown.ts +275 -0
  234. package/src/internal/openapi/openapi.ts +212 -0
  235. package/src/internal/openapi/openrpc.test.ts +239 -0
  236. package/src/internal/openapi/openrpc.ts +295 -0
  237. package/src/internal/openapi/parser.test.ts +203 -0
  238. package/src/internal/openapi/parser.ts +613 -0
  239. package/src/internal/openapi/registry.test.ts +89 -0
  240. package/src/internal/openapi/registry.ts +89 -0
  241. package/src/internal/openapi/sample.test.ts +283 -0
  242. package/src/internal/openapi/sample.ts +562 -0
  243. package/src/internal/openapi/search.test.ts +62 -0
  244. package/src/internal/openapi/search.ts +108 -0
  245. package/src/internal/openapi/sidebar.test.ts +131 -0
  246. package/src/internal/openapi/sidebar.ts +94 -0
  247. package/src/internal/openapi/union.test.ts +51 -0
  248. package/src/internal/openapi/union.ts +74 -0
  249. package/src/internal/search.ts +20 -0
  250. package/src/internal/test/virtual-config.stub.ts +14 -0
  251. package/src/internal/vite-plugins.ts +106 -11
  252. package/src/openapi-app/App.tsx +64 -0
  253. package/src/openapi-app/blocks.tsx +33 -0
  254. package/src/openapi-app/client.tsx +25 -0
  255. package/src/openapi-app/links.test.ts +84 -0
  256. package/src/openapi-app/links.ts +66 -0
  257. package/src/openapi-app/payload.ts +20 -0
  258. package/src/openapi-app/virtual/config.ts +7 -0
  259. package/src/openapi-app/virtual/group-icons.ts +2 -0
  260. package/src/openapi-app/virtual/langs.ts +6 -0
  261. package/src/openapi-app/virtual/openapi.ts +10 -0
  262. package/src/openapi-app/virtual/search-index.ts +21 -0
  263. package/src/openapi-app/virtual/slots.ts +4 -0
  264. package/src/openapi-app/virtual/user-styles.ts +2 -0
  265. package/src/openapi-app/waku.tsx +154 -0
  266. package/src/react/Badge.tsx +2 -3
  267. package/src/react/Layout.client.tsx +17 -4
  268. package/src/react/OpenApi.tsx +5 -0
  269. package/src/react/internal/CodeToHtml.client.tsx +283 -22
  270. package/src/react/internal/Sidebar.tsx +126 -22
  271. package/src/react/internal/openapi/CodeSample.client.tsx +294 -0
  272. package/src/react/internal/openapi/CollapsibleChildren.client.tsx +41 -0
  273. package/src/react/internal/openapi/Disclosure.client.tsx +67 -0
  274. package/src/react/internal/openapi/Endpoints.tsx +58 -0
  275. package/src/react/internal/openapi/EndpointsView.tsx +76 -0
  276. package/src/react/internal/openapi/EnumValues.client.tsx +49 -0
  277. package/src/react/internal/openapi/HeadingAnchor.tsx +28 -0
  278. package/src/react/internal/openapi/OpenApiPage.tsx +173 -0
  279. package/src/react/internal/openapi/Operation.test.tsx +101 -0
  280. package/src/react/internal/openapi/Operation.tsx +335 -0
  281. package/src/react/internal/openapi/Playground.client.tsx +234 -0
  282. package/src/react/internal/openapi/PropertyExample.client.tsx +55 -0
  283. package/src/react/internal/openapi/Reference.tsx +120 -0
  284. package/src/react/internal/openapi/Schema.tsx +467 -0
  285. package/src/react/internal/openapi/SchemaUnion.client.tsx +123 -0
  286. package/src/react/internal/openapi/anchor-navigation.client.ts +154 -0
  287. package/src/react/internal/openapi/auth.ts +69 -0
  288. package/src/react/useLayout.ts +4 -0
  289. package/src/server/handlers.ts +31 -6
  290. package/src/server/og-assets.ts +14 -0
  291. package/src/server/openapi/assets.generated.ts +1093 -0
  292. package/src/server/openapi/assets.ts +57 -0
  293. package/src/server/openapi/handler.test.ts +244 -0
  294. package/src/server/openapi/handler.ts +277 -0
  295. package/src/server/openapi/html.ts +84 -0
  296. package/src/server/openapi/pages.test.ts +111 -0
  297. package/src/server/openapi/pages.ts +153 -0
  298. package/src/server/openapi/state.ts +136 -0
  299. package/src/styles/index.css +16 -0
  300. package/src/styles/markdown.css +9 -7
  301. package/src/styles/openapi-playground.css +80 -0
  302. package/src/styles/openapi.css +660 -0
  303. package/src/vite.ts +1 -0
  304. package/src/waku/internal/middleware/md-router.ts +8 -52
  305. package/src/waku/internal/patches/adapters/vercel-build-enhancer.ts +1 -1
  306. package/src/waku/internal/patches/router.ts +131 -1
@@ -0,0 +1,187 @@
1
+ /**
2
+ * OpenAPI integration config.
3
+ *
4
+ * Mounts an isolated, auto-generated API reference section in the docs from an
5
+ * OpenAPI spec. Use {@link from} to define an entry in `vocs.config.ts`.
6
+ */
7
+ import type * as VocsConfig from '../config.js';
8
+ import type { SidebarItem } from '../sidebar.js';
9
+ /**
10
+ * Spec source.
11
+ *
12
+ * - A file path relative to the project root (e.g. `./openapi.yaml`).
13
+ * - A URL (e.g. `https://example.com/openapi.json`).
14
+ * - Raw JSON/YAML content.
15
+ * - An inline OpenAPI document object.
16
+ */
17
+ export type Spec = string | Record<string, unknown>;
18
+ /**
19
+ * A spec source, an already-started promise resolving to one, or a (lazy)
20
+ * provider that returns one. Promises/providers are awaited once when the
21
+ * reference is first rendered (and the result reused), so specs generated at
22
+ * runtime — e.g. from a server framework like `hono-openapi` — can be passed
23
+ * without resolving them up front. This lets `Handler.openApi` be constructed
24
+ * synchronously (and mounted via `app.route(...)`) even when the spec is
25
+ * produced asynchronously: build it eagerly and pass the promise directly.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const spec = generateSpecs(app) // Promise<Spec>, started eagerly
30
+ * app.route('/', Handler.openApi({ spec }, { fallback: 'next' }))
31
+ * ```
32
+ */
33
+ export type SpecInput = Spec | Promise<Spec> | (() => Spec | Promise<Spec>);
34
+ /**
35
+ * Extra sidebar items to add around the auto-generated section.
36
+ *
37
+ * These are typically links to consumer-authored override/guide pages mounted
38
+ * under the same `path` (e.g. `pages/api/auth.mdx`).
39
+ */
40
+ export type SidebarExtras = {
41
+ /** Items prepended above the generated `Introduction`/categories. */
42
+ top?: SidebarItem[] | undefined;
43
+ /** Items appended below the generated categories. */
44
+ bottom?: SidebarItem[] | undefined;
45
+ /**
46
+ * Items nested under the generated `Introduction` entry. When provided, the
47
+ * `Introduction` leaf becomes a collapsible group whose first child is an
48
+ * `Overview` link to the landing page, followed by these items (typically
49
+ * links to guide `pages` mounted under the section, e.g. authentication or
50
+ * versioning).
51
+ */
52
+ intro?: SidebarItem[] | undefined;
53
+ /**
54
+ * Collapse the generated category groups by default. The group matching the
55
+ * active page still auto-expands, so deep links stay navigable. The generated
56
+ * `Introduction` entry is unaffected.
57
+ *
58
+ * @default false
59
+ */
60
+ collapsed?: boolean | undefined;
61
+ };
62
+ /**
63
+ * A consumer-authored `.md`/`.mdx` page mounted into an OpenAPI section.
64
+ *
65
+ * In the Vite/site integration these are discovered automatically by the file
66
+ * router (e.g. `pages/api/auth.mdx`). In the standalone server handler
67
+ * ({@link file://./../../server/handlers.ts `Handler.openApi`}) — which has no
68
+ * filesystem router — they are supplied explicitly so override/guide content can
69
+ * still be rendered.
70
+ *
71
+ * - `path` is the route relative to the section mount (e.g. `/` overrides the
72
+ * landing intro, `/auth` is a guide page, `/<group>` overrides a category
73
+ * header).
74
+ * - `file` is the path to the `.md`/`.mdx` source, resolved against the handler
75
+ * `rootDir` (default `process.cwd()`). Reading a file requires `node:fs`, so
76
+ * on filesystem-less runtimes (e.g. Cloudflare Workers) supply `content`
77
+ * instead.
78
+ * - `content` is the `.md`/`.mdx` source inline, an alternative to `file` that
79
+ * needs no filesystem access. Exactly one of `file`/`content` is required.
80
+ * - `title` overrides the document title otherwise taken from frontmatter or the
81
+ * first `# heading`, and renders as the page's heading on standalone guide
82
+ * pages.
83
+ * - `description` renders as a subtitle below the title on standalone guide
84
+ * pages (Markdown). Also taken from frontmatter `description` when omitted.
85
+ */
86
+ export type Page = {
87
+ path: string;
88
+ file?: string | undefined;
89
+ content?: string | undefined;
90
+ title?: string | undefined;
91
+ description?: string | undefined;
92
+ };
93
+ export type Config = {
94
+ /**
95
+ * OpenAPI spec source: file path, URL, raw content, inline object, or a (lazy)
96
+ * provider function returning any of those.
97
+ */
98
+ spec: SpecInput;
99
+ /**
100
+ * Mount path for the generated API reference section.
101
+ *
102
+ * The section gets its own isolated sidebar scoped to this path.
103
+ *
104
+ * Required for the Vite/site integration. Optional for the standalone
105
+ * {@link file://./../../server/handlers.ts `Handler.openApi`} handler (the
106
+ * Hono mount provides the location; `path` only seeds generated link bases and
107
+ * defaults to `/`).
108
+ *
109
+ * @example "/api"
110
+ */
111
+ path?: string | undefined;
112
+ /**
113
+ * Extra sidebar items to add around the auto-generated section (e.g. links to
114
+ * consumer-authored guide pages mounted under `path`).
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * sidebar: {
119
+ * top: [{ text: 'Authentication', link: '/api/auth' }],
120
+ * bottom: [{ text: 'Errors', link: '/api/errors' }],
121
+ * }
122
+ * ```
123
+ */
124
+ sidebar?: SidebarExtras | undefined;
125
+ /**
126
+ * Consumer-authored `.md`/`.mdx` override/guide pages.
127
+ *
128
+ * Only used by the standalone {@link file://./../../server/handlers.ts
129
+ * `Handler.openApi`} handler — the Vite/site integration discovers these via
130
+ * the file router instead.
131
+ */
132
+ pages?: Page[] | undefined;
133
+ /**
134
+ * Vocs config passthrough for the standalone {@link
135
+ * file://./../../server/handlers.ts `Handler.openApi`} handler.
136
+ *
137
+ * The handler renders the real Vocs layout, so these options customize the
138
+ * chrome (theme, top navigation, logo, socials, …) exactly like a
139
+ * `vocs.config.ts`.
140
+ *
141
+ * `title` and `description` default to the spec's `info.title`/`info.description`
142
+ * but can be overridden here. `sidebar` is derived from the generated section
143
+ * (plus the `sidebar` config above) and cannot be set here.
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * vocs: {
148
+ * title: 'Acme Docs',
149
+ * logoUrl: '/logo.svg',
150
+ * theme: { accentColor: '#7c3aed' },
151
+ * topNav: [{ text: 'Home', link: 'https://acme.com' }],
152
+ * }
153
+ * ```
154
+ */
155
+ vocs?: Omit<VocsConfig.define.Options, 'sidebar' | 'openapi'> | undefined;
156
+ };
157
+ /**
158
+ * Config for the Vite/site integration, where `path` is required (it scopes the
159
+ * generated sidebar and routes).
160
+ */
161
+ export type SiteConfig = Config & {
162
+ path: string;
163
+ };
164
+ /**
165
+ * Defines an OpenAPI integration entry.
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * import { OpenApi } from 'vocs/config'
170
+ *
171
+ * export default defineConfig({
172
+ * openapi: [
173
+ * OpenApi.from({ spec: './openapi.yaml', path: '/api' }),
174
+ * ],
175
+ * })
176
+ * ```
177
+ */
178
+ export declare function from(config: from.Options): SiteConfig;
179
+ export declare namespace from {
180
+ type Options = SiteConfig;
181
+ }
182
+ /**
183
+ * Normalizes a mount path: ensures a leading slash and strips any trailing
184
+ * slash (except for the root `/`).
185
+ */
186
+ export declare function normalizePath(path: string): string;
187
+ //# sourceMappingURL=openapi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../../src/internal/openapi/openapi.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,KAAK,UAAU,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD;;;;;;;GAOG;AACH,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEnD;;;;;;;;;;;;;;GAc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G;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IAChC,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,GAAG,UAAU,CAYrD;AAED,MAAM,CAAC,OAAO,WAAW,IAAI,CAAC;IAC5B,KAAK,OAAO,GAAG,UAAU,CAAA;CAC1B;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIlD"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * OpenAPI integration config.
3
+ *
4
+ * Mounts an isolated, auto-generated API reference section in the docs from an
5
+ * OpenAPI spec. Use {@link from} to define an entry in `vocs.config.ts`.
6
+ */
7
+ /**
8
+ * Defines an OpenAPI integration entry.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { OpenApi } from 'vocs/config'
13
+ *
14
+ * export default defineConfig({
15
+ * openapi: [
16
+ * OpenApi.from({ spec: './openapi.yaml', path: '/api' }),
17
+ * ],
18
+ * })
19
+ * ```
20
+ */
21
+ export function from(config) {
22
+ const { spec, path, sidebar, pages } = config;
23
+ if (!spec)
24
+ throw new Error('[vocs] `openapi` entry is missing a `spec`.');
25
+ if (!path)
26
+ throw new Error('[vocs] `openapi` entry is missing a `path`.');
27
+ return {
28
+ spec,
29
+ path: normalizePath(path),
30
+ ...(sidebar ? { sidebar } : {}),
31
+ ...(pages ? { pages } : {}),
32
+ };
33
+ }
34
+ /**
35
+ * Normalizes a mount path: ensures a leading slash and strips any trailing
36
+ * slash (except for the root `/`).
37
+ */
38
+ export function normalizePath(path) {
39
+ let normalized = path.startsWith('/') ? path : `/${path}`;
40
+ if (normalized.length > 1 && normalized.endsWith('/'))
41
+ normalized = normalized.slice(0, -1);
42
+ return normalized;
43
+ }
44
+ //# sourceMappingURL=openapi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi.js","sourceRoot":"","sources":["../../../src/internal/openapi/openapi.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsKH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,IAAI,CAAC,MAAoB;IACvC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IAE7C,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;IACzE,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;IAEzE,OAAO;QACL,IAAI;QACJ,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC;QACzB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/B,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5B,CAAA;AACH,CAAC;AAMD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,IAAI,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAA;IACzD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAC3F,OAAO,UAAU,CAAA;AACnB,CAAC"}
@@ -0,0 +1,90 @@
1
+ import type { IrOperation } from './parser.js';
2
+ /**
3
+ * Minimal structural typing for the OpenRPC documents we expand. Only the
4
+ * fields consumed during expansion are modeled; everything else is ignored.
5
+ *
6
+ * @see https://spec.open-rpc.org
7
+ */
8
+ export type Document = {
9
+ openrpc?: string;
10
+ info?: {
11
+ title?: string;
12
+ version?: string;
13
+ description?: string;
14
+ };
15
+ methods?: Method[];
16
+ components?: {
17
+ schemas?: Record<string, unknown>;
18
+ };
19
+ };
20
+ export type Method = {
21
+ name: string;
22
+ summary?: string;
23
+ description?: string;
24
+ deprecated?: boolean;
25
+ params?: ContentDescriptor[];
26
+ result?: ContentDescriptor;
27
+ examples?: Example[];
28
+ };
29
+ type ContentDescriptor = {
30
+ name?: string;
31
+ summary?: string;
32
+ description?: string;
33
+ required?: boolean;
34
+ deprecated?: boolean;
35
+ schema?: Record<string, unknown>;
36
+ };
37
+ type Example = {
38
+ name?: string;
39
+ params?: {
40
+ name?: string;
41
+ value?: unknown;
42
+ }[];
43
+ result?: {
44
+ name?: string;
45
+ value?: unknown;
46
+ };
47
+ };
48
+ /**
49
+ * Expands an OpenRPC document into one {@link IrOperation} per JSON-RPC method,
50
+ * modeled after a single host HTTP operation (the JSON-RPC endpoint).
51
+ *
52
+ * JSON-RPC methods all POST the same envelope to one endpoint, which OpenAPI
53
+ * cannot express as distinct path items. Expanding at the IR level instead lets
54
+ * each method become its own sidebar entry and page section while keeping the
55
+ * shared transport: every generated operation reuses the host operation's
56
+ * `method` (POST) and `path`, so request code samples target the real endpoint.
57
+ *
58
+ * Each method maps to:
59
+ * - `summary` → the method name (the sidebar/section title)
60
+ * - `description` → the method summary + description
61
+ * - `parameters` (`in: 'rpc'`) → the JSON-RPC params, rendered like path/query
62
+ * params
63
+ * - `requestBody` → the JSON-RPC request envelope, `hidden` from the body
64
+ * section but used to generate an accurate request code sample
65
+ * - a `200` response → the JSON-RPC response envelope wrapping the method result
66
+ */
67
+ export declare function expand(host: IrOperation, document: Document | string, options?: expand.Options): Promise<expand.Result>;
68
+ export declare namespace expand {
69
+ type Options = {
70
+ /**
71
+ * Base URL relative `x-openrpc` URLs (e.g. `/openrpc.json`) resolve against:
72
+ * the spec URL when the spec was loaded from a URL, or the request origin in
73
+ * the standalone server handler.
74
+ */
75
+ baseUrl?: string | undefined;
76
+ };
77
+ /** A named JSON-RPC request example to inject onto the host operation. */
78
+ type RpcExample = {
79
+ summary?: string | undefined;
80
+ value: unknown;
81
+ };
82
+ type Result = {
83
+ /** One IR operation per JSON-RPC method. */
84
+ operations: IrOperation[];
85
+ /** Request examples keyed by method name, for the host operation. */
86
+ examples: Record<string, RpcExample>;
87
+ };
88
+ }
89
+ export {};
90
+ //# sourceMappingURL=openrpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openrpc.d.ts","sourceRoot":"","sources":["../../../src/internal/openapi/openrpc.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAe,MAAM,aAAa,CAAA;AAE3D;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACjE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,UAAU,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAA;CACnD,CAAA;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,MAAM,CAAC,EAAE,iBAAiB,EAAE,CAAA;IAC5B,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAA;CACrB,CAAA;AAED,KAAK,iBAAiB,GAAG;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC,CAAA;AAED,KAAK,OAAO,GAAG;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAAE,CAAA;IAC7C,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAC5C,CAAA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,MAAM,CAC1B,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,QAAQ,GAAG,MAAM,EAC3B,OAAO,GAAE,MAAM,CAAC,OAAY,GAC3B,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAwFxB;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,KAAK,OAAO,GAAG;QACb;;;;WAIG;QACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAC7B,CAAA;IACD,0EAA0E;IAC1E,KAAK,UAAU,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAA;IAClE,KAAK,MAAM,GAAG;QACZ,4CAA4C;QAC5C,UAAU,EAAE,WAAW,EAAE,CAAA;QACzB,qEAAqE;QACrE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;KACrC,CAAA;CACF"}
@@ -0,0 +1,213 @@
1
+ import { dereference } from '@scalar/openapi-parser';
2
+ import GithubSlugger from 'github-slugger';
3
+ /**
4
+ * Expands an OpenRPC document into one {@link IrOperation} per JSON-RPC method,
5
+ * modeled after a single host HTTP operation (the JSON-RPC endpoint).
6
+ *
7
+ * JSON-RPC methods all POST the same envelope to one endpoint, which OpenAPI
8
+ * cannot express as distinct path items. Expanding at the IR level instead lets
9
+ * each method become its own sidebar entry and page section while keeping the
10
+ * shared transport: every generated operation reuses the host operation's
11
+ * `method` (POST) and `path`, so request code samples target the real endpoint.
12
+ *
13
+ * Each method maps to:
14
+ * - `summary` → the method name (the sidebar/section title)
15
+ * - `description` → the method summary + description
16
+ * - `parameters` (`in: 'rpc'`) → the JSON-RPC params, rendered like path/query
17
+ * params
18
+ * - `requestBody` → the JSON-RPC request envelope, `hidden` from the body
19
+ * section but used to generate an accurate request code sample
20
+ * - a `200` response → the JSON-RPC response envelope wrapping the method result
21
+ */
22
+ export async function expand(host, document, options = {}) {
23
+ const resolved = await resolve(document, options);
24
+ const methods = resolved.methods ?? [];
25
+ const slugger = new GithubSlugger();
26
+ // Named request examples (keyed by method name) injected onto the host
27
+ // operation so the interactive client (Scalar) can prefill the JSON-RPC
28
+ // envelope for each method. JSON-RPC methods all share one path+verb, so the
29
+ // client distinguishes them by selecting the matching named example.
30
+ const examples = {};
31
+ const operations = methods.map((method) => {
32
+ const example = method.examples?.[0];
33
+ const parameters = (method.params ?? []).map((param, index) => ({
34
+ name: param.name ?? `param${index}`,
35
+ in: 'rpc',
36
+ required: param.required,
37
+ deprecated: param.deprecated,
38
+ description: param.description ?? param.summary,
39
+ schema: param.schema,
40
+ example: paramExample(param, index, example),
41
+ }));
42
+ // The wire-format example values (positional `params` array) used for the
43
+ // request code sample and to fill in any params the examples omit.
44
+ const paramValues = parameters.map((parameter) => parameter.example !== undefined ? parameter.example : sampleFromSchema(parameter.schema));
45
+ const requestExample = {
46
+ jsonrpc: '2.0',
47
+ id: 1,
48
+ method: method.name,
49
+ params: paramValues,
50
+ };
51
+ examples[method.name] = { summary: method.summary, value: requestExample };
52
+ const resultSchema = method.result?.schema;
53
+ const resultValue = example?.result?.value !== undefined ? example.result.value : sampleFromSchema(resultSchema);
54
+ const responseExample = { jsonrpc: '2.0', id: 1, result: resultValue };
55
+ const description = [method.summary, method.description].filter(Boolean).join('\n\n');
56
+ return {
57
+ id: slugger.slug(method.name),
58
+ method: host.method,
59
+ path: host.path,
60
+ // Name of the host operation's request example to select in the
61
+ // interactive client (matches the key added to `examples` above).
62
+ rpcExample: method.name,
63
+ summary: method.name,
64
+ description: description || undefined,
65
+ deprecated: method.deprecated,
66
+ parameters,
67
+ requestBody: {
68
+ required: true,
69
+ // Hidden from the rendered "Request Body" section: the params already
70
+ // appear in the "Parameters" section and the literal envelope shows in
71
+ // the request code sample. The body is still used to build that sample.
72
+ hidden: true,
73
+ content: [
74
+ {
75
+ mediaType: 'application/json',
76
+ schema: requestEnvelopeSchema(method),
77
+ example: requestExample,
78
+ },
79
+ ],
80
+ },
81
+ responses: [
82
+ {
83
+ status: '200',
84
+ description: method.result?.description ?? 'JSON-RPC response.',
85
+ content: [
86
+ {
87
+ mediaType: 'application/json',
88
+ schema: responseEnvelopeSchema(resultSchema),
89
+ example: responseExample,
90
+ },
91
+ ],
92
+ headers: [],
93
+ },
94
+ ],
95
+ };
96
+ });
97
+ return { operations, examples };
98
+ }
99
+ /**
100
+ * Resolves an OpenRPC source (URL, raw JSON, or object) to a dereferenced doc.
101
+ *
102
+ * A string is treated as raw JSON when it begins with `{`; otherwise it's a
103
+ * URL. Absolute (`http(s)://`) URLs are fetched directly. Relative URLs (e.g.
104
+ * `/openrpc.json`, the host-relative link an OpenAPI document commonly uses) are
105
+ * resolved against `baseUrl` — the spec URL when the spec was loaded from a URL,
106
+ * or the request origin in the standalone server handler — then fetched.
107
+ */
108
+ async function resolve(document, options = {}) {
109
+ let raw = document;
110
+ if (typeof document === 'string') {
111
+ const trimmed = document.trimStart();
112
+ if (trimmed.startsWith('{')) {
113
+ raw = JSON.parse(trimmed);
114
+ }
115
+ else {
116
+ const url = trimmed.startsWith('http://') || trimmed.startsWith('https://')
117
+ ? trimmed
118
+ : options.baseUrl
119
+ ? new URL(trimmed, options.baseUrl).toString()
120
+ : undefined;
121
+ if (!url)
122
+ throw new Error(`Cannot resolve relative OpenRPC document "${trimmed}" without a base URL.`);
123
+ const response = await fetch(url);
124
+ if (!response.ok)
125
+ throw new Error(`Failed to fetch OpenRPC document from ${url}: ${response.statusText}`);
126
+ raw = await response.json();
127
+ }
128
+ }
129
+ // Dereference internal `$ref`s (`#/components/schemas/...`) so the renderer
130
+ // sees concrete schemas, matching how the OpenAPI parser dereferences specs.
131
+ const { schema } = await dereference(raw);
132
+ return (schema ?? raw);
133
+ }
134
+ /** JSON-RPC request envelope schema for a method (used only for code samples). */
135
+ function requestEnvelopeSchema(method) {
136
+ return {
137
+ type: 'object',
138
+ properties: {
139
+ jsonrpc: { type: 'string', const: '2.0' },
140
+ id: { type: 'integer' },
141
+ method: { type: 'string', const: method.name },
142
+ params: {
143
+ type: 'array',
144
+ prefixItems: (method.params ?? []).map((param) => param.schema ?? {}),
145
+ },
146
+ },
147
+ required: ['jsonrpc', 'method'],
148
+ };
149
+ }
150
+ /** JSON-RPC response envelope schema wrapping a method's result schema. */
151
+ function responseEnvelopeSchema(resultSchema) {
152
+ return {
153
+ type: 'object',
154
+ properties: {
155
+ jsonrpc: { type: 'string', const: '2.0' },
156
+ id: { type: 'integer' },
157
+ ...(resultSchema ? { result: resultSchema } : {}),
158
+ },
159
+ };
160
+ }
161
+ /** Looks up the example value for a param, by name then position. */
162
+ function paramExample(param, index, example) {
163
+ const entries = example?.params ?? [];
164
+ const byName = param.name ? entries.find((entry) => entry.name === param.name) : undefined;
165
+ const entry = byName ?? entries[index];
166
+ return entry?.value;
167
+ }
168
+ /**
169
+ * Derives a representative value from a JSON Schema for methods/params that lack
170
+ * authored examples. Intentionally small — prefers authored `example`/`default`/
171
+ * `enum` values and otherwise falls back to a type-based placeholder.
172
+ */
173
+ function sampleFromSchema(schema) {
174
+ if (!schema || typeof schema !== 'object')
175
+ return undefined;
176
+ if ('example' in schema)
177
+ return schema['example'];
178
+ if (Array.isArray(schema['examples']) && schema['examples'].length > 0)
179
+ return schema['examples'][0];
180
+ if ('default' in schema)
181
+ return schema['default'];
182
+ if ('const' in schema)
183
+ return schema['const'];
184
+ if (Array.isArray(schema['enum']) && schema['enum'].length > 0)
185
+ return schema['enum'][0];
186
+ const type = Array.isArray(schema['type']) ? schema['type'][0] : schema['type'];
187
+ switch (type) {
188
+ case 'string':
189
+ return 'string';
190
+ case 'integer':
191
+ case 'number':
192
+ return 0;
193
+ case 'boolean':
194
+ return true;
195
+ case 'array': {
196
+ const items = schema['items'];
197
+ const item = sampleFromSchema(items);
198
+ return item === undefined ? [] : [item];
199
+ }
200
+ case 'object': {
201
+ const properties = schema['properties'];
202
+ if (!properties)
203
+ return {};
204
+ const result = {};
205
+ for (const [key, value] of Object.entries(properties))
206
+ result[key] = sampleFromSchema(value);
207
+ return result;
208
+ }
209
+ default:
210
+ return undefined;
211
+ }
212
+ }
213
+ //# sourceMappingURL=openrpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openrpc.js","sourceRoot":"","sources":["../../../src/internal/openapi/openrpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,aAAa,MAAM,gBAAgB,CAAA;AAyC1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,IAAiB,EACjB,QAA2B,EAC3B,UAA0B,EAAE;IAE5B,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACjD,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAA;IACtC,MAAM,OAAO,GAAG,IAAI,aAAa,EAAE,CAAA;IAEnC,uEAAuE;IACvE,wEAAwE;IACxE,6EAA6E;IAC7E,qEAAqE;IACrE,MAAM,QAAQ,GAAsC,EAAE,CAAA;IAEtD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CA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