vitepress-openapi 0.2.6 → 0.2.8

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 (180) hide show
  1. package/dist/{angular-html-CGsuZc6a.cjs → angular-html-IrYiNUL5.cjs} +1 -1
  2. package/dist/{angular-html-DARb335O.js → angular-html-uv0a0QNn.js} +2 -2
  3. package/dist/{angular-ts-CrrEVOLQ.js → angular-ts-CVTzQ4yM.js} +2 -2
  4. package/dist/{angular-ts-Bg4b1K8o.cjs → angular-ts-CmalYPic.cjs} +1 -1
  5. package/dist/{apl-D9ujzlDe.cjs → apl-Cp2eHb5H.cjs} +1 -1
  6. package/dist/{apl-BUNzB7iS.js → apl-G7yswX6Q.js} +5 -5
  7. package/dist/{astro-DuWrFiiv.cjs → astro-CRpTyG5K.cjs} +1 -1
  8. package/dist/{astro-CT6LVfZb.js → astro-DUi5zMa4.js} +5 -5
  9. package/dist/{blade-DEZwhTmz.cjs → blade-DMsLIvGX.cjs} +1 -1
  10. package/dist/{blade-CT3BYEkw.js → blade-uJ4Xa5wc.js} +7 -7
  11. package/dist/{c-Df26Rt3n.js → c-CtMd0n5W.js} +1 -1
  12. package/dist/{c-DDdF0YXr.cjs → c-DJDNxT35.cjs} +1 -1
  13. package/dist/{chapel-BGl0pLYE.cjs → chapel-CCgxhb9n.cjs} +1 -1
  14. package/dist/{chapel-7XVmedRB.js → chapel-DGgSBAIm.js} +1 -1
  15. package/dist/{cobol-7e4lFVpj.js → cobol-CDcij9i2.js} +2 -2
  16. package/dist/{cobol-BgGrvcfE.cjs → cobol-DP8yLe0J.cjs} +1 -1
  17. package/dist/{coffee-D2EFnoK3.js → coffee-Bcg2ycks.js} +1 -1
  18. package/dist/{coffee-CnTOT7qi.cjs → coffee-D3hXAm0d.cjs} +1 -1
  19. package/dist/{cpp-BdIhYOqJ.cjs → cpp-CEMyuz0Z.cjs} +1 -1
  20. package/dist/{cpp-BrJ3qayw.js → cpp-CfsSSf1b.js} +3 -3
  21. package/dist/{crystal-CijsJH2S.js → crystal-B76s5RL_.js} +6 -6
  22. package/dist/{crystal-C0oOOTvI.cjs → crystal-BPjfGQfv.cjs} +1 -1
  23. package/dist/{css-BJ4fQgJY.cjs → css-B_5YxPHw.cjs} +1 -1
  24. package/dist/{css-BDLPKt_n.js → css-Dnve9eIF.js} +1 -1
  25. package/dist/{edge-D7t7tSii.cjs → edge-DEHYswlE.cjs} +1 -1
  26. package/dist/{edge-CWCiEXP9.js → edge-Dlu9JAOU.js} +3 -3
  27. package/dist/{elixir-CEVCh53I.cjs → elixir-CKhKSpjp.cjs} +1 -1
  28. package/dist/{elixir-8Qtl7ev_.js → elixir-CSK8G02U.js} +1 -1
  29. package/dist/{elm-CQNq4BKy.js → elm-CsVe-drn.js} +1 -1
  30. package/dist/{elm-BktTaRPW.cjs → elm-oUMNo4dE.cjs} +1 -1
  31. package/dist/{erb-DCFD7vrt.js → erb-3PcpbjWs.js} +2 -2
  32. package/dist/{erb-Bas_b7PL.cjs → erb-B8WJz_Ls.cjs} +1 -1
  33. package/dist/{git-rebase-CSFTH0sQ.js → git-rebase-BFPUa7RP.js} +1 -1
  34. package/dist/{git-rebase-DGo4nA7C.cjs → git-rebase-CBj8NRO-.cjs} +1 -1
  35. package/dist/{glimmer-js-Z7E0DaWX.cjs → glimmer-js-BkM2LzJ_.cjs} +1 -1
  36. package/dist/{glimmer-js-Ce8bwdpO.js → glimmer-js-C06d46qf.js} +4 -4
  37. package/dist/{glimmer-ts-osenBmqR.cjs → glimmer-ts-B9TsQ9YM.cjs} +1 -1
  38. package/dist/{glimmer-ts-CdP0Y2rr.js → glimmer-ts-BfZJAJhH.js} +4 -4
  39. package/dist/{glsl-gQ2PTprT.js → glsl-Bl7M-IPe.js} +2 -2
  40. package/dist/{glsl-DqSyLtjd.cjs → glsl-uL1y-Bk6.cjs} +1 -1
  41. package/dist/{graphql-DTkt67qx.cjs → graphql-UjpB-MIz.cjs} +1 -1
  42. package/dist/{graphql-D9d0A3NW.js → graphql-j5wYAqtD.js} +5 -5
  43. package/dist/{hack-D2t7w518.js → hack-BN-XE31l.js} +2 -2
  44. package/dist/{hack-BsFtI2Eg.cjs → hack-DC3gQB4E.cjs} +1 -1
  45. package/dist/{haml-BBf8fdr9.cjs → haml-Bhy5P-KC.cjs} +1 -1
  46. package/dist/{haml-DtrHnXyI.js → haml-CDfF0h4F.js} +3 -3
  47. package/dist/{handlebars-BFrhjavm.js → handlebars-BRDXZqV4.js} +4 -4
  48. package/dist/{handlebars-DPepJR-F.cjs → handlebars-CNE9oFMe.cjs} +1 -1
  49. package/dist/{html-CZSxUh6E.js → html-CPA7KoKg.js} +3 -3
  50. package/dist/{html-tDTTwBjP.cjs → html-DF6ZRDg_.cjs} +1 -1
  51. package/dist/{html-derivative-1D9rMziY.js → html-derivative-61htNTyH.js} +1 -1
  52. package/dist/{html-derivative-CiU9WY3_.cjs → html-derivative-D7b_E1PX.cjs} +1 -1
  53. package/dist/{http-BEeboTha.cjs → http-BjRzGfMq.cjs} +1 -1
  54. package/dist/{http-_yCM4LFM.js → http-CR6vxe-f.js} +4 -4
  55. package/dist/{hurl-CjTriWW3.js → hurl-DR3Ao4uN.js} +2 -2
  56. package/dist/{hurl-CzW0xtQK.cjs → hurl-Dz53E_EO.cjs} +1 -1
  57. package/dist/{java-BBWcloI5.js → java-BCOO6DGx.js} +1 -1
  58. package/dist/{java-DEV9nIzf.cjs → java-rdA6e0wp.cjs} +1 -1
  59. package/dist/{javascript-COXg7KRK.cjs → javascript-4PA_CVZC.cjs} +1 -1
  60. package/dist/{javascript-BtdwTU5l.js → javascript-B0H0Bm6m.js} +1 -1
  61. package/dist/{jinja-SDapQ1jF.cjs → jinja-BcxYV4gu.cjs} +1 -1
  62. package/dist/{jinja-0Fph51Wu.js → jinja-DdO6Tf4t.js} +1 -1
  63. package/dist/{jison-C6HvDI82.cjs → jison-BJENBrIF.cjs} +1 -1
  64. package/dist/{jison-DKkCHBi3.js → jison-CmQksr2y.js} +1 -1
  65. package/dist/{json-D9-BN10e.cjs → json-BJ_bvg_A.cjs} +1 -1
  66. package/dist/{json-1Shnxn5T.js → json-Dd3OP7m9.js} +1 -1
  67. package/dist/{jsx-DMGrwzK7.js → jsx-BhoiPRal.js} +1 -1
  68. package/dist/{jsx-CJ8AuAld.cjs → jsx-CaK8syd3.cjs} +1 -1
  69. package/dist/{julia-CtGveS0F.js → julia-CDeyMHwa.js} +4 -4
  70. package/dist/{julia-BOWoqzWb.cjs → julia-DdPKjdf7.cjs} +1 -1
  71. package/dist/{just-DJBTWvtH.cjs → just-B3mF2_pd.cjs} +1 -1
  72. package/dist/{just-Ocglo-Ta.js → just-Db1lRieD.js} +5 -5
  73. package/dist/{latex-CwRnFmhO.js → latex-D73GL9tM.js} +1 -1
  74. package/dist/{latex-jmD-x2Sw.cjs → latex-DyUb8gG5.cjs} +1 -1
  75. package/dist/{liquid-B0j0Ojr6.cjs → liquid-CztsYCRo.cjs} +1 -1
  76. package/dist/{liquid-BUvHlsu4.js → liquid-DF-tIke9.js} +4 -4
  77. package/dist/{lua-Cx8wh7Cx.cjs → lua-Cg38zrfV.cjs} +1 -1
  78. package/dist/{lua-CCwV5A-2.js → lua-xXZSPcKB.js} +2 -2
  79. package/dist/{marko-DgvX-ocG.cjs → marko-BuXulXH5.cjs} +1 -1
  80. package/dist/{marko-B7d7a75U.js → marko-D-oNtuqC.js} +3 -3
  81. package/dist/{mdc-T8GMGcnF.cjs → mdc-CXK0bw8f.cjs} +1 -1
  82. package/dist/{mdc-qWBp3e-g.js → mdc-FTCNLElJ.js} +2 -2
  83. package/dist/{nginx-BbITQOFT.js → nginx-C7lNZZWT.js} +1 -1
  84. package/dist/{nginx-CJ6LIx1U.cjs → nginx-Cgnh7QO-.cjs} +1 -1
  85. package/dist/{nim-_u7AMou0.cjs → nim-D3q9r1nf.cjs} +1 -1
  86. package/dist/{nim-jrsjoy8-.js → nim-DIkmkdRK.js} +6 -6
  87. package/dist/{org-BlOpuc2_.cjs → org-Be03OJi3.cjs} +1 -1
  88. package/dist/{org-BvB9eDZB.js → org-CsORUXsX.js} +26 -26
  89. package/dist/{perl-Db3mBsuQ.js → perl-DzKqYwtD.js} +5 -5
  90. package/dist/{perl-D8XroKo0.cjs → perl-jEpH5QnN.cjs} +1 -1
  91. package/dist/{php-C8SG25Wa.cjs → php-Cd0xNNLC.cjs} +1 -1
  92. package/dist/{php-DXAFydNe.js → php-MrcCGNBb.js} +6 -6
  93. package/dist/{pug-DUGE64tE.js → pug-7jPx_35W.js} +3 -3
  94. package/dist/{pug-DGLtElT2.cjs → pug-tintEWep.cjs} +1 -1
  95. package/dist/{qml-BI8Qke4k.js → qml-6QUtoeWA.js} +1 -1
  96. package/dist/{qml-f8YoerFJ.cjs → qml-BYzhsmnS.cjs} +1 -1
  97. package/dist/{r-DTie9Nyk.cjs → r-Bwq_agHo.cjs} +1 -1
  98. package/dist/{r-BqUCIOdg.js → r-DSFCAodN.js} +1 -1
  99. package/dist/{razor-Cznq4CrH.cjs → razor-GHEO8ZrJ.cjs} +1 -1
  100. package/dist/{razor-DzYuKCwQ.js → razor-kZ9VMhh7.js} +1 -1
  101. package/dist/{regexp-W6uDzT_l.cjs → regexp-BTPSBkuS.cjs} +1 -1
  102. package/dist/{regexp-CCkYPv1N.js → regexp-C4cLyNsj.js} +1 -1
  103. package/dist/{rst-DkdHGABB.js → rst-Celv7pzQ.js} +6 -6
  104. package/dist/{rst-CjRZqYHL.cjs → rst-DC596VAb.cjs} +1 -1
  105. package/dist/{ruby-SrIlbOFE.js → ruby-CMUkZc4V.js} +12 -12
  106. package/dist/{ruby-DYZIHus3.cjs → ruby-CkA4Oavu.cjs} +1 -1
  107. package/dist/{sas-D4DC5Y7L.cjs → sas-CWtZaM4y.cjs} +1 -1
  108. package/dist/{sas-BgMaDA2M.js → sas-DM3UyDFg.js} +1 -1
  109. package/dist/{scss-Cy7mHhKR.js → scss-Ce0za1qK.js} +2 -2
  110. package/dist/{scss-D2afYGNC.cjs → scss-LkHhJo18.cjs} +1 -1
  111. package/dist/{shellscript-DL7dA6YH.cjs → shellscript-CiDBNSSV.cjs} +1 -1
  112. package/dist/{shellscript-Dc7jtvdg.js → shellscript-DfQbZbZv.js} +1 -1
  113. package/dist/{shellsession-BZTJuggn.js → shellsession-B-u2-M3U.js} +1 -1
  114. package/dist/{shellsession-CGkCOuFx.cjs → shellsession-VJTxH3Qp.cjs} +1 -1
  115. package/dist/{soy-B2OqotLG.cjs → soy-CFhgAJvR.cjs} +1 -1
  116. package/dist/{soy-X1cLpGrT.js → soy-K4I5GWmG.js} +1 -1
  117. package/dist/{sql-BLxweCea.cjs → sql-CySKVD8Q.cjs} +1 -1
  118. package/dist/{sql-DRYM5A-g.js → sql-jusQgRuy.js} +1 -1
  119. package/dist/{stata-DUfnFR7t.cjs → stata-9iclJTGl.cjs} +1 -1
  120. package/dist/{stata-mshAKmrC.js → stata-B0U1mDy6.js} +1 -1
  121. package/dist/{surrealql-DQzrI0uj.js → surrealql-6aGCR7SU.js} +1 -1
  122. package/dist/{surrealql-Zfoia8BY.cjs → surrealql-DysQv_VH.cjs} +1 -1
  123. package/dist/{svelte-D2bLGYCT.js → svelte-B9UOpTL8.js} +3 -3
  124. package/dist/{svelte-aFul1Jy8.cjs → svelte-ZhIemg1n.cjs} +1 -1
  125. package/dist/{templ-Dx8bEvea.cjs → templ-BaKkruXs.cjs} +1 -1
  126. package/dist/{templ-BT5bFFZC.js → templ-CwElXEjo.js} +2 -2
  127. package/dist/{tex-DLVxreb-.cjs → tex-CwQDQCX_.cjs} +1 -1
  128. package/dist/{tex-BGjRDs2m.js → tex-kQHmfFkX.js} +2 -2
  129. package/dist/{ts-tags-Ck5aGNIn.js → ts-tags-BkcgKPdU.js} +7 -7
  130. package/dist/{ts-tags-BIebym7V.cjs → ts-tags-Dqqv0wS7.cjs} +1 -1
  131. package/dist/{tsx-B4QBkk0q.cjs → tsx-TxRbY_MS.cjs} +1 -1
  132. package/dist/{tsx-G3EWmL7D.js → tsx-tC9_eQM0.js} +1 -1
  133. package/dist/{twig-BgwYNE2l.cjs → twig-Dsriugp3.cjs} +1 -1
  134. package/dist/{twig-CHwtVyR-.js → twig-zezbIase.js} +5 -5
  135. package/dist/types/src/components/Common/OAJSONEditor.vue.d.ts +2 -2
  136. package/dist/types/src/composables/useShiki.d.ts +13 -2
  137. package/dist/types/src/composables/useTheme.d.ts +53 -0
  138. package/dist/types/src/lib/parser/generateRequestBodyUi.d.ts +2 -1
  139. package/dist/types/src/lib/parser/generateResponseUi.d.ts +2 -1
  140. package/dist/types/src/lib/parser/getSchemaUi.d.ts +5 -1
  141. package/dist/types/src/lib/parser/mergeAllOf.d.ts +6 -0
  142. package/dist/types/src/lib/parser/resolveCircularRef.d.ts +1 -1
  143. package/dist/types/src/lib/shiki/resolveGrammar.d.ts +11 -0
  144. package/dist/{typescript-DoW3h951.cjs → typescript-BoS6yqrz.cjs} +1 -1
  145. package/dist/{typescript-DAazdaCE.js → typescript-KKVXItRs.js} +1 -1
  146. package/dist/{typst-9vf_wdP8.cjs → typst-B_783qIn.cjs} +1 -1
  147. package/dist/{typst-BLT0Jxqy.js → typst-DsM2L8MG.js} +29 -29
  148. package/dist/{useOpenapi-zUwxozsv.cjs → useOpenapi-DOw8b0Cm.cjs} +83 -83
  149. package/dist/{useOpenapi-DyGwf6EG.js → useOpenapi-tKaw3COz.js} +1526 -1467
  150. package/dist/vitepress-openapi.client.cjs.js +126 -126
  151. package/dist/vitepress-openapi.client.es.js +12914 -12832
  152. package/dist/vitepress-openapi.node.cjs.js +1 -1
  153. package/dist/vitepress-openapi.node.es.js +1 -1
  154. package/dist/{vue-CpqLnHVY.js → vue-B58kMEAQ.js} +6 -6
  155. package/dist/{vue-BRjGF9q6.cjs → vue-C-ymR46K.cjs} +1 -1
  156. package/dist/{vue-html-Zve9lhNA.js → vue-html-B8vwCoQU.js} +1 -1
  157. package/dist/{vue-html-5pJeWJlE.cjs → vue-html-qs-Ree4R.cjs} +1 -1
  158. package/dist/{vue-vine-BIyjr9Yw.js → vue-vine-B95XCKNF.js} +3 -3
  159. package/dist/{vue-vine-D8sXouna.cjs → vue-vine-Nsb-fhNk.cjs} +1 -1
  160. package/dist/{xml-B4yjP0re.js → xml-B119d3-g.js} +2 -2
  161. package/dist/{xml-DfteIxKp.cjs → xml-DzTGxXsy.cjs} +1 -1
  162. package/dist/{xsl-BfNOhnnx.js → xsl-CEz1476V.js} +1 -1
  163. package/dist/{xsl-BaF5pye5.cjs → xsl-xWljPYeJ.cjs} +1 -1
  164. package/dist/{yaml-BMWpYE45.js → yaml-B9YlAzUe.js} +1 -1
  165. package/dist/{yaml-BWP6Z5iN.cjs → yaml-Cd_AUGXn.cjs} +1 -1
  166. package/package.json +1 -1
  167. package/src/components/Common/OAJSONEditor.vue +2 -1
  168. package/src/composables/useOpenapi.ts +2 -2
  169. package/src/composables/usePlayground.ts +4 -2
  170. package/src/composables/useShiki.ts +226 -105
  171. package/src/composables/useTheme.ts +57 -0
  172. package/src/lib/parser/dereferenceWithAnnotations.ts +22 -5
  173. package/src/lib/parser/generateRequestBodyUi.ts +3 -3
  174. package/src/lib/parser/generateResponseUi.ts +3 -3
  175. package/src/lib/parser/getSchemaUi.ts +50 -22
  176. package/src/lib/parser/mergeAllOf.ts +45 -0
  177. package/src/lib/parser/parseOpenapi.ts +12 -7
  178. package/src/lib/parser/resolveCircularRef.ts +25 -45
  179. package/src/lib/shiki/resolveGrammar.ts +42 -0
  180. package/src/lib/spec/createOpenApiSpec.ts +27 -51
@@ -44,7 +44,17 @@ export interface OAProperty {
44
44
  meta?: Metadata
45
45
  }
46
46
 
47
+ // Shared schemas are walked and converted once and reused, so the output is a DAG
48
+ // instead of an exponentially large tree. Keyed by object identity, so a cache is
49
+ // only valid while its schemas aren't mutated: share one within a single parse.
50
+ export class SchemaUiCache {
51
+ walked = new WeakSet<object>()
52
+ ui = new WeakMap<object, OAProperty>()
53
+ }
54
+
47
55
  class UiPropertyFactory {
56
+ constructor(private memo: WeakMap<object, OAProperty>) {}
57
+
48
58
  static createBaseProperty(
49
59
  name: string,
50
60
  property: Partial<OpenAPI.SchemaObject> = {},
@@ -97,7 +107,7 @@ class UiPropertyFactory {
97
107
  }
98
108
  }
99
109
 
100
- static createUnionProperty(
110
+ createUnionProperty(
101
111
  unionProperties: Partial<OpenAPI.SchemaObject>[],
102
112
  unionType: 'oneOf' | 'anyOf',
103
113
  name: string = '',
@@ -125,7 +135,7 @@ class UiPropertyFactory {
125
135
  const metaKey = isOneOf ? 'isOneOf' : 'isAnyOf'
126
136
 
127
137
  baseProperty.properties = unionProperties.map((prop) => {
128
- const property = UiPropertyFactory.schemaToUiProperty('', prop)
138
+ const property = this.schemaToUiProperty('', prop)
129
139
  property.meta = { ...(property.meta || {}), [metaItemKey]: true }
130
140
  return property
131
141
  })
@@ -135,25 +145,25 @@ class UiPropertyFactory {
135
145
  return baseProperty
136
146
  }
137
147
 
138
- static createOneOfProperty(
148
+ createOneOfProperty(
139
149
  oneOfProperties: Partial<OpenAPI.SchemaObject>[],
140
150
  name: string = '',
141
151
  baseSchema: Partial<OpenAPI.SchemaObject> = {},
142
152
  required = false,
143
153
  ): OAProperty {
144
- return UiPropertyFactory.createUnionProperty(oneOfProperties, 'oneOf', name, baseSchema, required)
154
+ return this.createUnionProperty(oneOfProperties, 'oneOf', name, baseSchema, required)
145
155
  }
146
156
 
147
- static createAnyOfProperty(
157
+ createAnyOfProperty(
148
158
  anyOfProperties: Partial<OpenAPI.SchemaObject>[],
149
159
  name: string = '',
150
160
  baseSchema: Partial<OpenAPI.SchemaObject> = {},
151
161
  required = false,
152
162
  ): OAProperty {
153
- return UiPropertyFactory.createUnionProperty(anyOfProperties, 'anyOf', name, baseSchema, required)
163
+ return this.createUnionProperty(anyOfProperties, 'anyOf', name, baseSchema, required)
154
164
  }
155
165
 
156
- static schemaToUiProperty(
166
+ schemaToUiProperty(
157
167
  name: string,
158
168
  schema: Partial<OpenAPI.SchemaObject>,
159
169
  required = false,
@@ -170,12 +180,27 @@ class UiPropertyFactory {
170
180
  return UiPropertyFactory.createCircularReferenceProperty(name, schema.circularReference)
171
181
  }
172
182
 
183
+ let property = this.memo.get(schema)
184
+ if (!property) {
185
+ property = this.buildUiProperty(schema)
186
+ this.memo.set(schema, property)
187
+ }
188
+
189
+ // Shallow copy: callers reassign `meta`/`required` on the returned object.
190
+ return { ...property, name, required }
191
+ }
192
+
193
+ buildUiProperty(
194
+ schema: Partial<OpenAPI.SchemaObject>,
195
+ name = '',
196
+ required = false,
197
+ ): OAProperty {
173
198
  if (schema.oneOf) {
174
- return UiPropertyFactory.createOneOfProperty(schema.oneOf, name, schema, required)
199
+ return this.createOneOfProperty(schema.oneOf, name, schema, required)
175
200
  }
176
201
 
177
202
  if (schema.anyOf) {
178
- return UiPropertyFactory.createAnyOfProperty(schema.anyOf, name, schema, required)
203
+ return this.createAnyOfProperty(schema.anyOf, name, schema, required)
179
204
  }
180
205
 
181
206
  if (schema.const !== undefined) {
@@ -228,7 +253,7 @@ class UiPropertyFactory {
228
253
  const schemaType = determineSchemaType(schema.items)
229
254
 
230
255
  property.properties = schemaType === 'object'
231
- ? UiPropertyFactory.extractProperties(
256
+ ? this.extractProperties(
232
257
  schema.items.properties,
233
258
  schema.items.required || [],
234
259
  schema.items.additionalProperties,
@@ -259,7 +284,7 @@ class UiPropertyFactory {
259
284
  property.properties = unionProperties.map((prop: any) => {
260
285
  const propSchema = { ...prop, type: schema.items.type }
261
286
  return {
262
- ...UiPropertyFactory.schemaToUiProperty('', propSchema),
287
+ ...this.schemaToUiProperty('', propSchema),
263
288
  meta: { ...(prop.meta || {}), [metaItemKey]: true },
264
289
  }
265
290
  })
@@ -272,7 +297,7 @@ class UiPropertyFactory {
272
297
  && !schema.items.oneOf
273
298
  && !schema.items.anyOf
274
299
  ) {
275
- const itemProperty = UiPropertyFactory.schemaToUiProperty('[item]', schema.items)
300
+ const itemProperty = this.schemaToUiProperty('[item]', schema.items)
276
301
  if (
277
302
  itemProperty.description
278
303
  || itemProperty.enum
@@ -286,7 +311,7 @@ class UiPropertyFactory {
286
311
 
287
312
  if (schema.prefixItems && Array.isArray(schema.prefixItems)) {
288
313
  property.properties = schema.prefixItems.map((prefixItem, index) => {
289
- const prefixItemProperty = UiPropertyFactory.schemaToUiProperty(
314
+ const prefixItemProperty = this.schemaToUiProperty(
290
315
  `[${index}]`,
291
316
  prefixItem,
292
317
  false,
@@ -309,7 +334,7 @@ class UiPropertyFactory {
309
334
 
310
335
  // Handle case when both prefixItems and items are present.
311
336
  if (schema.prefixItems && Array.isArray(schema.prefixItems) && schema.items) {
312
- const additionalItemsProperty = UiPropertyFactory.schemaToUiProperty(
337
+ const additionalItemsProperty = this.schemaToUiProperty(
313
338
  '[n+]', // Name indicating "additional items".
314
339
  schema.items,
315
340
  false,
@@ -329,7 +354,7 @@ class UiPropertyFactory {
329
354
  property.subtype = undefined
330
355
  }
331
356
  } else if (Array.isArray(schema.type) ? schema.type.includes('object') : schema.type === 'object') {
332
- property.properties = UiPropertyFactory.extractProperties(
357
+ property.properties = this.extractProperties(
333
358
  schema.properties,
334
359
  schema.required || [],
335
360
  schema.additionalProperties,
@@ -338,7 +363,7 @@ class UiPropertyFactory {
338
363
  } else if (schema.type === undefined) {
339
364
  if (schema.properties || schema.additionalProperties) {
340
365
  property.types = ['object']
341
- property.properties = UiPropertyFactory.extractProperties(
366
+ property.properties = this.extractProperties(
342
367
  schema.properties,
343
368
  schema.required || [],
344
369
  schema.additionalProperties,
@@ -350,7 +375,7 @@ class UiPropertyFactory {
350
375
  return property
351
376
  }
352
377
 
353
- static extractProperties(
378
+ extractProperties(
354
379
  propertiesNode?: Record<string, OpenAPI.SchemaObject>,
355
380
  requiredProperties: string[] = [],
356
381
  additionalPropertiesNode?: OpenAPI.SchemaObject | boolean,
@@ -361,7 +386,7 @@ class UiPropertyFactory {
361
386
  if (propertiesNode) {
362
387
  Object.entries(propertiesNode).forEach(([key, value]) => {
363
388
  const isRequired = requiredProperties.includes(key)
364
- properties.push(UiPropertyFactory.schemaToUiProperty(key, value, isRequired))
389
+ properties.push(this.schemaToUiProperty(key, value, isRequired))
365
390
  })
366
391
  }
367
392
 
@@ -371,7 +396,7 @@ class UiPropertyFactory {
371
396
  : { type: 'string' }
372
397
 
373
398
  const name = additionalPropertiesName || 'additionalProperties'
374
- const property = UiPropertyFactory.schemaToUiProperty(name, additionalProps)
399
+ const property = this.schemaToUiProperty(name, additionalProps)
375
400
  property.required = false
376
401
  property.meta = { ...(property.meta || {}), isAdditionalProperties: true }
377
402
  properties.push(property)
@@ -381,14 +406,17 @@ class UiPropertyFactory {
381
406
  }
382
407
  }
383
408
 
384
- export function getSchemaUi(jsonSchema: OpenAPI.SchemaObject): OAProperty | OAProperty[] {
409
+ export function getSchemaUi(
410
+ jsonSchema: OpenAPI.SchemaObject,
411
+ cache = new SchemaUiCache(),
412
+ ): OAProperty | OAProperty[] {
385
413
  if (!jsonSchema || Object.keys(jsonSchema).length === 0) {
386
414
  return []
387
415
  }
388
416
 
389
- const resolvedSchema = resolveCircularRef(jsonSchema)
417
+ const resolvedSchema = resolveCircularRef(jsonSchema, cache.walked)
390
418
 
391
- return UiPropertyFactory.schemaToUiProperty('', resolvedSchema)
419
+ return new UiPropertyFactory(cache.ui).schemaToUiProperty('', resolvedSchema)
392
420
  }
393
421
 
394
422
  function inferTypesFromEnum(values: unknown[]): JSONSchemaType[] {
@@ -0,0 +1,45 @@
1
+ import { merge } from 'allof-merge'
2
+
3
+ /**
4
+ * Merges `allOf` entries under `paths` and `components` without crawling the whole document.
5
+ * Merge a sparse copy holding just those entries, at their original paths so the cycle
6
+ * $refs allof-merge emits stay valid.
7
+ */
8
+ export function mergeAllOf(spec: any): any {
9
+ const groups = [['paths'], ...Object.keys(spec.components ?? {}).map(section => ['components', section])]
10
+ const entries = groups.flatMap(group => Object.entries(getIn(spec, group) ?? {})
11
+ .filter(([, entry]) => hasAllOf(entry))
12
+ .map(([name]) => [...group, name]))
13
+
14
+ if (!entries.length) {
15
+ return spec
16
+ }
17
+
18
+ const sparse = { openapi: spec.openapi }
19
+ entries.forEach(path => setIn(sparse, path, getIn(spec, path)))
20
+ const merged = merge(sparse, { source: spec })
21
+
22
+ const result = { ...spec }
23
+ entries.forEach(path => setIn(result, path, getIn(merged, path)))
24
+ return result
25
+ }
26
+
27
+ function hasAllOf(value: unknown): boolean {
28
+ if (!value || typeof value !== 'object') {
29
+ return false
30
+ }
31
+ return 'allOf' in value || Object.values(value).some(hasAllOf)
32
+ }
33
+
34
+ function getIn(value: any, path: string[]): any {
35
+ return path.reduce((node, key) => node?.[key], value)
36
+ }
37
+
38
+ // Shallow-copies containers along the path, so the input spec is never mutated.
39
+ function setIn(target: any, path: string[], value: unknown): void {
40
+ let node = target
41
+ for (const key of path.slice(0, -1)) {
42
+ node = node[key] = { ...node[key] }
43
+ }
44
+ node[path[path.length - 1]] = value
45
+ }
@@ -2,7 +2,6 @@ import type { JSONSchema } from '@trojs/openapi-dereference'
2
2
  import type { OpenAPIDocument, ParsedOpenAPI } from '../../types'
3
3
 
4
4
  import { $trycatch } from '@tszen/trycatch'
5
- import { merge } from 'allof-merge'
6
5
  import { parseSpec } from '../utils/parseSpec'
7
6
  import { dereferenceWithAnnotationsSync } from './dereferenceWithAnnotations'
8
7
  import { generateCodeSamples } from './generateCodeSamples'
@@ -12,6 +11,8 @@ import { generateMissingTags } from './generateMissingTags'
12
11
  import { generateRequestBodyUi } from './generateRequestBodyUi'
13
12
  import { generateResponseUi } from './generateResponseUi'
14
13
  import { generateSecurityUi } from './generateSecurityUi'
14
+ import { SchemaUiCache } from './getSchemaUi'
15
+ import { mergeAllOf } from './mergeAllOf'
15
16
 
16
17
  export function parseOpenapi() {
17
18
  function transformSync({
@@ -78,13 +79,14 @@ export function parseOpenapi() {
78
79
 
79
80
  let parsedSpec = { ...specContent } as ParsedOpenAPI
80
81
 
81
- const [mergedSpec, errMerge] = $trycatch(() => merge(
82
- transformSync({
82
+ const [mergedSpec, errMerge] = $trycatch(() => {
83
+ const transformed = transformSync({
83
84
  spec,
84
85
  defaultTag,
85
86
  defaultTagDescription,
86
- }),
87
- ) as ParsedOpenAPI)
87
+ })
88
+ return mergeAllOf(transformed) as ParsedOpenAPI
89
+ })
88
90
  parsedSpec = errMerge ? parsedSpec : mergedSpec
89
91
 
90
92
  const [dereferencedSpec, errDereference] = $trycatch(() => dereferenceWithAnnotationsSync(parsedSpec as JSONSchema) as ParsedOpenAPI)
@@ -93,10 +95,13 @@ export function parseOpenapi() {
93
95
  const [securitySpec, errSecurity] = $trycatch(() => generateSecurityUi(parsedSpec))
94
96
  parsedSpec = errSecurity ? parsedSpec : securitySpec
95
97
 
96
- const [requestBodySpec, errRequestBody] = $trycatch(() => generateRequestBodyUi(parsedSpec))
98
+ // Requests and responses share schemas: convert each once per parse.
99
+ const schemaUiCache = new SchemaUiCache()
100
+
101
+ const [requestBodySpec, errRequestBody] = $trycatch(() => generateRequestBodyUi(parsedSpec, schemaUiCache))
97
102
  parsedSpec = errRequestBody ? parsedSpec : requestBodySpec
98
103
 
99
- const [responseSpec, errResponse] = $trycatch(() => generateResponseUi(parsedSpec))
104
+ const [responseSpec, errResponse] = $trycatch(() => generateResponseUi(parsedSpec, schemaUiCache))
100
105
  parsedSpec = errResponse ? parsedSpec : responseSpec
101
106
 
102
107
  parsedSpec.externalDocs = parsedSpec.externalDocs || parsedSpec.externalDocs || {}
@@ -7,19 +7,22 @@ interface SchemaNode {
7
7
  parent: SchemaNode | null
8
8
  }
9
9
 
10
- export function resolveCircularRef(schema: OpenAPI.SchemaObject): OpenAPI.SchemaObject {
11
- const rootNode: SchemaNode = {
12
- key: 'root',
13
- value: schema,
14
- parent: null,
15
- }
16
-
17
- traverseNode(rootNode)
10
+ // `done` holds nodes already walked. Pass the same set across calls within one parse
11
+ // (operations reference the same dereferenced schemas) to walk each node only once.
12
+ export function resolveCircularRef(
13
+ schema: OpenAPI.SchemaObject,
14
+ done = new WeakSet<object>(),
15
+ ): OpenAPI.SchemaObject {
16
+ traverseNode({ key: 'root', value: schema, parent: null }, new Map(), done)
18
17
 
19
18
  return schema
20
19
  }
21
20
 
22
- function traverseNode(node: SchemaNode): void {
21
+ // Depth-first walk that cuts back edges (a node whose origin is already on the
22
+ // ancestor stack). Nodes already fully walked are skipped: removing every back
23
+ // edge found by a DFS leaves an acyclic graph, so shared schemas don't need to be
24
+ // re-expanded per path (which is exponential on specs like Stripe's).
25
+ function traverseNode(node: SchemaNode, ancestors: Map<unknown, SchemaNode>, done: WeakSet<object>): void {
23
26
  const { value } = node
24
27
 
25
28
  if (typeof value !== 'object' || value === null) {
@@ -27,51 +30,28 @@ function traverseNode(node: SchemaNode): void {
27
30
  return
28
31
  }
29
32
 
30
- const circularReference = detectCircularReference(node.parent, value)
33
+ const origin = (value as any)[originSymbol] ?? value
34
+ const ancestor = ancestors.get(origin)
31
35
 
32
- if (circularReference) {
36
+ if (ancestor) {
33
37
  // Replace the circular reference with a descriptor object.
34
38
  node.parent!.value[node.key] = {
35
39
  type: 'object',
36
- circularReference,
37
- }
38
- } else {
39
- // Recursively traverse child nodes.
40
- for (const [key, childValue] of Object.entries(value)) {
41
- const childNode: SchemaNode = {
42
- key,
43
- value: childValue,
44
- parent: node,
45
- }
46
-
47
- traverseNode(childNode)
40
+ circularReference: buildReferencePath(ancestor),
48
41
  }
42
+ return
49
43
  }
50
- }
51
44
 
52
- function detectCircularReference(
53
- ancestor: SchemaNode | null,
54
- value: any,
55
- ): string | null {
56
- const target
57
- = value && (value as any)[originSymbol]
58
- ? (value as any)[originSymbol]
59
- : value
60
-
61
- while (ancestor) {
62
- const ancestorValue = ancestor.value
63
- const ancestorTarget
64
- = ancestorValue && (ancestorValue as any)[originSymbol]
65
- ? (ancestorValue as any)[originSymbol]
66
- : ancestorValue
67
-
68
- if (ancestorTarget === target) {
69
- return buildReferencePath(ancestor)
70
- }
71
- ancestor = ancestor.parent
45
+ if (done.has(value)) {
46
+ return
72
47
  }
73
48
 
74
- return null
49
+ ancestors.set(origin, node)
50
+ for (const [key, childValue] of Object.entries(value)) {
51
+ traverseNode({ key, value: childValue, parent: node }, ancestors, done)
52
+ }
53
+ ancestors.delete(origin)
54
+ done.add(value)
75
55
  }
76
56
 
77
57
  function buildReferencePath(node: SchemaNode | null): string {
@@ -0,0 +1,42 @@
1
+ import type { ShikiGrammar, ShikiLanguageSource } from '../../composables/useTheme'
2
+
3
+ function isLanguageModule(value: object): value is { default: ShikiGrammar | ShikiGrammar[] } {
4
+ return 'default' in value && !('scopeName' in value)
5
+ }
6
+
7
+ /**
8
+ * Resolve a registry entry (grammar, array, or loader) into TextMate grammars.
9
+ */
10
+ export async function resolveShikiLanguageSource(source: ShikiLanguageSource): Promise<ShikiGrammar[]> {
11
+ const resolved = typeof source === 'function' ? await source() : source
12
+ const grammars = isLanguageModule(resolved) ? resolved.default : resolved
13
+ return Array.isArray(grammars) ? grammars : [grammars]
14
+ }
15
+
16
+ /**
17
+ * Ensure the registry key can be used as a Shiki language id when it differs
18
+ * from the grammar `name` / `aliases`.
19
+ */
20
+ export function withRegistryAlias(grammars: ShikiGrammar[], lang: string): ShikiGrammar[] {
21
+ if (grammars.length === 0) {
22
+ return grammars
23
+ }
24
+
25
+ const known = grammars.some(grammar => grammar.name === lang || grammar.aliases?.includes(lang))
26
+ if (known) {
27
+ return grammars
28
+ }
29
+
30
+ const [first, ...rest] = grammars
31
+ return [{
32
+ ...first,
33
+ aliases: [...(first.aliases ?? []), lang],
34
+ }, ...rest]
35
+ }
36
+
37
+ export function collectEmbeddedLangs(grammars: ShikiGrammar[]): string[] {
38
+ return [...new Set(grammars.flatMap(grammar => [
39
+ ...(grammar.embeddedLangs ?? []),
40
+ ...(grammar.embeddedLanguages ?? []),
41
+ ]))]
42
+ }
@@ -32,9 +32,13 @@ export function createOpenApiSpec(options: {
32
32
  } = {}): OpenApiSpecInstance {
33
33
  let innerSpec: OpenAPIDocument | null = null
34
34
  let innerOriginalSpec: OpenAPIDocument | null = options.originalSpec ?? null
35
+ // operationId -> location, built on first lookup so repeated lookups (one per
36
+ // rendered operation, per operation link) don't rescan every path and verb.
37
+ let operationIndex: Map<string, { path: string, method: string, operation: any }> | null = null
35
38
 
36
39
  function setSpec(spec: OpenAPIDocument) {
37
40
  innerSpec = spec
41
+ operationIndex = null
38
42
  }
39
43
 
40
44
  function getSpec(): OpenAPIDocument {
@@ -55,53 +59,32 @@ export function createOpenApiSpec(options: {
55
59
  innerOriginalSpec = spec
56
60
  }
57
61
 
58
- function findOperation(paths: OpenAPIV3.PathsObject, operationId: string) {
59
- for (const path of Object.values(paths)) {
60
- for (const verb of httpVerbs) {
61
- if (path && path[verb]?.operationId === operationId) {
62
- return path[verb]
62
+ function findOperation(operationId: string) {
63
+ if (!operationIndex) {
64
+ operationIndex = new Map()
65
+ for (const [path, methods] of Object.entries(getPaths())) {
66
+ for (const verb of httpVerbs) {
67
+ const operation = methods?.[verb]
68
+ // First match wins, like the linear scan this replaces.
69
+ if (operation?.operationId !== undefined && !operationIndex.has(operation.operationId)) {
70
+ operationIndex.set(operation.operationId, { path, method: verb, operation })
71
+ }
63
72
  }
64
73
  }
65
74
  }
66
- return null
75
+ return operationIndex.get(operationId) ?? null
67
76
  }
68
77
 
69
78
  function getOperation(operationId: string) {
70
- const paths = getSpec().paths as OpenAPIV3.PathsObject
71
- if (!paths) {
72
- return null
73
- }
74
- return findOperation(paths, operationId)
79
+ return findOperation(operationId)?.operation ?? null
75
80
  }
76
81
 
77
82
  function getOperationPath(operationId: string) {
78
- const paths = getSpec().paths as OpenAPIV3.PathsObject
79
- if (!paths) {
80
- return null
81
- }
82
- for (const [path, methods] of Object.entries(paths)) {
83
- for (const verb of httpVerbs) {
84
- if (methods && methods[verb]?.operationId === operationId) {
85
- return path
86
- }
87
- }
88
- }
89
- return null
83
+ return findOperation(operationId)?.path ?? null
90
84
  }
91
85
 
92
86
  function getOperationMethod(operationId: string) {
93
- const paths = getSpec().paths as OpenAPIV3.PathsObject
94
- if (!paths) {
95
- return null
96
- }
97
- for (const path of Object.values(paths)) {
98
- for (const verb of httpVerbs) {
99
- if (path && path[verb]?.operationId === operationId) {
100
- return verb
101
- }
102
- }
103
- }
104
- return null
87
+ return findOperation(operationId)?.method ?? null
105
88
  }
106
89
 
107
90
  function getOperationParameters(operationId: string) {
@@ -152,13 +135,12 @@ export function createOpenApiSpec(options: {
152
135
  }
153
136
 
154
137
  function getOperationServers(operationId: string): OpenAPIV3.ServerObject[] {
155
- const operation = findOperation(getPaths(), operationId)
156
- if (!operation) {
138
+ const entry = findOperation(operationId)
139
+ if (!entry) {
157
140
  return []
158
141
  }
159
- const operationPath = getOperationPath(operationId)
160
- const paths = getSpec().paths as OpenAPIV3.PathsObject
161
- const pathServers = paths[(operationPath ?? '')]?.servers
142
+ const operation = entry.operation
143
+ const pathServers = getPaths()[entry.path]?.servers
162
144
 
163
145
  if (operation?.servers !== undefined) {
164
146
  return operation.servers as OpenAPIV3.ServerObject[]
@@ -173,19 +155,13 @@ export function createOpenApiSpec(options: {
173
155
  if (!getSpec().paths) {
174
156
  return []
175
157
  }
176
- const paths = getSpec().paths as OpenAPIV3.PathsObject
177
- return Object.values(paths).reduce((tags: string[], path) => {
158
+ const tags = new Set<string>()
159
+ for (const path of Object.values(getPaths())) {
178
160
  for (const verb of httpVerbs) {
179
- if (path && path[verb]?.tags) {
180
- path[verb].tags.forEach((tag: string) => {
181
- if (!tags.includes(tag)) {
182
- tags.push(tag)
183
- }
184
- })
185
- }
161
+ path?.[verb]?.tags?.forEach((tag: string) => tags.add(tag))
186
162
  }
187
- return tags
188
- }, [])
163
+ }
164
+ return [...tags]
189
165
  }
190
166
 
191
167
  function filterPaths(predicate: (operation: any) => boolean) {