@redocly/openapi-docs 3.23.0-next.6 → 3.23.0-next.7

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.
@@ -1 +1 @@
1
- import{IS_BROWSER as E,isObject as R,isString as B,isUndefined as s}from"@redocly/theme/core/openapi";import{tryDecodeURIComponent as W,getDefinitionName as I}from"../utils/index.js";import{JsonPointer as g}from"../utils/JsonPointer.js";import{normalizeOptions as z}from"./config-options/normalizeOptions.js";function w(m,e){return e&&m[m.length-1]!==e?[...m,e]:m}function $(m,e){return e?m.concat(e):m}class _{options;definitionUrl;definition;allowMergeRefs=!1;constructor(e,t,f=z({})){this.options=f,this.definition=Object.assign({},e),this.validate(e),this.definition=e,this.allowMergeRefs=e.openapi.startsWith("3.1");const n=E?window.location.href:"";B(t)&&(this.definitionUrl=new URL(t,n).href)}validate(e){if(s(e.openapi))throw new Error("Document must be valid OpenAPI 3.0.0 definition")}byRef=e=>{let t;if(this.definition){e.charAt(0)!=="#"&&(e="#"+e),e=W(e);try{t=g.get(this.definition,e)}catch{}return t||{}}};isRef(e){return e?(e=e,e.$ref!==void 0&&e.$ref!==null):!1}deref(e,t=[],f=!1,n=0){const i=e?.["x-refsStack"];if(t=$(t,i),n>5)return{resolved:Object.assign({},e,{"x-complex":!0}),refsStack:t};if(this.isRef(e)){const r=I(e.$ref);if(r&&this.options.ignoreNamedSchemas.has(r))return{resolved:{type:"object",title:r},refsStack:t};let o=this.byRef(e.$ref);if(!o)throw new Error(`Failed to resolve $ref "${e.$ref}"`);return t.includes(e.$ref)?o=Object.assign({},o,{"x-circular-ref":!0}):this.isRef(o)&&(o=this.deref(o,t,f,n).resolved),this.allowMergeRefs&&(o=this.mergeRefs(e,o,f)),{resolved:o,refsStack:w(t,e.$ref)}}return{resolved:e,refsStack:$(t,i)}}mergeRefs(e,t,f){const{$ref:n,...i}=e,r=Object.keys(i);if(r.length===0)return t;if(f&&r.some(o=>!["description","title","externalDocs","x-refsStack","x-parentRefs","readOnly","writeOnly","x-complex"].includes(o))){const{description:o,title:u,readOnly:y,writeOnly:a,...O}=i;return{allOf:[{description:o,title:u,readOnly:y,writeOnly:a},t,O]}}else return{...t,...i}}mergeAllOf(e,t,f,n="",i=0){if(e["x-circular-ref"])return e;if(e=this.hoistOneOfs(e),e.allOf===void 0)return{absolutePointer:n,...e};let r={...e,"x-parentRefs":[],absolutePointer:g.join(n,["allOf"]),allOf:void 0,title:i===0?e.title||I(t):e.title};!s(r.properties)&&R(r.properties)&&(r.properties={...r.properties}),!s(r.items)&&R(r.items)&&(r.items={...r.items});const o=e.allOf.map((u,y)=>{const{resolved:a,refsStack:O}=this.deref(u,f,!0,i),c=u.$ref,p=c||g.join(n,[String(y)]);if(a["x-complex"])return{$ref:c,refsStack:w(O,c),schema:{"x-complex":!0},absolutePointer:p};const d=this.mergeAllOf(a,c,O,p,i+1);if(!(d["x-circular-ref"]&&d.allOf))return c&&r["x-parentRefs"]?.push(...d["x-parentRefs"]||[],c),{$ref:c,refsStack:w(O,c),schema:d,absolutePointer:p}}).filter(Boolean);for(const[u,{$ref:y,schema:a,refsStack:O,absolutePointer:c}]of o.entries()){const{type:p,enum:d,properties:h,items:D,required:k,title:S,description:C,readOnly:M,writeOnly:N,oneOf:P,anyOf:v,"x-circular-ref":A,"x-complex":b,...U}=a||{};if(!(r.type!==p&&!s(r.type)&&!s(p)&&!i)){if(s(p)||(Array.isArray(p)&&Array.isArray(r.type)?r.type=[...p,...r.type]:r.type=p),s(d)||(Array.isArray(d)&&Array.isArray(r.enum)?r.enum=Array.from(new Set([...d,...r.enum])):r.enum=d),!s(h)&&R(h)){r.properties=r.properties||{};for(const l in h){const x=$(O,h[l]?.["x-refsStack"]);if(!r.properties[l])r.properties[l]={...h[l],absolutePointer:g.join(c,["properties",l]),"x-refsStack":x};else if(!A){const q=this.mergeAllOf({allOf:[r.properties[l],h[l]],"x-refsStack":x},t+"/properties/"+l,x,g.join(c,["allOf",String(u),"properties",l]),i+1);r.properties[l]=q}}}if(!s(D)&&!A&&!b){const l=typeof r.items=="boolean"?{}:Object.assign({},r.items),x=typeof a.items=="boolean"?{}:Object.assign({},a.items);r.items=this.mergeAllOf({allOf:[l,x]},t+"/items",O,"",i+1)}s(P)||(r.oneOf=P),s(v)||(r.anyOf=v),Array.isArray(k)&&(r.required=[...r.required||[],...k]),r={...r,title:e.title||(y&&S?S:r.title||S),description:r.description||C,readOnly:s(r.readOnly)?M:r.readOnly,writeOnly:s(r.writeOnly)?N:r.writeOnly,"x-circular-ref":r["x-circular-ref"]||A,"x-complex":r["x-complex"]||b,...U}}}return r}findDerived(e){const t={},f=this.definition.components&&this.definition.components.schemas||{};for(const n in f){const{resolved:i}=this.deref(f[n]);!s(i.allOf)&&i.allOf.find(r=>!s(r.$ref)&&e.indexOf(r.$ref)>-1)&&(t["#/components/schemas/"+n]=[i["x-discriminator-value"]||n])}return t}hoistOneOfs(e){if(s(e.allOf))return e;const{allOf:t,...f}=e;for(let n=0;n<t.length;n++){const{oneOf:i,...r}=t[n];if(i&&Array.isArray(i)&&s(r.discriminator)&&s(r["x-discriminator"])){const o=t.slice(0,n),u=t.slice(n+1),y=Object.keys(r).length>0?[r]:[];return{...f,oneOf:i.map(a=>({allOf:[...o,...y,a,...u]}))}}}return e}}export{_ as OpenAPIParser,$ as concatRefStacks,w as pushRef};
1
+ import{IS_BROWSER as E,isObject as w,isString as B,isUndefined as i}from"@redocly/theme/core/openapi";import{tryDecodeURIComponent as W,getDefinitionName as I}from"../utils/index.js";import{JsonPointer as g}from"../utils/JsonPointer.js";import{normalizeOptions as z}from"./config-options/normalizeOptions.js";function R(O,e){return e&&O[O.length-1]!==e?[...O,e]:O}function $(O,e){return e?O.concat(e):O}class _{options;definitionUrl;definition;allowMergeRefs=!1;constructor(e,t,l=z({})){this.options=l,this.definition=Object.assign({},e),this.validate(e),this.definition=e,this.allowMergeRefs=e.openapi.startsWith("3.1");const s=E?window.location.href:"";B(t)&&(this.definitionUrl=new URL(t,s).href)}validate(e){if(i(e.openapi))throw new Error("Document must be valid OpenAPI 3.0.0 definition")}byRef=e=>{let t;if(this.definition){e.charAt(0)!=="#"&&(e="#"+e),e=W(e);try{t=g.get(this.definition,e)}catch{}return t||{}}};isRef(e){return e?(e=e,e.$ref!==void 0&&e.$ref!==null):!1}deref(e,t=[],l=!1,s=0){const n=e?.["x-refsStack"];if(t=$(t,n),s>5)return{resolved:Object.assign({},e,{"x-complex":!0}),refsStack:t};if(this.isRef(e)){const r=I(e.$ref);if(r&&this.options.ignoreNamedSchemas.has(r))return{resolved:{type:"object",title:r},refsStack:t};let f=this.byRef(e.$ref);if(!f)throw new Error(`Failed to resolve $ref "${e.$ref}"`);return t.includes(e.$ref)?f=Object.assign({},f,{"x-circular-ref":!0}):this.isRef(f)&&(f=this.deref(f,t,l,s).resolved),this.allowMergeRefs&&(f=this.mergeRefs(e,f,l)),{resolved:f,refsStack:R(t,e.$ref)}}return{resolved:e,refsStack:$(t,n)}}mergeRefs(e,t,l){const{$ref:s,...n}=e,r=Object.keys(n);if(r.length===0)return t;if(l&&r.some(f=>!["description","title","externalDocs","x-refsStack","x-parentRefs","readOnly","writeOnly","x-complex"].includes(f))){const{description:f,title:d,readOnly:h,writeOnly:o,...y}=n;return{allOf:[{description:f,title:d,readOnly:h,writeOnly:o},t,y]}}else return{...t,...n}}mergeAllOf(e,t,l,s="",n=0){if(e["x-circular-ref"])return e;if(e=this.hoistOneOfs(e),e.allOf===void 0)return{absolutePointer:s,...e};let r={...e,"x-parentRefs":[],absolutePointer:g.join(s,["allOf"]),allOf:void 0,title:n===0?e.title||I(t):e.title};!i(r.properties)&&w(r.properties)&&(r.properties={...r.properties}),!i(r.items)&&w(r.items)&&(r.items={...r.items});const f=e.allOf.map((d,h)=>{const{resolved:o,refsStack:y}=this.deref(d,l,!0,n),p=d.$ref,u=p||g.join(s,[String(h)]);if(o["x-complex"]){const c={"x-complex":!0};return i(o.readOnly)||(c.readOnly=o.readOnly),i(o.writeOnly)||(c.writeOnly=o.writeOnly),i(o.title)||(c.title=o.title),i(o.description)||(c.description=o.description),{$ref:p,refsStack:R(y,p),schema:c,absolutePointer:u}}const m=this.mergeAllOf(o,p,y,u,n+1);if(!(m["x-circular-ref"]&&m.allOf))return p&&r["x-parentRefs"]?.push(...m["x-parentRefs"]||[],p),{$ref:p,refsStack:R(y,p),schema:m,absolutePointer:u}}).filter(Boolean);for(const[d,{$ref:h,schema:o,refsStack:y,absolutePointer:p}]of f.entries()){const{type:u,enum:m,properties:c,items:D,required:k,title:S,description:C,readOnly:M,writeOnly:N,oneOf:P,anyOf:v,"x-circular-ref":A,"x-complex":b,...U}=o||{};if(!(r.type!==u&&!i(r.type)&&!i(u)&&!n)){if(i(u)||(Array.isArray(u)&&Array.isArray(r.type)?r.type=[...u,...r.type]:r.type=u),i(m)||(Array.isArray(m)&&Array.isArray(r.enum)?r.enum=Array.from(new Set([...m,...r.enum])):r.enum=m),!i(c)&&w(c)){r.properties=r.properties||{};for(const a in c){const x=$(y,c[a]?.["x-refsStack"]);if(!r.properties[a])r.properties[a]={...c[a],absolutePointer:g.join(p,["properties",a]),"x-refsStack":x};else if(!A){const q=this.mergeAllOf({allOf:[r.properties[a],c[a]],"x-refsStack":x},t+"/properties/"+a,x,g.join(p,["allOf",String(d),"properties",a]),n+1);r.properties[a]=q}}}if(!i(D)&&!A&&!b){const a=typeof r.items=="boolean"?{}:Object.assign({},r.items),x=typeof o.items=="boolean"?{}:Object.assign({},o.items);r.items=this.mergeAllOf({allOf:[a,x]},t+"/items",y,"",n+1)}i(P)||(r.oneOf=P),i(v)||(r.anyOf=v),Array.isArray(k)&&(r.required=[...r.required||[],...k]),r={...r,title:e.title||(h&&S?S:r.title||S),description:r.description||C,readOnly:i(r.readOnly)?M:r.readOnly,writeOnly:i(r.writeOnly)?N:r.writeOnly,"x-circular-ref":r["x-circular-ref"]||A,"x-complex":r["x-complex"]||b,...U}}}return r}findDerived(e){const t={},l=this.definition.components&&this.definition.components.schemas||{};for(const s in l){const{resolved:n}=this.deref(l[s]);!i(n.allOf)&&n.allOf.find(r=>!i(r.$ref)&&e.indexOf(r.$ref)>-1)&&(t["#/components/schemas/"+s]=[n["x-discriminator-value"]||s])}return t}hoistOneOfs(e){if(i(e.allOf))return e;const{allOf:t,...l}=e;for(let s=0;s<t.length;s++){const{oneOf:n,...r}=t[s];if(n&&Array.isArray(n)&&i(r.discriminator)&&i(r["x-discriminator"])){const f=t.slice(0,s),d=t.slice(s+1),h=Object.keys(r).length>0?[r]:[];return{...l,oneOf:n.map(o=>({allOf:[...f,...h,o,...d]}))}}}return e}}export{_ as OpenAPIParser,$ as concatRefStacks,R as pushRef};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-docs",
3
- "version": "3.23.0-next.6",
3
+ "version": "3.23.0-next.7",
4
4
  "description": "Redocly OpenAPI Docs",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "@babel/core": "7.29.7",
24
24
  "@markdoc/markdoc": "0.5.2",
25
- "@redocly/openapi-core": "2.35.0",
25
+ "@redocly/openapi-core": "2.37.0",
26
26
  "deepmerge": "^4.2.2",
27
27
  "dompurify": "3.4.11",
28
28
  "fast-deep-equal": "^3.1.3",
@@ -39,9 +39,9 @@
39
39
  "url-template": "^2.0.8",
40
40
  "util": "~0.12.5",
41
41
  "web-vitals": "3.3.1",
42
- "@redocly/config": "0.49.1",
42
+ "@redocly/config": "0.50.1",
43
43
  "@redocly/redoc-opentelemetry": "0.2.2",
44
- "@redocly/replay": "0.26.0-next.6"
44
+ "@redocly/replay": "0.26.0-next.7"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@shikijs/transformers": "3.21.0",
@@ -69,9 +69,9 @@
69
69
  "tsx": "4.20.3",
70
70
  "typescript": "6.0.3",
71
71
  "url": "~0.11.0",
72
- "vite": "7.3.3",
72
+ "vite": "7.3.6",
73
73
  "vitest": "4.1.8",
74
- "@redocly/theme": "0.67.0-next.5"
74
+ "@redocly/theme": "0.67.0-next.6"
75
75
  },
76
76
  "scripts": {
77
77
  "start": "pnpm run copy-highlight-hook && vite",