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.
- package/dist/{angular-html-CGsuZc6a.cjs → angular-html-IrYiNUL5.cjs} +1 -1
- package/dist/{angular-html-DARb335O.js → angular-html-uv0a0QNn.js} +2 -2
- package/dist/{angular-ts-CrrEVOLQ.js → angular-ts-CVTzQ4yM.js} +2 -2
- package/dist/{angular-ts-Bg4b1K8o.cjs → angular-ts-CmalYPic.cjs} +1 -1
- package/dist/{apl-D9ujzlDe.cjs → apl-Cp2eHb5H.cjs} +1 -1
- package/dist/{apl-BUNzB7iS.js → apl-G7yswX6Q.js} +5 -5
- package/dist/{astro-DuWrFiiv.cjs → astro-CRpTyG5K.cjs} +1 -1
- package/dist/{astro-CT6LVfZb.js → astro-DUi5zMa4.js} +5 -5
- package/dist/{blade-DEZwhTmz.cjs → blade-DMsLIvGX.cjs} +1 -1
- package/dist/{blade-CT3BYEkw.js → blade-uJ4Xa5wc.js} +7 -7
- package/dist/{c-Df26Rt3n.js → c-CtMd0n5W.js} +1 -1
- package/dist/{c-DDdF0YXr.cjs → c-DJDNxT35.cjs} +1 -1
- package/dist/{chapel-BGl0pLYE.cjs → chapel-CCgxhb9n.cjs} +1 -1
- package/dist/{chapel-7XVmedRB.js → chapel-DGgSBAIm.js} +1 -1
- package/dist/{cobol-7e4lFVpj.js → cobol-CDcij9i2.js} +2 -2
- package/dist/{cobol-BgGrvcfE.cjs → cobol-DP8yLe0J.cjs} +1 -1
- package/dist/{coffee-D2EFnoK3.js → coffee-Bcg2ycks.js} +1 -1
- package/dist/{coffee-CnTOT7qi.cjs → coffee-D3hXAm0d.cjs} +1 -1
- package/dist/{cpp-BdIhYOqJ.cjs → cpp-CEMyuz0Z.cjs} +1 -1
- package/dist/{cpp-BrJ3qayw.js → cpp-CfsSSf1b.js} +3 -3
- package/dist/{crystal-CijsJH2S.js → crystal-B76s5RL_.js} +6 -6
- package/dist/{crystal-C0oOOTvI.cjs → crystal-BPjfGQfv.cjs} +1 -1
- package/dist/{css-BJ4fQgJY.cjs → css-B_5YxPHw.cjs} +1 -1
- package/dist/{css-BDLPKt_n.js → css-Dnve9eIF.js} +1 -1
- package/dist/{edge-D7t7tSii.cjs → edge-DEHYswlE.cjs} +1 -1
- package/dist/{edge-CWCiEXP9.js → edge-Dlu9JAOU.js} +3 -3
- package/dist/{elixir-CEVCh53I.cjs → elixir-CKhKSpjp.cjs} +1 -1
- package/dist/{elixir-8Qtl7ev_.js → elixir-CSK8G02U.js} +1 -1
- package/dist/{elm-CQNq4BKy.js → elm-CsVe-drn.js} +1 -1
- package/dist/{elm-BktTaRPW.cjs → elm-oUMNo4dE.cjs} +1 -1
- package/dist/{erb-DCFD7vrt.js → erb-3PcpbjWs.js} +2 -2
- package/dist/{erb-Bas_b7PL.cjs → erb-B8WJz_Ls.cjs} +1 -1
- package/dist/{git-rebase-CSFTH0sQ.js → git-rebase-BFPUa7RP.js} +1 -1
- package/dist/{git-rebase-DGo4nA7C.cjs → git-rebase-CBj8NRO-.cjs} +1 -1
- package/dist/{glimmer-js-Z7E0DaWX.cjs → glimmer-js-BkM2LzJ_.cjs} +1 -1
- package/dist/{glimmer-js-Ce8bwdpO.js → glimmer-js-C06d46qf.js} +4 -4
- package/dist/{glimmer-ts-osenBmqR.cjs → glimmer-ts-B9TsQ9YM.cjs} +1 -1
- package/dist/{glimmer-ts-CdP0Y2rr.js → glimmer-ts-BfZJAJhH.js} +4 -4
- package/dist/{glsl-gQ2PTprT.js → glsl-Bl7M-IPe.js} +2 -2
- package/dist/{glsl-DqSyLtjd.cjs → glsl-uL1y-Bk6.cjs} +1 -1
- package/dist/{graphql-DTkt67qx.cjs → graphql-UjpB-MIz.cjs} +1 -1
- package/dist/{graphql-D9d0A3NW.js → graphql-j5wYAqtD.js} +5 -5
- package/dist/{hack-D2t7w518.js → hack-BN-XE31l.js} +2 -2
- package/dist/{hack-BsFtI2Eg.cjs → hack-DC3gQB4E.cjs} +1 -1
- package/dist/{haml-BBf8fdr9.cjs → haml-Bhy5P-KC.cjs} +1 -1
- package/dist/{haml-DtrHnXyI.js → haml-CDfF0h4F.js} +3 -3
- package/dist/{handlebars-BFrhjavm.js → handlebars-BRDXZqV4.js} +4 -4
- package/dist/{handlebars-DPepJR-F.cjs → handlebars-CNE9oFMe.cjs} +1 -1
- package/dist/{html-CZSxUh6E.js → html-CPA7KoKg.js} +3 -3
- package/dist/{html-tDTTwBjP.cjs → html-DF6ZRDg_.cjs} +1 -1
- package/dist/{html-derivative-1D9rMziY.js → html-derivative-61htNTyH.js} +1 -1
- package/dist/{html-derivative-CiU9WY3_.cjs → html-derivative-D7b_E1PX.cjs} +1 -1
- package/dist/{http-BEeboTha.cjs → http-BjRzGfMq.cjs} +1 -1
- package/dist/{http-_yCM4LFM.js → http-CR6vxe-f.js} +4 -4
- package/dist/{hurl-CjTriWW3.js → hurl-DR3Ao4uN.js} +2 -2
- package/dist/{hurl-CzW0xtQK.cjs → hurl-Dz53E_EO.cjs} +1 -1
- package/dist/{java-BBWcloI5.js → java-BCOO6DGx.js} +1 -1
- package/dist/{java-DEV9nIzf.cjs → java-rdA6e0wp.cjs} +1 -1
- package/dist/{javascript-COXg7KRK.cjs → javascript-4PA_CVZC.cjs} +1 -1
- package/dist/{javascript-BtdwTU5l.js → javascript-B0H0Bm6m.js} +1 -1
- package/dist/{jinja-SDapQ1jF.cjs → jinja-BcxYV4gu.cjs} +1 -1
- package/dist/{jinja-0Fph51Wu.js → jinja-DdO6Tf4t.js} +1 -1
- package/dist/{jison-C6HvDI82.cjs → jison-BJENBrIF.cjs} +1 -1
- package/dist/{jison-DKkCHBi3.js → jison-CmQksr2y.js} +1 -1
- package/dist/{json-D9-BN10e.cjs → json-BJ_bvg_A.cjs} +1 -1
- package/dist/{json-1Shnxn5T.js → json-Dd3OP7m9.js} +1 -1
- package/dist/{jsx-DMGrwzK7.js → jsx-BhoiPRal.js} +1 -1
- package/dist/{jsx-CJ8AuAld.cjs → jsx-CaK8syd3.cjs} +1 -1
- package/dist/{julia-CtGveS0F.js → julia-CDeyMHwa.js} +4 -4
- package/dist/{julia-BOWoqzWb.cjs → julia-DdPKjdf7.cjs} +1 -1
- package/dist/{just-DJBTWvtH.cjs → just-B3mF2_pd.cjs} +1 -1
- package/dist/{just-Ocglo-Ta.js → just-Db1lRieD.js} +5 -5
- package/dist/{latex-CwRnFmhO.js → latex-D73GL9tM.js} +1 -1
- package/dist/{latex-jmD-x2Sw.cjs → latex-DyUb8gG5.cjs} +1 -1
- package/dist/{liquid-B0j0Ojr6.cjs → liquid-CztsYCRo.cjs} +1 -1
- package/dist/{liquid-BUvHlsu4.js → liquid-DF-tIke9.js} +4 -4
- package/dist/{lua-Cx8wh7Cx.cjs → lua-Cg38zrfV.cjs} +1 -1
- package/dist/{lua-CCwV5A-2.js → lua-xXZSPcKB.js} +2 -2
- package/dist/{marko-DgvX-ocG.cjs → marko-BuXulXH5.cjs} +1 -1
- package/dist/{marko-B7d7a75U.js → marko-D-oNtuqC.js} +3 -3
- package/dist/{mdc-T8GMGcnF.cjs → mdc-CXK0bw8f.cjs} +1 -1
- package/dist/{mdc-qWBp3e-g.js → mdc-FTCNLElJ.js} +2 -2
- package/dist/{nginx-BbITQOFT.js → nginx-C7lNZZWT.js} +1 -1
- package/dist/{nginx-CJ6LIx1U.cjs → nginx-Cgnh7QO-.cjs} +1 -1
- package/dist/{nim-_u7AMou0.cjs → nim-D3q9r1nf.cjs} +1 -1
- package/dist/{nim-jrsjoy8-.js → nim-DIkmkdRK.js} +6 -6
- package/dist/{org-BlOpuc2_.cjs → org-Be03OJi3.cjs} +1 -1
- package/dist/{org-BvB9eDZB.js → org-CsORUXsX.js} +26 -26
- package/dist/{perl-Db3mBsuQ.js → perl-DzKqYwtD.js} +5 -5
- package/dist/{perl-D8XroKo0.cjs → perl-jEpH5QnN.cjs} +1 -1
- package/dist/{php-C8SG25Wa.cjs → php-Cd0xNNLC.cjs} +1 -1
- package/dist/{php-DXAFydNe.js → php-MrcCGNBb.js} +6 -6
- package/dist/{pug-DUGE64tE.js → pug-7jPx_35W.js} +3 -3
- package/dist/{pug-DGLtElT2.cjs → pug-tintEWep.cjs} +1 -1
- package/dist/{qml-BI8Qke4k.js → qml-6QUtoeWA.js} +1 -1
- package/dist/{qml-f8YoerFJ.cjs → qml-BYzhsmnS.cjs} +1 -1
- package/dist/{r-DTie9Nyk.cjs → r-Bwq_agHo.cjs} +1 -1
- package/dist/{r-BqUCIOdg.js → r-DSFCAodN.js} +1 -1
- package/dist/{razor-Cznq4CrH.cjs → razor-GHEO8ZrJ.cjs} +1 -1
- package/dist/{razor-DzYuKCwQ.js → razor-kZ9VMhh7.js} +1 -1
- package/dist/{regexp-W6uDzT_l.cjs → regexp-BTPSBkuS.cjs} +1 -1
- package/dist/{regexp-CCkYPv1N.js → regexp-C4cLyNsj.js} +1 -1
- package/dist/{rst-DkdHGABB.js → rst-Celv7pzQ.js} +6 -6
- package/dist/{rst-CjRZqYHL.cjs → rst-DC596VAb.cjs} +1 -1
- package/dist/{ruby-SrIlbOFE.js → ruby-CMUkZc4V.js} +12 -12
- package/dist/{ruby-DYZIHus3.cjs → ruby-CkA4Oavu.cjs} +1 -1
- package/dist/{sas-D4DC5Y7L.cjs → sas-CWtZaM4y.cjs} +1 -1
- package/dist/{sas-BgMaDA2M.js → sas-DM3UyDFg.js} +1 -1
- package/dist/{scss-Cy7mHhKR.js → scss-Ce0za1qK.js} +2 -2
- package/dist/{scss-D2afYGNC.cjs → scss-LkHhJo18.cjs} +1 -1
- package/dist/{shellscript-DL7dA6YH.cjs → shellscript-CiDBNSSV.cjs} +1 -1
- package/dist/{shellscript-Dc7jtvdg.js → shellscript-DfQbZbZv.js} +1 -1
- package/dist/{shellsession-BZTJuggn.js → shellsession-B-u2-M3U.js} +1 -1
- package/dist/{shellsession-CGkCOuFx.cjs → shellsession-VJTxH3Qp.cjs} +1 -1
- package/dist/{soy-B2OqotLG.cjs → soy-CFhgAJvR.cjs} +1 -1
- package/dist/{soy-X1cLpGrT.js → soy-K4I5GWmG.js} +1 -1
- package/dist/{sql-BLxweCea.cjs → sql-CySKVD8Q.cjs} +1 -1
- package/dist/{sql-DRYM5A-g.js → sql-jusQgRuy.js} +1 -1
- package/dist/{stata-DUfnFR7t.cjs → stata-9iclJTGl.cjs} +1 -1
- package/dist/{stata-mshAKmrC.js → stata-B0U1mDy6.js} +1 -1
- package/dist/{surrealql-DQzrI0uj.js → surrealql-6aGCR7SU.js} +1 -1
- package/dist/{surrealql-Zfoia8BY.cjs → surrealql-DysQv_VH.cjs} +1 -1
- package/dist/{svelte-D2bLGYCT.js → svelte-B9UOpTL8.js} +3 -3
- package/dist/{svelte-aFul1Jy8.cjs → svelte-ZhIemg1n.cjs} +1 -1
- package/dist/{templ-Dx8bEvea.cjs → templ-BaKkruXs.cjs} +1 -1
- package/dist/{templ-BT5bFFZC.js → templ-CwElXEjo.js} +2 -2
- package/dist/{tex-DLVxreb-.cjs → tex-CwQDQCX_.cjs} +1 -1
- package/dist/{tex-BGjRDs2m.js → tex-kQHmfFkX.js} +2 -2
- package/dist/{ts-tags-Ck5aGNIn.js → ts-tags-BkcgKPdU.js} +7 -7
- package/dist/{ts-tags-BIebym7V.cjs → ts-tags-Dqqv0wS7.cjs} +1 -1
- package/dist/{tsx-B4QBkk0q.cjs → tsx-TxRbY_MS.cjs} +1 -1
- package/dist/{tsx-G3EWmL7D.js → tsx-tC9_eQM0.js} +1 -1
- package/dist/{twig-BgwYNE2l.cjs → twig-Dsriugp3.cjs} +1 -1
- package/dist/{twig-CHwtVyR-.js → twig-zezbIase.js} +5 -5
- package/dist/types/src/components/Common/OAJSONEditor.vue.d.ts +2 -2
- package/dist/types/src/composables/useShiki.d.ts +13 -2
- package/dist/types/src/composables/useTheme.d.ts +53 -0
- package/dist/types/src/lib/parser/generateRequestBodyUi.d.ts +2 -1
- package/dist/types/src/lib/parser/generateResponseUi.d.ts +2 -1
- package/dist/types/src/lib/parser/getSchemaUi.d.ts +5 -1
- package/dist/types/src/lib/parser/mergeAllOf.d.ts +6 -0
- package/dist/types/src/lib/parser/resolveCircularRef.d.ts +1 -1
- package/dist/types/src/lib/shiki/resolveGrammar.d.ts +11 -0
- package/dist/{typescript-DoW3h951.cjs → typescript-BoS6yqrz.cjs} +1 -1
- package/dist/{typescript-DAazdaCE.js → typescript-KKVXItRs.js} +1 -1
- package/dist/{typst-9vf_wdP8.cjs → typst-B_783qIn.cjs} +1 -1
- package/dist/{typst-BLT0Jxqy.js → typst-DsM2L8MG.js} +29 -29
- package/dist/{useOpenapi-zUwxozsv.cjs → useOpenapi-DOw8b0Cm.cjs} +83 -83
- package/dist/{useOpenapi-DyGwf6EG.js → useOpenapi-tKaw3COz.js} +1526 -1467
- package/dist/vitepress-openapi.client.cjs.js +126 -126
- package/dist/vitepress-openapi.client.es.js +12914 -12832
- package/dist/vitepress-openapi.node.cjs.js +1 -1
- package/dist/vitepress-openapi.node.es.js +1 -1
- package/dist/{vue-CpqLnHVY.js → vue-B58kMEAQ.js} +6 -6
- package/dist/{vue-BRjGF9q6.cjs → vue-C-ymR46K.cjs} +1 -1
- package/dist/{vue-html-Zve9lhNA.js → vue-html-B8vwCoQU.js} +1 -1
- package/dist/{vue-html-5pJeWJlE.cjs → vue-html-qs-Ree4R.cjs} +1 -1
- package/dist/{vue-vine-BIyjr9Yw.js → vue-vine-B95XCKNF.js} +3 -3
- package/dist/{vue-vine-D8sXouna.cjs → vue-vine-Nsb-fhNk.cjs} +1 -1
- package/dist/{xml-B4yjP0re.js → xml-B119d3-g.js} +2 -2
- package/dist/{xml-DfteIxKp.cjs → xml-DzTGxXsy.cjs} +1 -1
- package/dist/{xsl-BfNOhnnx.js → xsl-CEz1476V.js} +1 -1
- package/dist/{xsl-BaF5pye5.cjs → xsl-xWljPYeJ.cjs} +1 -1
- package/dist/{yaml-BMWpYE45.js → yaml-B9YlAzUe.js} +1 -1
- package/dist/{yaml-BWP6Z5iN.cjs → yaml-Cd_AUGXn.cjs} +1 -1
- package/package.json +1 -1
- package/src/components/Common/OAJSONEditor.vue +2 -1
- package/src/composables/useOpenapi.ts +2 -2
- package/src/composables/usePlayground.ts +4 -2
- package/src/composables/useShiki.ts +226 -105
- package/src/composables/useTheme.ts +57 -0
- package/src/lib/parser/dereferenceWithAnnotations.ts +22 -5
- package/src/lib/parser/generateRequestBodyUi.ts +3 -3
- package/src/lib/parser/generateResponseUi.ts +3 -3
- package/src/lib/parser/getSchemaUi.ts +50 -22
- package/src/lib/parser/mergeAllOf.ts +45 -0
- package/src/lib/parser/parseOpenapi.ts +12 -7
- package/src/lib/parser/resolveCircularRef.ts +25 -45
- package/src/lib/shiki/resolveGrammar.ts +42 -0
- package/src/lib/spec/createOpenApiSpec.ts +27 -51
|
@@ -1,158 +1,279 @@
|
|
|
1
|
-
import type { HighlighterCore } from 'shiki/core'
|
|
1
|
+
import type { HighlighterCore, LanguageRegistration } from 'shiki/core'
|
|
2
2
|
import type { BundledLanguage } from 'shiki/langs'
|
|
3
3
|
import { createHighlighterCore } from 'shiki/core'
|
|
4
4
|
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript'
|
|
5
5
|
import { bundledLanguages as highlighterImports } from 'shiki/langs'
|
|
6
6
|
import { ref } from 'vue'
|
|
7
|
+
import {
|
|
8
|
+
collectEmbeddedLangs,
|
|
9
|
+
resolveShikiLanguageSource,
|
|
10
|
+
withRegistryAlias,
|
|
11
|
+
} from '../lib/shiki/resolveGrammar'
|
|
7
12
|
import { useTheme } from './useTheme'
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
/** Always loaded for response / schema bodies (not the code-samples UI). */
|
|
10
15
|
const CORE_HIGHLIGHTERS: BundledLanguage[] = ['json', 'xml', 'markdown']
|
|
11
16
|
|
|
17
|
+
const FALLBACK_HTML = (content: string) => `<pre><code>${content}</code></pre>`
|
|
18
|
+
|
|
12
19
|
let shiki: HighlighterCore | null = null
|
|
13
20
|
let initPromise: Promise<void> | null = null
|
|
14
|
-
|
|
15
|
-
// Track in-flight language loads to avoid duplicate requests
|
|
16
21
|
const languageLoadPromises = new Map<string, Promise<boolean>>()
|
|
17
|
-
|
|
22
|
+
/** In-flight registered-grammar resolves, shared across concurrent batch walks. */
|
|
23
|
+
const languageSourcePromises = new Map<string, Promise<LanguageRegistration[]>>()
|
|
18
24
|
const loading = ref(true)
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function init(): Promise<void> {
|
|
26
|
-
if (initPromise) {
|
|
27
|
-
return initPromise
|
|
28
|
-
}
|
|
26
|
+
async function resolveRegisteredGrammars(lang: string): Promise<LanguageRegistration[] | null> {
|
|
27
|
+
const cached = languageSourcePromises.get(lang)
|
|
28
|
+
if (cached) {
|
|
29
|
+
return cached
|
|
30
|
+
}
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const themeConfig = useTheme()
|
|
38
|
-
|
|
39
|
-
// Load only core highlighters during init
|
|
40
|
-
const coreLangModules = await Promise.all(
|
|
41
|
-
CORE_HIGHLIGHTERS.map(async (lang) => {
|
|
42
|
-
const importer = highlighterImports[lang]
|
|
43
|
-
if (!importer) {
|
|
44
|
-
return []
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
const mod = await importer()
|
|
48
|
-
return mod.default
|
|
49
|
-
} catch {
|
|
50
|
-
return []
|
|
51
|
-
}
|
|
52
|
-
}),
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
shiki = await createHighlighterCore({
|
|
56
|
-
themes: [
|
|
57
|
-
themeConfig.getHighlighterTheme()?.light,
|
|
58
|
-
themeConfig.getHighlighterTheme()?.dark,
|
|
59
|
-
],
|
|
60
|
-
langs: coreLangModules.filter(Boolean).flat(),
|
|
61
|
-
engine: createJavaScriptRegexEngine({
|
|
62
|
-
target: 'ES2018',
|
|
63
|
-
}),
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
if (!shiki) {
|
|
67
|
-
throw new Error('Failed to create Shiki highlighter')
|
|
68
|
-
}
|
|
32
|
+
const source = useTheme().getShikiLanguage(lang)
|
|
33
|
+
if (!source) {
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
69
36
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
37
|
+
const pending = Promise.resolve(resolveShikiLanguageSource(source))
|
|
38
|
+
.then(grammars => withRegistryAlias(grammars, lang) as LanguageRegistration[])
|
|
39
|
+
.catch((error) => {
|
|
40
|
+
// Drop only this attempt so a later ensureLanguage can retry the loader.
|
|
41
|
+
if (languageSourcePromises.get(lang) === pending) {
|
|
42
|
+
languageSourcePromises.delete(lang)
|
|
74
43
|
}
|
|
75
|
-
|
|
44
|
+
throw error
|
|
45
|
+
})
|
|
76
46
|
|
|
77
|
-
|
|
47
|
+
languageSourcePromises.set(lang, pending)
|
|
48
|
+
return pending
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function importBundledLanguage(lang: BundledLanguage): Promise<LanguageRegistration[]> {
|
|
52
|
+
const importer = highlighterImports[lang]
|
|
53
|
+
if (!importer) {
|
|
54
|
+
return []
|
|
78
55
|
}
|
|
79
56
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
57
|
+
try {
|
|
58
|
+
const mod = await importer()
|
|
59
|
+
return mod.default
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return []
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function loadCoreLanguages(): Promise<LanguageRegistration[]> {
|
|
67
|
+
const modules = await Promise.all(CORE_HIGHLIGHTERS.map(importBundledLanguage))
|
|
68
|
+
return modules.flat()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function createHighlighter(): Promise<HighlighterCore> {
|
|
72
|
+
const themeConfig = useTheme()
|
|
73
|
+
const highlighter = await createHighlighterCore({
|
|
74
|
+
themes: [
|
|
75
|
+
themeConfig.getHighlighterTheme()?.light,
|
|
76
|
+
themeConfig.getHighlighterTheme()?.dark,
|
|
77
|
+
],
|
|
78
|
+
langs: await loadCoreLanguages(),
|
|
79
|
+
engine: createJavaScriptRegexEngine({
|
|
80
|
+
target: 'ES2018',
|
|
81
|
+
}),
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
if (!highlighter) {
|
|
85
|
+
throw new Error('Failed to create Shiki highlighter')
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return highlighter
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function isLanguageReady(lang: string): boolean {
|
|
92
|
+
return shiki?.getLoadedLanguages().includes(lang) ?? false
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Walk registered grammars (including circular embeds) into one batch, and
|
|
97
|
+
* collect bundled embed ids that must be ensured before the batch load.
|
|
98
|
+
* Cycles among registered grammars are handled by `batch.has(lang)`.
|
|
99
|
+
*/
|
|
100
|
+
async function collectRegisteredGrammarBatch(
|
|
101
|
+
lang: string,
|
|
102
|
+
batch: Map<string, LanguageRegistration[]>,
|
|
103
|
+
bundledEmbeds: Set<string>,
|
|
104
|
+
): Promise<void> {
|
|
105
|
+
if (batch.has(lang) || isLanguageReady(lang)) {
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const grammars = await resolveRegisteredGrammars(lang)
|
|
110
|
+
if (!grammars) {
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
batch.set(lang, grammars)
|
|
115
|
+
|
|
116
|
+
for (const embeddedLang of collectEmbeddedLangs(grammars)) {
|
|
117
|
+
if (isLanguageReady(embeddedLang)) {
|
|
118
|
+
continue
|
|
91
119
|
}
|
|
92
120
|
|
|
93
|
-
if (
|
|
121
|
+
if (useTheme().getShikiLanguage(embeddedLang)) {
|
|
122
|
+
// Keep cyclic / nested registered grammars in the same loadLanguage call.
|
|
123
|
+
await collectRegisteredGrammarBatch(embeddedLang, batch, bundledEmbeds)
|
|
124
|
+
continue
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
bundledEmbeds.add(embeddedLang)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function loadRegisteredLanguage(lang: string): Promise<boolean> {
|
|
132
|
+
if (!shiki) {
|
|
133
|
+
return false
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const batch = new Map<string, LanguageRegistration[]>()
|
|
137
|
+
const bundledEmbeds = new Set<string>()
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
await collectRegisteredGrammarBatch(lang, batch, bundledEmbeds)
|
|
141
|
+
|
|
142
|
+
if (!batch.has(lang)) {
|
|
94
143
|
return false
|
|
95
144
|
}
|
|
96
145
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
146
|
+
for (const embeddedLang of bundledEmbeds) {
|
|
147
|
+
if (isLanguageReady(embeddedLang)) {
|
|
148
|
+
continue
|
|
149
|
+
}
|
|
150
|
+
await ensureLanguage(embeddedLang)
|
|
100
151
|
}
|
|
101
152
|
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
153
|
+
// Register the whole registered subgraph together so circular embeds resolve.
|
|
154
|
+
await shiki.loadLanguage([...batch.values()].flat())
|
|
155
|
+
return isLanguageReady(lang)
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
for (const key of batch.keys()) {
|
|
159
|
+
languageSourcePromises.delete(key)
|
|
106
160
|
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
107
163
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
164
|
+
async function loadBundledLanguage(lang: string): Promise<boolean> {
|
|
165
|
+
if (!shiki) {
|
|
166
|
+
return false
|
|
167
|
+
}
|
|
111
168
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
169
|
+
const grammars = await importBundledLanguage(lang as BundledLanguage)
|
|
170
|
+
if (grammars.length === 0) {
|
|
171
|
+
console.warn(`Shiki language "${lang}" not available.`)
|
|
172
|
+
return false
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
await shiki.loadLanguage(grammars)
|
|
176
|
+
return true
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function loadLanguage(lang: string): Promise<boolean> {
|
|
180
|
+
try {
|
|
181
|
+
if (useTheme().getShikiLanguage(lang)) {
|
|
182
|
+
return await loadRegisteredLanguage(lang)
|
|
183
|
+
}
|
|
184
|
+
return await loadBundledLanguage(lang)
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
console.error(`Failed to load Shiki language "${lang}":`, error)
|
|
188
|
+
return false
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
languageLoadPromises.delete(lang)
|
|
192
|
+
languageSourcePromises.delete(lang)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Initialize Shiki with core highlighters only (json, xml, markdown).
|
|
198
|
+
* Additional languages are loaded on-demand via ensureLanguage().
|
|
199
|
+
*/
|
|
200
|
+
function init(): Promise<void> {
|
|
201
|
+
if (initPromise) {
|
|
202
|
+
return initPromise
|
|
203
|
+
}
|
|
116
204
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
console.error(`Failed to load Shiki language "${lang}":`, e)
|
|
123
|
-
return false
|
|
124
|
-
} finally {
|
|
125
|
-
languageLoadPromises.delete(lang)
|
|
205
|
+
initPromise = (async () => {
|
|
206
|
+
try {
|
|
207
|
+
if (shiki) {
|
|
208
|
+
loading.value = false
|
|
209
|
+
return
|
|
126
210
|
}
|
|
127
|
-
})()
|
|
128
211
|
|
|
129
|
-
|
|
130
|
-
|
|
212
|
+
shiki = await createHighlighter()
|
|
213
|
+
loading.value = false
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
initPromise = null
|
|
217
|
+
throw error
|
|
218
|
+
}
|
|
219
|
+
})()
|
|
220
|
+
|
|
221
|
+
return initPromise
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Ensure a language is loaded. Loads it on-demand if not already available.
|
|
226
|
+
* Returns true if the language is ready, false if it couldn't be loaded.
|
|
227
|
+
*/
|
|
228
|
+
async function ensureLanguage(lang: string): Promise<boolean> {
|
|
229
|
+
try {
|
|
230
|
+
await init()
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
console.error('Failed to initialize Shiki:', error)
|
|
234
|
+
return false
|
|
131
235
|
}
|
|
132
236
|
|
|
237
|
+
if (!shiki) {
|
|
238
|
+
return false
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (isLanguageReady(lang)) {
|
|
242
|
+
return true
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const inFlight = languageLoadPromises.get(lang)
|
|
246
|
+
if (inFlight) {
|
|
247
|
+
return inFlight
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const loadPromise = loadLanguage(lang)
|
|
251
|
+
languageLoadPromises.set(lang, loadPromise)
|
|
252
|
+
return loadPromise
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function useShiki() {
|
|
133
256
|
function isReady(): boolean {
|
|
134
257
|
return shiki !== null
|
|
135
258
|
}
|
|
136
259
|
|
|
137
260
|
function isLanguageLoaded(lang: string): boolean {
|
|
138
|
-
return
|
|
261
|
+
return isLanguageReady(lang)
|
|
139
262
|
}
|
|
140
263
|
|
|
141
264
|
function renderShiki(content: string, { lang, theme }: { lang: string, theme: string }) {
|
|
142
|
-
if (shiki
|
|
143
|
-
return
|
|
144
|
-
lang,
|
|
145
|
-
theme,
|
|
146
|
-
})
|
|
147
|
-
} else {
|
|
148
|
-
return `<pre><code>${content}</code></pre>`
|
|
265
|
+
if (!shiki || !isLanguageReady(lang)) {
|
|
266
|
+
return FALLBACK_HTML(content)
|
|
149
267
|
}
|
|
268
|
+
|
|
269
|
+
return shiki.codeToHtml(content, { lang, theme })
|
|
150
270
|
}
|
|
151
271
|
|
|
152
272
|
function reset() {
|
|
153
273
|
shiki = null
|
|
154
274
|
initPromise = null
|
|
155
275
|
languageLoadPromises.clear()
|
|
276
|
+
languageSourcePromises.clear()
|
|
156
277
|
loading.value = true
|
|
157
278
|
}
|
|
158
279
|
|
|
@@ -51,11 +51,41 @@ export type PlaygroundJsonEditorMode = 'text' | 'tree' | 'table'
|
|
|
51
51
|
export type Languages = 'es' | 'en' | 'ja' | 'pt-BR' | 'zh' | string
|
|
52
52
|
export type Messages = Record<Languages, Record<string, string>>
|
|
53
53
|
|
|
54
|
+
export interface ShikiGrammar {
|
|
55
|
+
name: string
|
|
56
|
+
scopeName: string
|
|
57
|
+
displayName?: string
|
|
58
|
+
aliases?: string[]
|
|
59
|
+
embeddedLangs?: string[]
|
|
60
|
+
embeddedLanguages?: string[]
|
|
61
|
+
patterns?: readonly unknown[]
|
|
62
|
+
repository?: Record<string, unknown>
|
|
63
|
+
injectTo?: string[]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ShikiLanguageModule {
|
|
67
|
+
default: ShikiGrammar | ShikiGrammar[]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
type ShikiLanguageResolved = ShikiLanguageModule | ShikiGrammar | ShikiGrammar[]
|
|
71
|
+
|
|
72
|
+
export type ShikiLanguageSource
|
|
73
|
+
= | ShikiGrammar
|
|
74
|
+
| ShikiGrammar[]
|
|
75
|
+
| (() => ShikiLanguageResolved | Promise<ShikiLanguageResolved>)
|
|
76
|
+
|
|
77
|
+
export type ShikiLanguages = Record<string, ShikiLanguageSource>
|
|
78
|
+
|
|
54
79
|
export interface ThemeConfig {
|
|
55
80
|
highlighterTheme?: {
|
|
56
81
|
light?: any
|
|
57
82
|
dark?: any
|
|
58
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* TextMate grammars for languages that Shiki does not bundle.
|
|
86
|
+
* Keys are the ids passed as `LanguageConfig.highlighter` or `OACodeBlock` `lang`.
|
|
87
|
+
*/
|
|
88
|
+
shikiLanguages?: ShikiLanguages
|
|
59
89
|
}
|
|
60
90
|
|
|
61
91
|
export interface PathConfig {
|
|
@@ -512,6 +542,10 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
512
542
|
setHighlighterTheme(config.theme.highlighterTheme)
|
|
513
543
|
}
|
|
514
544
|
|
|
545
|
+
if (config.theme?.shikiLanguages) {
|
|
546
|
+
setShikiLanguages(config.theme.shikiLanguages)
|
|
547
|
+
}
|
|
548
|
+
|
|
515
549
|
// Path
|
|
516
550
|
if (config.path?.showBaseURL !== undefined) {
|
|
517
551
|
ensureRefProperty(themeConfig, 'path', 'showBaseURL', config.path.showBaseURL)
|
|
@@ -634,6 +668,9 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
634
668
|
|
|
635
669
|
function reset() {
|
|
636
670
|
setConfig(defaultValues)
|
|
671
|
+
if (themeConfig.theme) {
|
|
672
|
+
themeConfig.theme.shikiLanguages = {}
|
|
673
|
+
}
|
|
637
674
|
}
|
|
638
675
|
|
|
639
676
|
function getState() {
|
|
@@ -665,6 +702,22 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
665
702
|
}
|
|
666
703
|
}
|
|
667
704
|
|
|
705
|
+
function getShikiLanguages(): ShikiLanguages {
|
|
706
|
+
return themeConfig.theme?.shikiLanguages ?? {}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
function getShikiLanguage(lang: string): ShikiLanguageSource | undefined {
|
|
710
|
+
return themeConfig.theme?.shikiLanguages?.[lang]
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function setShikiLanguages(languages: ShikiLanguages) {
|
|
714
|
+
const theme = ensureNestedProperty(themeConfig, 'theme')
|
|
715
|
+
theme.shikiLanguages = {
|
|
716
|
+
...theme.shikiLanguages,
|
|
717
|
+
...languages,
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
668
721
|
function getRequestBodyDefaultView(): BodyViewType | undefined {
|
|
669
722
|
return themeConfig?.requestBody?.defaultView?.value
|
|
670
723
|
}
|
|
@@ -1120,6 +1173,10 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
1120
1173
|
getLocale,
|
|
1121
1174
|
setLocale,
|
|
1122
1175
|
getHighlighterTheme,
|
|
1176
|
+
setHighlighterTheme,
|
|
1177
|
+
getShikiLanguages,
|
|
1178
|
+
getShikiLanguage,
|
|
1179
|
+
setShikiLanguages,
|
|
1123
1180
|
/** @deprecated Use `getRequestBodyDefaultView` instead. */
|
|
1124
1181
|
getSchemaDefaultView: getRequestBodyDefaultView,
|
|
1125
1182
|
getRequestBodyDefaultView,
|
|
@@ -27,7 +27,7 @@ export function resolveRefSync(schema: JSONSchema, ref: string): unknown {
|
|
|
27
27
|
|
|
28
28
|
// The ref is a JSON pointer, so walk through the path segments to find the
|
|
29
29
|
// referenced node in the schema. The leading "#" is removed by splitting.
|
|
30
|
-
const path = ref.split('/').slice(1)
|
|
30
|
+
const path = ref.split('/').slice(1).map(unescapePointerSegment)
|
|
31
31
|
|
|
32
32
|
let current: any = schema
|
|
33
33
|
// Walk segment by segment until we either reach the target or hit a dead end
|
|
@@ -44,6 +44,15 @@ export function resolveRefSync(schema: JSONSchema, ref: string): unknown {
|
|
|
44
44
|
return current
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// RFC 6901: a URI-fragment JSON pointer is percent-encoded, with `~1` for `/` and `~0` for `~`.
|
|
48
|
+
function unescapePointerSegment(segment: string): string {
|
|
49
|
+
try {
|
|
50
|
+
segment = decodeURIComponent(segment)
|
|
51
|
+
}
|
|
52
|
+
catch {}
|
|
53
|
+
return segment.replace(/~1/g, '/').replace(/~0/g, '~')
|
|
54
|
+
}
|
|
55
|
+
|
|
47
56
|
// Lightweight deep clone based on https://github.com/lukeed/klona, License - MIT;
|
|
48
57
|
// implementation from the @trojs/openapi-dereference https://trojs.org/, License - MIT.
|
|
49
58
|
export function klona(val: any): any {
|
|
@@ -129,17 +138,19 @@ export function dereferenceWithAnnotationsSync(schema: JSONSchema): JSONSchema {
|
|
|
129
138
|
return cache.get(schema) as JSONSchema
|
|
130
139
|
}
|
|
131
140
|
|
|
132
|
-
|
|
141
|
+
// Node -> what it resolved to. A `$ref` node reached again (e.g. a shared parameter
|
|
142
|
+
// cloned for a second operation) must yield its resolved value, not the raw `$ref`.
|
|
143
|
+
const resolvedNodes = new Map<any, any>()
|
|
133
144
|
const cloned = klona(schema)
|
|
134
145
|
markOrigins(cloned)
|
|
135
146
|
|
|
136
147
|
const resolve = (current: any): any => {
|
|
137
148
|
if (typeof current === 'object' && current !== null) {
|
|
138
149
|
// Don't process the same object twice to prevent infinite recursion on circular structures
|
|
139
|
-
if (
|
|
140
|
-
return current
|
|
150
|
+
if (resolvedNodes.has(current)) {
|
|
151
|
+
return resolvedNodes.get(current)
|
|
141
152
|
}
|
|
142
|
-
|
|
153
|
+
resolvedNodes.set(current, current)
|
|
143
154
|
|
|
144
155
|
if (Array.isArray(current)) {
|
|
145
156
|
// Recurse into array items
|
|
@@ -154,6 +165,11 @@ export function dereferenceWithAnnotationsSync(schema: JSONSchema): JSONSchema {
|
|
|
154
165
|
ref = resolveRefSync(cloned, ref.$ref)
|
|
155
166
|
} while (ref?.$ref)
|
|
156
167
|
|
|
168
|
+
// Leave unresolvable refs in place instead of aborting the whole dereference.
|
|
169
|
+
if (ref == null) {
|
|
170
|
+
return current
|
|
171
|
+
}
|
|
172
|
+
|
|
157
173
|
// Clone the referenced object so that adding annotations doesn't mutate the cache
|
|
158
174
|
// and keep track of where it originated from
|
|
159
175
|
ref = cloneWithOrigins(ref)
|
|
@@ -165,6 +181,7 @@ export function dereferenceWithAnnotationsSync(schema: JSONSchema): JSONSchema {
|
|
|
165
181
|
ref[key] = current[key]
|
|
166
182
|
}
|
|
167
183
|
}
|
|
184
|
+
resolvedNodes.set(current, ref)
|
|
168
185
|
return ref
|
|
169
186
|
}
|
|
170
187
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ParsedContent, ParsedOpenAPI, ParsedOperation } from '../../types'
|
|
2
2
|
import { httpVerbs } from '../../index'
|
|
3
3
|
import { getSchemaExample } from '../examples/getSchemaExample'
|
|
4
|
-
import { getSchemaUi } from './getSchemaUi'
|
|
4
|
+
import { getSchemaUi, SchemaUiCache } from './getSchemaUi'
|
|
5
5
|
|
|
6
|
-
export function generateRequestBodyUi(spec: ParsedOpenAPI): ParsedOpenAPI {
|
|
6
|
+
export function generateRequestBodyUi(spec: ParsedOpenAPI, cache = new SchemaUiCache()): ParsedOpenAPI {
|
|
7
7
|
if (!spec.paths) {
|
|
8
8
|
return spec
|
|
9
9
|
}
|
|
@@ -27,7 +27,7 @@ export function generateRequestBodyUi(spec: ParsedOpenAPI): ParsedOpenAPI {
|
|
|
27
27
|
continue
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
parsedContent.ui = getSchemaUi(parsedContent.schema)
|
|
30
|
+
parsedContent.ui = getSchemaUi(parsedContent.schema, cache)
|
|
31
31
|
parsedContent.examples = {
|
|
32
32
|
...(parsedContent.examples || {}),
|
|
33
33
|
...getSchemaExample(contentType, parsedContent.ui, true),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ParsedContent, ParsedOpenAPI, ParsedOperation } from '../../types'
|
|
2
2
|
import { httpVerbs } from '../../index'
|
|
3
3
|
import { getSchemaExample } from '../examples/getSchemaExample'
|
|
4
|
-
import { getSchemaUi } from './getSchemaUi'
|
|
4
|
+
import { getSchemaUi, SchemaUiCache } from './getSchemaUi'
|
|
5
5
|
|
|
6
|
-
export function generateResponseUi(spec: ParsedOpenAPI): ParsedOpenAPI {
|
|
6
|
+
export function generateResponseUi(spec: ParsedOpenAPI, cache = new SchemaUiCache()): ParsedOpenAPI {
|
|
7
7
|
if (!spec.paths) {
|
|
8
8
|
return spec
|
|
9
9
|
}
|
|
@@ -28,7 +28,7 @@ export function generateResponseUi(spec: ParsedOpenAPI): ParsedOpenAPI {
|
|
|
28
28
|
continue
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
parsedContent.ui = getSchemaUi(parsedContent.schema)
|
|
31
|
+
parsedContent.ui = getSchemaUi(parsedContent.schema, cache)
|
|
32
32
|
parsedContent.examples = {
|
|
33
33
|
...(parsedContent.examples || {}),
|
|
34
34
|
...getSchemaExample(contentType, parsedContent.ui, true),
|