@redocly/openapi-docs 3.20.0-next.7 → 3.20.0-next.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.
@@ -1 +1 @@
1
- import{IS_BROWSER as E,isObject as R,isString as B,isUndefined as o}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(o(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 s=this.byRef(e.$ref);if(!s)throw new Error(`Failed to resolve $ref "${e.$ref}"`);return t.includes(e.$ref)?s=Object.assign({},s,{"x-circular-ref":!0}):this.isRef(s)&&(s=this.deref(s,t,f,n).resolved),this.allowMergeRefs&&(s=this.mergeRefs(e,s,f)),{resolved:s,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(s=>!["description","title","externalDocs","x-refsStack","x-parentRefs","readOnly","writeOnly","x-complex"].includes(s))){const{description:s,title:u,readOnly:y,writeOnly:a,...O}=i;return{allOf:[{description:s,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};!o(r.properties)&&R(r.properties)&&(r.properties={...r.properties}),!o(r.items)&&R(r.items)&&(r.items={...r.items});const s=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 s.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&&!o(r.type)&&!o(p)&&!i)){if(o(p)||(Array.isArray(p)&&Array.isArray(r.type)?r.type=[...p,...r.type]:r.type=p),o(d)||(Array.isArray(d)&&Array.isArray(r.enum)?r.enum=Array.from(new Set([...d,...r.enum])):r.enum=d),!o(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(!o(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)}o(P)||(r.oneOf=P),o(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:o(r.readOnly)?M:r.readOnly,writeOnly:o(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]);!o(i.allOf)&&i.allOf.find(r=>!o(r.$ref)&&e.indexOf(r.$ref)>-1)&&(t["#/components/schemas/"+n]=[i["x-discriminator-value"]||n])}return t}hoistOneOfs(e){if(o(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)){const s=t.slice(0,n),u=t.slice(n+1),y=Object.keys(r).length>0?[r]:[];return{...f,oneOf:i.map(a=>({allOf:[...s,...y,a,...u]}))}}}return e}}export{_ as OpenAPIParser,$ as concatRefStacks,w as pushRef};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-docs",
3
- "version": "3.20.0-next.7",
3
+ "version": "3.20.0-next.8",
4
4
  "description": "Redocly OpenAPI Docs",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -38,9 +38,9 @@
38
38
  "url-template": "^2.0.8",
39
39
  "util": "~0.12.5",
40
40
  "web-vitals": "3.3.1",
41
- "@redocly/config": "0.47.0",
41
+ "@redocly/config": "0.48.0",
42
42
  "@redocly/redoc-opentelemetry": "0.0.8",
43
- "@redocly/replay": "0.23.0-next.5"
43
+ "@redocly/replay": "0.23.0-next.6"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@shikijs/transformers": "3.21.0",
@@ -72,7 +72,7 @@
72
72
  "url": "~0.11.0",
73
73
  "vite": "7.2.6",
74
74
  "vitest": "4.0.10",
75
- "@redocly/theme": "0.64.0-next.5"
75
+ "@redocly/theme": "0.64.0-next.6"
76
76
  },
77
77
  "scripts": {
78
78
  "start": "pnpm run copy-highlight-hook && vite",