vitepress-openapi 0.2.7 → 0.2.9
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-C0iYY931.js → angular-html-B1XELn26.js} +2 -2
- package/dist/{angular-html-DAq3gDGA.cjs → angular-html-rIG_zEfF.cjs} +1 -1
- package/dist/{angular-ts-Ct5d_gHN.js → angular-ts-DXqtm5IU.js} +2 -2
- package/dist/{angular-ts-B2PPB0Y5.cjs → angular-ts-f2TIFV5M.cjs} +1 -1
- package/dist/{apl-CiiA3JDJ.js → apl-B1OCEGWr.js} +5 -5
- package/dist/{apl-CoWANpfc.cjs → apl-Ci3ALcue.cjs} +1 -1
- package/dist/{astro-BX6R0KnA.cjs → astro-CvLdnrh3.cjs} +1 -1
- package/dist/{astro-Bzlt-IuJ.js → astro-D1h7VNXE.js} +5 -5
- package/dist/{blade-BBZCfhID.cjs → blade-Cwi6STL9.cjs} +1 -1
- package/dist/{blade-BGVF6ubL.js → blade-DhZOZtfj.js} +7 -7
- package/dist/{c-BpiaxH9s.js → c-7YqkXL9Z.js} +1 -1
- package/dist/{c-CHRY6FQk.cjs → c-C7EnZWQp.cjs} +1 -1
- package/dist/{chapel-CCUE2hqL.cjs → chapel-BnA0bPCH.cjs} +1 -1
- package/dist/{chapel-fECU7c1r.js → chapel-JTgeOnk1.js} +1 -1
- package/dist/{cobol-lxVOio4o.js → cobol-BTWAs8is.js} +2 -2
- package/dist/{cobol-Ete-w65U.cjs → cobol-CP7NwoJy.cjs} +1 -1
- package/dist/{coffee-DcVdEhV6.cjs → coffee-LJIPHo3K.cjs} +1 -1
- package/dist/{coffee-D_GP6Mp_.js → coffee-WesP7zhC.js} +1 -1
- package/dist/{cpp-BQiBH6_n.cjs → cpp-Cbp1scY6.cjs} +1 -1
- package/dist/{cpp-C2_nndOX.js → cpp-DAQpXhG0.js} +3 -3
- package/dist/{crystal-D68fQQf4.js → crystal-B4idWfGx.js} +6 -6
- package/dist/{crystal-bWCs3mcQ.cjs → crystal-ChvXSZhJ.cjs} +1 -1
- package/dist/{css-LUs62piT.cjs → css-DddeWnQl.cjs} +1 -1
- package/dist/{css-CwZ52NVY.js → css-GGKvWM3L.js} +1 -1
- package/dist/{edge-CxIBp4BJ.js → edge-CtXsoVCh.js} +3 -3
- package/dist/{edge-CRrD84FE.cjs → edge-DwK7rLUo.cjs} +1 -1
- package/dist/{elixir-txrLIPgt.cjs → elixir-Bgu3U6Wa.cjs} +1 -1
- package/dist/{elixir-DzlkeFTp.js → elixir-D83eYIIE.js} +1 -1
- package/dist/{elm-BSAvBsXU.js → elm-DpgO83wp.js} +1 -1
- package/dist/{elm-D3rgeOAI.cjs → elm-lX9Roq8z.cjs} +1 -1
- package/dist/{erb-CDFFPhk2.js → erb-BQVZ9HCP.js} +2 -2
- package/dist/{erb-CEerDw7_.cjs → erb-D4GvUbRw.cjs} +1 -1
- package/dist/{git-rebase-BRc34H8A.cjs → git-rebase-BL2dAbMZ.cjs} +1 -1
- package/dist/{git-rebase-BI3TNfL1.js → git-rebase-Rrq2ZWm2.js} +1 -1
- package/dist/{glimmer-js-BCOl9pkK.js → glimmer-js-DWVebztp.js} +4 -4
- package/dist/{glimmer-js-BjCbjAxk.cjs → glimmer-js-kdiBETU4.cjs} +1 -1
- package/dist/{glimmer-ts-BaygTMht.cjs → glimmer-ts-2i4ik6-X.cjs} +1 -1
- package/dist/{glimmer-ts-DtU3AR2J.js → glimmer-ts-BR-tSF2n.js} +4 -4
- package/dist/{glsl-C3jot75m.js → glsl-NrFCE9B3.js} +2 -2
- package/dist/{glsl-C4QVQ8IM.cjs → glsl-XEAEz2VT.cjs} +1 -1
- package/dist/{graphql-CWVurcx-.cjs → graphql-Cafwg7BL.cjs} +1 -1
- package/dist/{graphql-C57m_foI.js → graphql-L_gmMBRF.js} +5 -5
- package/dist/{hack-CO29PdAW.cjs → hack-BPeNRA1P.cjs} +1 -1
- package/dist/{hack-LG-O4iX2.js → hack-CFPozk9L.js} +2 -2
- package/dist/{haml-Qqt96dA3.js → haml-Dnt1of6J.js} +3 -3
- package/dist/{haml-D5udMhEZ.cjs → haml-kHWYo3MO.cjs} +1 -1
- package/dist/{handlebars-dotklBKW.cjs → handlebars-Cp6KipX3.cjs} +1 -1
- package/dist/{handlebars-BBft0uRg.js → handlebars-DzeI5biV.js} +4 -4
- package/dist/{html-Cm4eMgz9.js → html-CD7xOHw5.js} +3 -3
- package/dist/{html-hrBEmwSv.cjs → html-DlNGDfk2.cjs} +1 -1
- package/dist/{html-derivative-Cu6O2gHN.cjs → html-derivative-CFtmvvi-.cjs} +1 -1
- package/dist/{html-derivative-DMWaumzq.js → html-derivative-Cb94qT-w.js} +1 -1
- package/dist/{http-D168KNW_.cjs → http-DSs5YpUC.cjs} +1 -1
- package/dist/{http-Cz6VY5Wo.js → http-TK3fYlls.js} +4 -4
- package/dist/{hurl-D36azgIj.js → hurl-BfEx9X4Q.js} +2 -2
- package/dist/{hurl-DSwY6Z5G.cjs → hurl-wYovbyGz.cjs} +1 -1
- package/dist/{java-CFiC7SeI.cjs → java-7h-cze_O.cjs} +1 -1
- package/dist/{java-BKXCRk8D.js → java-Cg0ETIHg.js} +1 -1
- package/dist/{javascript-Bx9N9g1f.cjs → javascript-BNQL6umw.cjs} +1 -1
- package/dist/{javascript-DljrdC8t.js → javascript-BzzJDFzo.js} +1 -1
- package/dist/{jinja-NZUdcntO.js → jinja-IbZE90jR.js} +1 -1
- package/dist/{jinja-f05HaP8v.cjs → jinja-Oa5J7fUC.cjs} +1 -1
- package/dist/{jison-BQnZ1V4P.js → jison-BSBE0rWh.js} +1 -1
- package/dist/{jison-Dlb0RIZ3.cjs → jison-BSMwaMLb.cjs} +1 -1
- package/dist/{json-CzaEM6zR.cjs → json-De9V2v7R.cjs} +1 -1
- package/dist/{json-DyprfpNy.js → json-KEsWV5Ng.js} +1 -1
- package/dist/{jsx-X5IYTTmR.cjs → jsx-BSapmhxJ.cjs} +1 -1
- package/dist/{jsx-DoPFZPXc.js → jsx-CeAAZrLd.js} +1 -1
- package/dist/{julia-DrSudrKE.js → julia-BZFATeHL.js} +4 -4
- package/dist/{julia-BUcVnjBf.cjs → julia-xcZKc5Ew.cjs} +1 -1
- package/dist/{just-tTSTWYrq.js → just-CMG_0Fcq.js} +5 -5
- package/dist/{just-DydEbCQZ.cjs → just-D18H_x3N.cjs} +1 -1
- package/dist/{latex-BUsA-DrV.js → latex-CV2tVWCk.js} +1 -1
- package/dist/{latex-BQA9tWbc.cjs → latex-CtVwg9F3.cjs} +1 -1
- package/dist/{liquid-cWkPgL2I.js → liquid-CGMhEsSb.js} +4 -4
- package/dist/{liquid-DkgygF2N.cjs → liquid-Dp13YYeR.cjs} +1 -1
- package/dist/{lua-C6iAvpwo.js → lua-AaCey3qg.js} +2 -2
- package/dist/{lua-DIfY63me.cjs → lua-Ch_W9mH8.cjs} +1 -1
- package/dist/{marko-Du_QgmTX.cjs → marko-C5qkRYFl.cjs} +1 -1
- package/dist/{marko-CNIbHKC5.js → marko-CBVMpjgt.js} +3 -3
- package/dist/{mdc-DJo1F4gz.js → mdc-BDRDuMS7.js} +2 -2
- package/dist/{mdc-C_TsMRBC.cjs → mdc-BMY__-lv.cjs} +1 -1
- package/dist/{nginx-CwCNXVm0.js → nginx-CtvX9zIL.js} +1 -1
- package/dist/{nginx-B4IJHacq.cjs → nginx-D85LWKUU.cjs} +1 -1
- package/dist/{nim-vPNRZtmW.js → nim-BlruIwKi.js} +6 -6
- package/dist/{nim-rz8U_2RE.cjs → nim-CyM3gSu_.cjs} +1 -1
- package/dist/{org-BXPZpMn-.js → org-8WaPnqtv.js} +26 -26
- package/dist/{org-BJUQuLxI.cjs → org-BCFMP1HF.cjs} +1 -1
- package/dist/{perl-C4EazcOb.js → perl-CAdQB2tx.js} +5 -5
- package/dist/{perl-CmADOgcQ.cjs → perl-DkYI6GA4.cjs} +1 -1
- package/dist/{php-BDdD_YcH.cjs → php-CCrUGZVW.cjs} +1 -1
- package/dist/{php-BsJ_ZqPP.js → php-_x3_l_UU.js} +6 -6
- package/dist/{pug-BqCAm08K.cjs → pug-DzKmLctf.cjs} +1 -1
- package/dist/{pug-BYXwQyBY.js → pug-hly27XLj.js} +3 -3
- package/dist/{qml-BkLbkVNV.cjs → qml-D-XitYWS.cjs} +1 -1
- package/dist/{qml-CnP9LpPo.js → qml-D_bIW4fQ.js} +1 -1
- package/dist/{r-Crbt2ian.cjs → r-C0mb1qAW.cjs} +1 -1
- package/dist/{r-BskJ0B3b.js → r-Crtx_Rj8.js} +1 -1
- package/dist/{razor-CgobKwDB.js → razor-CNmNW5in.js} +1 -1
- package/dist/{razor-CcOw1mzY.cjs → razor-DW4mGGX9.cjs} +1 -1
- package/dist/{regexp-35oNQcei.js → regexp-CVT3nhGv.js} +1 -1
- package/dist/{regexp-CiRKg-B7.cjs → regexp-DXSU4ubT.cjs} +1 -1
- package/dist/{rst-0CCQrjRR.cjs → rst-B5KTR2vb.cjs} +1 -1
- package/dist/{rst-CcG1VyHf.js → rst-BhA6XXbN.js} +6 -6
- package/dist/{ruby-D84T3HVs.js → ruby-CEbJCOQJ.js} +12 -12
- package/dist/{ruby-Bz7pH067.cjs → ruby-CUw63IwB.cjs} +1 -1
- package/dist/{sas-CfNVA6xj.cjs → sas-6_2bmt_p.cjs} +1 -1
- package/dist/{sas-leffZV-t.js → sas-UnkqfIql.js} +1 -1
- package/dist/{scss-tjluFEfq.cjs → scss-Cj6kiN3V.cjs} +1 -1
- package/dist/{scss-ConKgv_x.js → scss-CtC0Ahui.js} +2 -2
- package/dist/{shellscript-CZORtZ0m.cjs → shellscript-B77I5Ggp.cjs} +1 -1
- package/dist/{shellscript-Cqrf74-d.js → shellscript-DuIgASGN.js} +1 -1
- package/dist/{shellsession-C7TZqfBX.cjs → shellsession-BI9ZpV8b.cjs} +1 -1
- package/dist/{shellsession-DGN6o4H4.js → shellsession-DmtSuVxo.js} +1 -1
- package/dist/{soy-C3C1N4BB.js → soy-CrunrCzs.js} +1 -1
- package/dist/{soy-CYwevEyV.cjs → soy-iSOjWcJx.cjs} +1 -1
- package/dist/{sql-D28Ep8kC.js → sql-Cde1eu3c.js} +1 -1
- package/dist/{sql-CKAdltev.cjs → sql-CyoUs2h4.cjs} +1 -1
- package/dist/{stata-gwURYib4.cjs → stata-ChVO1eIY.cjs} +1 -1
- package/dist/{stata-BdKZ3Tfa.js → stata-SoHdZt6f.js} +1 -1
- package/dist/{surrealql-CBAekr00.cjs → surrealql-AyXmOtPo.cjs} +1 -1
- package/dist/{surrealql-BE3WUki2.js → surrealql-Bwe12AZT.js} +1 -1
- package/dist/{svelte-BIf-Q33W.js → svelte-5ylhl1aX.js} +3 -3
- package/dist/{svelte-ClXPqtyX.cjs → svelte-6qBNWwQn.cjs} +1 -1
- package/dist/{templ-CJJCQFkp.cjs → templ-DQeUexgT.cjs} +1 -1
- package/dist/{templ-KcJQzTCJ.js → templ-DZ18fL-0.js} +2 -2
- package/dist/{tex-DtiwEWZU.js → tex-Bu4Cft9y.js} +2 -2
- package/dist/{tex-V7tXlPyb.cjs → tex-grxyCd6F.cjs} +1 -1
- package/dist/{ts-tags-gxidxB8R.js → ts-tags-ChoZiVav.js} +7 -7
- package/dist/{ts-tags-BaSrqEU0.cjs → ts-tags-DWyJqpzh.cjs} +1 -1
- package/dist/{tsx-CLVkAc-4.js → tsx-BVZRMVCS.js} +1 -1
- package/dist/{tsx-yCIscrGd.cjs → tsx-D8K0BrmX.cjs} +1 -1
- package/dist/{twig-DucNk_L2.cjs → twig-CzsEUGpk.cjs} +1 -1
- package/dist/{twig-BozPiA4G.js → twig-qC2X1Ju8.js} +5 -5
- package/dist/types/src/components/Common/OAJSONEditor.vue.d.ts +2 -2
- 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/{typescript-v3MDZy3z.js → typescript-BnzWnec5.js} +1 -1
- package/dist/{typescript-CpL8J23X.cjs → typescript-DJ3zklOW.cjs} +1 -1
- package/dist/{typst-KAYwLgnz.cjs → typst-5ZpLDH4k.cjs} +1 -1
- package/dist/{typst-BqVfAgGz.js → typst-Bw8BzyoB.js} +29 -29
- package/dist/{useOpenapi-_Y6U0hd9.cjs → useOpenapi-CfKOQmG7.cjs} +77 -77
- package/dist/{useOpenapi-B8TP2xUt.js → useOpenapi-vxhinHuF.js} +1538 -1451
- package/dist/vitepress-openapi.client.cjs.js +4 -4
- package/dist/vitepress-openapi.client.es.js +9044 -9040
- package/dist/vitepress-openapi.node.cjs.js +1 -1
- package/dist/vitepress-openapi.node.es.js +1 -1
- package/dist/{vue-DDP4ToP4.cjs → vue-BPajHkJ2.cjs} +1 -1
- package/dist/{vue-CCBnDBrj.js → vue-DwyDZ4RX.js} +6 -6
- package/dist/{vue-html-ChckxjrF.js → vue-html-Cj4_bNem.js} +1 -1
- package/dist/{vue-html-pUsOdCRA.cjs → vue-html-pQ4URscA.cjs} +1 -1
- package/dist/{vue-vine-CW6_oew-.js → vue-vine-0CAFnvXq.js} +3 -3
- package/dist/{vue-vine-C-R1ePqA.cjs → vue-vine-BxsDBvMs.cjs} +1 -1
- package/dist/{xml-5oO_YDXi.cjs → xml-CqFmiD9z.cjs} +1 -1
- package/dist/{xml-BjuxZasO.js → xml-PSx8kIzM.js} +2 -2
- package/dist/{xsl-A-O9TTaY.js → xsl-BJXJ9U2q.js} +1 -1
- package/dist/{xsl-BfGzl8_E.cjs → xsl-BsFSS-SN.cjs} +1 -1
- package/dist/{yaml-CFG4vyir.cjs → yaml-BOcaVyO_.cjs} +1 -1
- package/dist/{yaml-DgRJBItn.js → yaml-BsVfajRZ.js} +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/lib/examples/getSchemaUiJson.ts +118 -13
- 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/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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
|
154
|
+
return this.createUnionProperty(oneOfProperties, 'oneOf', name, baseSchema, required)
|
|
145
155
|
}
|
|
146
156
|
|
|
147
|
-
|
|
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
|
|
163
|
+
return this.createUnionProperty(anyOfProperties, 'anyOf', name, baseSchema, required)
|
|
154
164
|
}
|
|
155
165
|
|
|
156
|
-
|
|
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
|
|
199
|
+
return this.createOneOfProperty(schema.oneOf, name, schema, required)
|
|
175
200
|
}
|
|
176
201
|
|
|
177
202
|
if (schema.anyOf) {
|
|
178
|
-
return
|
|
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
|
-
?
|
|
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
|
-
...
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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(
|
|
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 =
|
|
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(
|
|
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(() =>
|
|
82
|
-
transformSync({
|
|
82
|
+
const [mergedSpec, errMerge] = $trycatch(() => {
|
|
83
|
+
const transformed = transformSync({
|
|
83
84
|
spec,
|
|
84
85
|
defaultTag,
|
|
85
86
|
defaultTagDescription,
|
|
86
|
-
})
|
|
87
|
-
|
|
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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
|
33
|
+
const origin = (value as any)[originSymbol] ?? value
|
|
34
|
+
const ancestor = ancestors.get(origin)
|
|
31
35
|
|
|
32
|
-
if (
|
|
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
|
-
|
|
53
|
-
|
|
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
|
-
|
|
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 {
|
|
@@ -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(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
156
|
-
if (!
|
|
138
|
+
const entry = findOperation(operationId)
|
|
139
|
+
if (!entry) {
|
|
157
140
|
return []
|
|
158
141
|
}
|
|
159
|
-
const
|
|
160
|
-
const
|
|
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
|
|
177
|
-
|
|
158
|
+
const tags = new Set<string>()
|
|
159
|
+
for (const path of Object.values(getPaths())) {
|
|
178
160
|
for (const verb of httpVerbs) {
|
|
179
|
-
|
|
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
|
-
|
|
188
|
-
|
|
163
|
+
}
|
|
164
|
+
return [...tags]
|
|
189
165
|
}
|
|
190
166
|
|
|
191
167
|
function filterPaths(predicate: (operation: any) => boolean) {
|