@redocly/api-docs 0.2.0-next.7 → 0.2.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{useContext as d,useMemo as l}from"react";import{useAtomValue as p}from"jotai";import{exampleStoreAtom as h,generatedExampleAtom as x,buildExampleAtomKey as S}from"../../jotai/examples.js";import{convertSampleToString as g}from"../../services/code-samples/index.js";import{isSequentialMediaType as A}from"../../utils/media-type.js";import{schemaStoreAtom as C}from"../../jotai/schema.js";import{buildOpenApiSectionSuffix as E,extractDeepLinkParamFromHash as L,hashIsForItem as b,hashIsInsideCallback as k,hashIsOutsideCallbacks as v,hashToElementId as I}from"../../utils/deep-link.js";import{ItemIdContext as D,useCallbackScope as P}from"../../hooks/useDeepLinkSection.js";import{useUrlHash as w}from"../../hooks/useUrlHash.js";import{routingBasePathAtom as y}from"../../jotai/store.js";import{useDeepLinkUrl as B}from"../../hooks/useDeepLinkSection.js";import{toRelativePath as F}from"../../utils/url.js";function H(e){const t=p(h);return!e||e.length===0?[]:e.map(o=>t[o]).filter(Boolean)}function N(e,t,o,n){const i=H(t),a=d(D)??"",r=n?.toLowerCase(),s=e?S(e,o,n,a):"",f=p(x(s)),u=p(C);if(i.length>0){if(r&&A(r)){const m=e?u[e]?.data:void 0;return i.map(c=>typeof c.value=="string"?c.value:g(c.value,r,m))}return i.map(m=>m.value)}return f!==void 0?[f]:[]}function Q(e,t){const o=l(()=>e?E("response",t,e):"",[e,t]);return B(o)}function W(e,t,o){const n=w(),i=p(y),a=P();return l(()=>{if(!e)return;const r=I(n),s=F(e,i).toLowerCase();if(!b(r,s)||!(a?k(r,s,a):v(r,s)))return;const u=L(n,o);if(u)return t?.find(m=>m.toLowerCase()===u)},[n,e,t,o,i,a])}export{H as useExampleEntries,W as useKeyFromHash,N as useResolvedExamples,Q as useResponseSectionDeepLink};
1
+ import{useContext as d,useMemo as l}from"react";import{useAtomValue as p}from"jotai";import{exampleStoreAtom as h,generatedExampleAtom as x,buildExampleAtomKey as S}from"../../jotai/examples.js";import{convertSampleToString as g}from"../../services/code-samples/index.js";import{isSequentialMediaType as A}from"../../utils/media-type.js";import{schemaStoreAtom as E}from"../../jotai/schema.js";import{buildOpenApiSectionSuffix as C,extractDeepLinkParamFromHash as I,hashIsForItem as L,hashIsInsideCallback as b,hashIsOutsideCallbacks as k,hashToElementId as v}from"../../utils/deep-link.js";import{ItemIdContext as D,useCallbackScope as w}from"../../hooks/useDeepLinkSection.js";import{useUrlHash as y}from"../../hooks/useUrlHash.js";import{routingBasePathAtom as B}from"../../jotai/store.js";import{useDeepLinkUrl as F}from"../../hooks/useDeepLinkSection.js";import{toElementId as H}from"../../utils/url.js";function K(e){const t=p(h);return!e||e.length===0?[]:e.map(o=>t[o]).filter(Boolean)}function N(e,t,o,n){const i=K(t),s=d(D)??"",r=n?.toLowerCase(),a=e?S(e,o,n,s):"",f=p(x(a)),u=p(E);if(i.length>0){if(r&&A(r)){const m=e?u[e]?.data:void 0;return i.map(c=>typeof c.value=="string"?c.value:g(c.value,r,m))}return i.map(m=>m.value)}return f!==void 0?[f]:[]}function Q(e,t){const o=l(()=>e?C("response",t,e):"",[e,t]);return F(o)}function W(e,t,o){const n=y(),i=p(B),s=w();return l(()=>{if(!e)return;const r=v(n),a=(H(e,i)??"").toLowerCase();if(!L(r,a)||!(s?b(r,a,s):k(r,a)))return;const u=I(n,o);if(u)return t?.find(m=>m.toLowerCase()===u)},[n,e,t,o,i,s])}export{K as useExampleEntries,W as useKeyFromHash,N as useResolvedExamples,Q as useResponseSectionDeepLink};
@@ -1,17 +1,17 @@
1
- import{jsx as o}from"react/jsx-runtime";import{memo as f,useCallback as v}from"react";import{styled as t,css as a}from"styled-components";import{Link as g}from"react-router";import{useUrlHash as k}from"../../hooks/useUrlHash.js";import{useAtomValue as u}from"jotai";import{LinkIcon as b}from"@redocly/theme/icons/LinkIcon/LinkIcon";import{ClipboardService as x}from"@redocly/theme/core/openapi";import{globalOptionsAtom as y}from"../../jotai/store.js";import{hashToElementId as l}from"../../utils/deep-link.js";function A({to:i,label:s,variant:c="heading"}){const{onDeepLinkClick:e}=u(y),p=k({trackSilentReplaces:!0}),r=i.split("#")[1],m=!!r&&l(p)===l(r),d=v(h=>{x.copyCustom(`${window.location.origin}${i}`),e&&(h.preventDefault(),e(i))},[e,i]);return o(C,{className:"deep-link-anchor","data-deep-link-anchor":!0,children:o(L,{$variant:c,to:i,"aria-label":s??`link to ${i}`,"aria-current":m?"location":void 0,onClick:d,children:o(b,{color:"--heading-anchor-color"})})})}const j=f(A),n="data-deep-link-anchor",w=`
2
- & [${n}] svg {
1
+ import{jsx as o}from"react/jsx-runtime";import{memo as f,useCallback as v}from"react";import{styled as a,css as l}from"styled-components";import{Link as g}from"react-router";import{useUrlHash as k}from"../../hooks/useUrlHash.js";import{useAtomValue as u}from"jotai";import{LinkIcon as b}from"@redocly/theme/icons/LinkIcon/LinkIcon";import{ClipboardService as x}from"@redocly/theme/core/openapi";import{globalOptionsAtom as y}from"../../jotai/store.js";import{hashToElementId as s}from"../../utils/deep-link.js";function A({to:e,label:c,variant:p="heading"}){const{onDeepLinkClick:i}=u(y),m=k({trackSilentReplaces:!0}),t=e.split("#")[1],d=!!t&&s(m)===s(t),h=v(n=>{x.copyCustom(n.currentTarget.href),i&&(n.preventDefault(),i(e))},[i,e]);return o(C,{className:"deep-link-anchor","data-deep-link-anchor":!0,children:o(L,{$variant:p,to:e,"aria-label":c??`link to ${e}`,"aria-current":d?"location":void 0,onClick:h,children:o(b,{color:"--heading-anchor-color"})})})}const j=f(A),r="data-deep-link-anchor",O=`
2
+ & [${r}] svg {
3
3
  visibility: hidden;
4
4
  }
5
- &:hover [${n}] svg,
6
- & [${n}] a:focus svg {
5
+ &:hover [${r}] svg,
6
+ & [${r}] a:focus svg {
7
7
  visibility: visible;
8
8
  }
9
- `,C=t.span`
9
+ `,C=a.span`
10
10
  position: relative;
11
11
  display: inline-flex;
12
12
  align-items: center;
13
13
  vertical-align: middle;
14
- `,L=t(g)`
14
+ `,L=a(g)`
15
15
  position: absolute;
16
16
  top: 50%;
17
17
  transform: translate(-100%, -50%);
@@ -19,9 +19,9 @@ import{jsx as o}from"react/jsx-runtime";import{memo as f,useCallback as v}from"r
19
19
  display: flex;
20
20
  align-items: center;
21
21
 
22
- ${({$variant:i})=>i==="field"?a`
22
+ ${({$variant:e})=>e==="field"?l`
23
23
  left: -2px;
24
- `:a`
24
+ `:l`
25
25
  left: 0;
26
26
  padding-right: var(--heading-anchor-offset-right, 4px);
27
27
  `}
@@ -29,4 +29,4 @@ import{jsx as o}from"react/jsx-runtime";import{memo as f,useCallback as v}from"r
29
29
  &&[aria-current] svg {
30
30
  visibility: visible;
31
31
  }
32
- `;export{n as DEEP_LINK_ANCHOR_ATTR,j as DeepLinkAnchor,w as deepLinkHoverReveal};
32
+ `;export{r as DEEP_LINK_ANCHOR_ATTR,j as DeepLinkAnchor,O as deepLinkHoverReveal};
@@ -1 +1 @@
1
- import{createContext as i,useContext as u,useMemo as c}from"react";import{useAtomValue as p}from"jotai";import{routingBasePathAtom as a}from"../jotai/store.js";import{buildDeepLinkUrl as I,buildOpenApiSectionSuffix as C,CALLBACKS_SECTION as S}from"../utils/deep-link.js";import{joinWithSeparator as h,toRelativePath as m}from"../utils/url.js";import{useNavigationUrlNormalizer as L}from"./useNormalizeUrl.js";const l=i(void 0),k=i(void 0);function D(){return u(k)}function P(){const t=u(l),e=p(a);return c(()=>t?m(t,e).toLowerCase():"",[t,e])}const U="synthetic-item:",T=i(null);function f(t,e){const o=u(l),r=D(),n=p(a),s=L();return c(()=>{if(!o||o.startsWith(U))return"";const d=n?m(o,n):o,x=e&&r?h(C(S,r),t):t;return s(I(n,d,x))},[o,r,e,n,t,s])}function _(t){return f(t,!0)}function v(t){return f(t,!1)}export{k as CallbackScopeContext,T as DeepLinkSectionContext,l as ItemIdContext,U as SYNTHETIC_ITEM_ID_PREFIX,D as useCallbackScope,_ as useDeepLinkUrl,v as useFieldDeepLinkUrl,P as useHashItemId};
1
+ import{createContext as i,useContext as u,useMemo as c}from"react";import{useAtomValue as m}from"jotai";import{routingBasePathAtom as p}from"../jotai/store.js";import{buildDeepLinkUrl as I,buildOpenApiSectionSuffix as x,CALLBACKS_SECTION as C}from"../utils/deep-link.js";import{joinWithSeparator as S,toElementId as h,toRelativePath as L}from"../utils/url.js";import{useNavigationUrlNormalizer as k}from"./useNormalizeUrl.js";const a=i(void 0),D=i(void 0);function U(){return u(D)}function T(){const t=u(a),e=m(p);return c(()=>t?(h(t,e)??"").toLowerCase():"",[t,e])}const g="synthetic-item:",_=i(null);function l(t,e){const o=u(a),r=U(),n=m(p),s=k();return c(()=>{if(!o||o.startsWith(g))return"";const f=n?L(o,n):o,d=e&&r?S(x(C,r),t):t;return s(I(n,f,d))},[o,r,e,n,t,s])}function v(t){return l(t,!0)}function z(t){return l(t,!1)}export{D as CallbackScopeContext,_ as DeepLinkSectionContext,a as ItemIdContext,g as SYNTHETIC_ITEM_ID_PREFIX,U as useCallbackScope,v as useDeepLinkUrl,z as useFieldDeepLinkUrl,T as useHashItemId};
@@ -1,7 +1,8 @@
1
1
  type Options = {
2
2
  trackSilentReplaces?: boolean;
3
3
  };
4
- /** Current `window.location.hash`. Ignores scroll-spy's silent hash clears (so
5
- * hash-driven state survives) unless `trackSilentReplaces` is set. */
4
+ /** Current URL hash. Under Redoc standalone's hash router (`#/route#deep-link`) only the
5
+ * trailing deep-link part, or `''` when the fragment holds a route alone. Ignores scroll-spy's
6
+ * silent hash clears (so hash-driven state survives) unless `trackSilentReplaces` is set. */
6
7
  export declare function useUrlHash(options?: Options): string;
7
8
  export {};
@@ -1 +1 @@
1
- import{useSyncExternalStore as r}from"react";import{URL_REPLACE_EVENT as s}from"./useRouterHashBridge.js";function o(e){return t=>{if(typeof window>"u")return()=>{};for(const n of e)window.addEventListener(n,t);return()=>{for(const n of e)window.removeEventListener(n,t)}}}const i=o(["hashchange","popstate"]),a=o(["hashchange","popstate",s]);function u(){return typeof window<"u"?window.location.hash:""}function c(){return""}function p(e){return r(e?.trackSilentReplaces?a:i,u,c)}export{p as useUrlHash};
1
+ import{useSyncExternalStore as o}from"react";import{URL_REPLACE_EVENT as s}from"./useRouterHashBridge.js";function r(e){return t=>{if(typeof window>"u")return()=>{};for(const n of e)window.addEventListener(n,t);return()=>{for(const n of e)window.removeEventListener(n,t)}}}const i=r(["hashchange","popstate"]),a=r(["hashchange","popstate",s]);function c(){if(typeof window>"u")return"";const e=window.location.hash;if(!e.startsWith("#/"))return e;const t=e.indexOf("#",1);return t===-1?"":e.slice(t)}function f(){return""}function p(e){return o(e?.trackSilentReplaces?a:i,c,f)}export{p as useUrlHash};
@@ -1 +1 @@
1
- import{REDOCLY_TEAMS_RBAC as f}from"@redocly/config";import{nodeTypes as P,contentType as S,schemaKind as E}from"../../types/common.js";import{extractFullText as y}from"../../adapters/utils/markdoc.js";import{appendArraySuffix as D,appendVariantSuffix as g,buildGraphqlSuffix as O,buildOpenApiSectionSuffix as j,makeDeepLink as I}from"../../utils/deep-link.js";const V=10,R="message payload",w="message headers",x=200;function _(k){return k.length>x?`${k.slice(0,x)}\u2026`:k}class G{#a=[];#r;#i;#s;#o;constructor(e,n,t){this.#r=e,this.#i=n,this.#s=t}addItem(e){if(!(!e.link||!e.content))try{switch(e.content.contentType){case S.OVERVIEW:this.#d(e,this.#r);break;case S.GROUP:case S.ITEM:this.#d(e,e.link);break}}catch(n){console.error(`Cannot add item to api-docs search indexer [${e.label}, ${e.link}]:`,n.message)}}#d(e,n){if(!e.content)return;const t=n.startsWith(this.#r+"/")?n.slice(this.#r.length+1):n.split("/").slice(-2).join("/"),r=e.content.children,i=this.#l(r),o=this.#y(r,t),s=e,a={id:n,url:n,title:e.label??"",text:i,path:[],deprecated:e.content.meta?.deprecated,..."httpVerb"in e&&e.httpVerb?{httpMethod:e.httpVerb}:{},..."httpPath"in e&&e.httpPath?{httpPath:e.httpPath}:{},..."badges"in e&&Array.isArray(e.badges)&&e.badges.length?{badges:e.badges}:{},..."isAdditionalOperation"in e&&e.isAdditionalOperation?{isAdditionalOperation:!0}:{},[f]:s[f],...o.length&&{parameters:o}};this.#a.push(a)}#l(e){const n=[],t=r=>{for(const i of r)if(i.nodeType===P.MARKDOC){const o=i;if(this.#h(o.content))continue;const s=y(o.content);s&&n.push(s)}else(i.nodeType===P.CONTAINER||i.nodeType===P.OVERVIEW_SECTION_WRAPPER)&&t(i.children)};return t(e),n.join(" ").trim()}#h(e){let n=!1,t=!1;const r=o=>{o.type==="code"&&o.attributes?.content?n=!0:o.type==="text"&&o.attributes?.content&&(t=!0);for(const s of o.children??[])r(s)},i=Array.isArray(e)?e:[e];for(const o of i)r(o);return n&&!t}#y(e,n){const t={},r=new Set,i=o=>{for(const s of o)if(s.nodeType===P.ITEM){const a=s;if(a[f])continue;this.#m(a,t,n),this.#S(a,t,r,n)}else if(s.nodeType===P.CONTAINER){const a=s;if(a[f])continue;i(a.children)}else s.nodeType===P.OVERVIEW_SECTION_WRAPPER&&i(s.children)};return i(e),Object.values(t)}#m(e,n,t){if(e.parameters?.length)for(const r of e.parameters){if(r[f])continue;const i=this.#g(e.variant),o=this.#k(e.variant),s=r.description?y(r.description):"",a=this.#$(r.schemaId),d={name:r.name,description:s,place:i,mediaType:void 0,type:a,required:r.required??!1,deepLink:this.#c(t,"request",o,void 0,void 0,[r.name]),example:void 0,enum:void 0};n[this.#t(d)]=d}}#t(e){return[...Array.isArray(e.path)?e.path:[],e.name.toString()].join(".")+e.description+e.place}#c(e,n,t,r,i,o){if(!e)return"";const s=o.join("/"),a=[`t=${n}`];return t&&a.push(`in=${t}`),i&&a.push(`c=${i}`),r&&a.push(`ct=${r}`),s&&a.push(`path=${s}`),`/${e}#${e}/${a.join("&")}`.toLowerCase()}#P(e,n,t,r){if(!e)return"";let i="messages";n&&(i+=`&m=${n}`),i+=`&t=${t}`;const o=r.join("/");return o&&(i+=`&path=${o}`),`/${e}#${e}/${i}`.toLowerCase()}#k(e){switch(e){case"query":return"query";case"path":return"path";case"headers":return"header";case"cookies":return"cookie";default:return}}#g(e){switch(e){case"query":return"query parameters";case"path":return"path parameters";case"headers":return"header parameters";case"cookies":return"cookie parameters";case"parameters":return"channel parameters";default:return e?`${e} parameters`:"parameters"}}#$(e){const n=this.#i?.[e];if(!n||n.kind!==E.JSON_SCHEMA)return"unknown";const t=n.data,r=this.#p(t);return this.#f(r)}#f(e){return Array.isArray(e.type)?e.type.join(" | "):e.type?e.type:e.properties||e.additionalProperties?"object":e.items?"array":e.enum?"string":"any"}#S(e,n,t,r){const i=this.#A(e);if(e.graphqlSchema&&Array.isArray(e.graphqlSchema)){this.#I(e.graphqlSchema,i,n,e,r);return}const o=!!this.#i&&!!this.#s;o&&this.#O(e,i,n,t,r);for(const s of e.responses??[])s[f]||(this.#T(s,n,r),o&&this.#b(s,n,r));if(o)for(const s of e.messages??[])s[f]||this.#q(s,n,r)}#O(e,n,t,r,i){const o=n.startsWith("response");if(e.mediaTypeSchemas){const s=Object.entries(e.mediaTypeSchemas),a=s.find(([,d])=>!d[f]);if(a){const[d,c]=a;c.schemaId&&this.#n(c.schemaId,n,d,s.length>1,o,t,[],r,i)}}else e.schemaId&&this.#n(e.schemaId,n,void 0,!1,o,t,[],r,i)}#T(e,n,t){const r=e.description?y(e.description):"",o=[e.summary?y(e.summary):"",r].filter(Boolean).join(" ").trim();if(!o)return;const s={name:e.code,description:o,place:`response ${e.code}`,mediaType:void 0,type:"unknown",required:!1,deepLink:t?I(t,j("response",void 0,e.code)):void 0,example:void 0,enum:void 0};n[this.#t(s)]=s}#b(e,n,t){const r=`response ${e.code} fields`,i=new Set;if(e.mediaTypeContent){const o=Object.entries(e.mediaTypeContent),s=o.find(([,a])=>!a[f]);if(s){const[a,d]=s;d.schemaId&&this.#n(d.schemaId,r,a,o.length>1,!0,n,[],i,t)}}else e.schemaId&&this.#n(e.schemaId,r,e.mediaType,!1,!0,n,[],i,t)}#q(e,n,t){const r=e.description?y(e.description):"",i=e.summary??"",o={name:e.name,description:(r+i).trim(),place:"message",mediaType:void 0,type:"unknown",required:!1,example:void 0,enum:void 0};n[this.#t(o)]=o,this.#o=e.name;const s=new Set;e.schemaId&&this.#n(e.schemaId,R,e.contentType,!1,!1,n,[],s,t),e.headerSchemaId&&this.#n(e.headerSchemaId,w,void 0,!1,!1,n,[],s,t),this.#o=void 0}#A(e){switch(e.variant){case"body":return"request fields";case"responses":return"response fields";case"graphql-fields":return"fields";case"graphql-args":return"arguments";case"return-type":return"return type fields";default:return e.variant??"fields"}}#E(e){return e.variant!=="graphql-args"?e.graphqlTypeName:e.graphqlFieldName?e.graphqlFieldName:e.graphqlTypeName?`@${e.graphqlTypeName}`:void 0}#I(e,n,t,r,i){const o=r.variant==="graphql-args",s=this.#E(r),a=d=>i&&s?I(i,d):void 0;for(const d of e){const c=d.description?y(d.description):"",u=`${s}.${d.name}`,l={name:d.name,description:c,place:n,mediaType:void 0,path:[],type:d.type??"unknown",required:!1,deepLink:a(o?O({t:"argument",path:u,arg:d.name}):O({t:"field",path:u})),example:void 0,enum:void 0};if(t[this.#t(l)]=l,d.args?.length)for(const p of d.args){const m=p.description?y(p.description):"",h={name:p.name,description:m,place:"arguments",mediaType:void 0,path:[d.name],type:p.type??"unknown",required:!1,deepLink:a(O({t:"argument",path:`${u}.${p.name}`,arg:p.name})),example:void 0,enum:void 0};t[this.#t(h)]=h}}}#n(e,n,t,r,i,o,s,a,d=""){const c=this.#i?.[e];if(!c||c.kind!==E.JSON_SCHEMA||c[f])return;const u=c.data,l=r?t:void 0;this.#u(u,n,t,l,i,o,{path:s,linkPath:[...s],depth:0},a,d)}#R(e){const n=e.match(/^response (\d+)/);return n?n[1]:void 0}#p(e){if(e.allOf){const n={};for(const t of e.allOf){const r=t.$ref?this.#e(t.$ref):t;if(r){const i=n.properties,o=n.required;Object.assign(n,r),(i||r.properties)&&(n.properties={...i||{},...r.properties||{}}),(o||r.required)&&(n.required=[...o||[],...r.required||[]])}}return delete n.allOf,e.description&&(n.description=e.description),n}if(e.$ref){const n=this.#e(e.$ref);if(n){const t={...n};return e.description&&(t.description=e.description),t}}return e}#e(e){if(!e.startsWith("#/"))return;const n=e.slice(2).split("/");let t=this.#s;for(const r of n){if(t==null||typeof t!="object")return;t=t[r]}return t!=null&&typeof t=="object"?t:void 0}#u(e,n,t,r,i,o,s,a,d=""){if(s.depth>V||e[f])return;const c=(p,m)=>this.#u(p,n,t,r,i,o,m,a,d);if(e.$ref){this.#w(e.$ref,c,s,a);return}if(e.allOf){c(this.#x(e,a),s);return}const u=e.discriminator??e["x-discriminator"];if(u?.propertyName&&!s.inDiscriminatorVariant){this.#W(e,u,c,s);return}const l=e.oneOf??e.anyOf;if(l){this.#C(e,l,c,s,a);return}if(e.if&&(e.then||e.else)){this.#L(e,c,s);return}e.properties&&this.#D(e,c,{place:n,mediaType:t,deepLinkContentType:r,isResponse:i,paramsMap:o,frame:s,visited:a,slug:d}),this.#v(e,c,s,a)}#w(e,n,t,r){if(r.has(e))return;r.add(e);const i=this.#e(e);i&&n(i,t)}#x(e,n){const t={};for(const r of e.allOf??[]){let i=r;if(r.$ref){if(n.has(r.$ref))continue;n.add(r.$ref),i=this.#e(r.$ref)}if(i){const o=t.properties,s=t.required;Object.assign(t,i),(o||i.properties)&&(t.properties={...o||{},...i.properties||{}}),(s||i.required)&&(t.required=[...s||[],...i.required||[]])}}return delete t.allOf,t}#C(e,n,t,r,i){e.properties&&t({...e,oneOf:void 0,anyOf:void 0},{...r,linkPath:g(r.linkPath,"&oneof=0")}),n.forEach((o,s)=>{if(o.$ref){if(i.has(o.$ref))return;i.add(o.$ref)}const a=o.$ref?this.#e(o.$ref):o;a&&t(a,{...r,linkPath:g(r.linkPath,`&oneof=${s}`),depth:r.depth+1})})}#L(e,n,t){const{if:r,then:i,else:o,...s}=e;[{allOf:[s,i??{},r??{}]},{allOf:[s,o??{}]}].forEach((d,c)=>{n(d,{...t,linkPath:g(t.linkPath,`&oneof=${c}`),depth:t.depth+1})})}#D(e,n,t){const{isResponse:r,paramsMap:i,frame:o,visited:s}=t,a=e.required||[],d=this.#R(t.place),c=r?"response":"request",u=t.place===R?"payload":t.place===w?"headers":void 0,l={requiredList:a,responseCode:d,type:c,asyncSubsection:u,...t};for(const[p,m]of Object.entries(e.properties??{})){if(m[f])continue;const h=this.#j(m,s);if(!h)continue;const C=this.#V(h,s),$=this.#p(h);if(!this.#_(h,$,r))continue;const T=p===o.discriminatorPropertyName,L=[...o.path,p],b=this.#F(p,T,o),q=this.#M(p,h,$,b,l),A=this.#t(q);i[A]==null&&(i[A]=q,!C&&!T&&n($,{path:L,linkPath:b,depth:o.depth+1}))}}#j(e,n){if(!e.$ref)return e;if(!n.has(e.$ref))return n.add(e.$ref),this.#e(e.$ref)}#V(e,n){if(!e.allOf)return!1;let t=!1;for(const r of e.allOf)r.$ref?n.has(r.$ref)||(n.add(r.$ref),t=!0):t=!0;return!t}#_(e,n,t){return!(e[f]||n[f]||n.readOnly&&!t||n.writeOnly&&t||e.additionalProperties!==void 0&&!e.properties)}#F(e,n,t){return[...n&&t.discriminatorLinkPath?t.discriminatorLinkPath:t.linkPath,e]}#M(e,n,t,r,i){const o=n.description??t.description,s=o?y(o):"",a=n.example??t.example,d=a!==void 0?_(typeof a=="string"?a:JSON.stringify(a)):void 0,c=Array.isArray(t.enum)&&t.enum.length?t.enum:void 0;return{name:e,description:s,place:i.place,mediaType:i.mediaType,path:i.frame.path,type:this.#f(t),required:i.requiredList.includes(e),deepLink:i.asyncSubsection?this.#P(i.slug,this.#o,i.asyncSubsection,r):this.#c(i.slug,i.type,void 0,i.deepLinkContentType,i.responseCode,r),example:d,enum:c}}#v(e,n,t,r){if(!e.items||typeof e.items!="object"||Array.isArray(e.items))return;if(e.items.$ref){if(r.has(e.items.$ref))return;r.add(e.items.$ref)}const i=e.items.$ref?this.#e(e.items.$ref):e.items;i&&n(i,{...t,linkPath:D(t.linkPath),depth:t.depth+1})}#W(e,n,t,r){const i=this.#G(e,n),o=s=>({...r,linkPath:g(r.linkPath,`&d=${s}`),inDiscriminatorVariant:!0,discriminatorPropertyName:n.propertyName,discriminatorLinkPath:r.linkPath});e.properties&&t({...e,discriminator:void 0,"x-discriminator":void 0,oneOf:void 0,anyOf:void 0},i.length?o(0):r),i.forEach((s,a)=>{t(s,{...o(a),depth:r.depth+1})})}#G(e,n){const t=e.oneOf??e.anyOf??[],r=Object.values(n.mapping??{});if(r.length===0)return t;const i=s=>t.find(a=>a.$ref===s||a["x-original-ref"]===s)??this.#e(s)??{},o=r.filter(s=>s!==n.defaultMapping).map(i);return n.defaultMapping&&o.push(i(n.defaultMapping)),o}getResult(){return this.#a}}export{G as ApiDocsSearchIndexer};
1
+ import{REDOCLY_TEAMS_RBAC as f}from"@redocly/config";import{nodeTypes as P,contentType as S,schemaKind as E}from"../../types/common.js";import{extractFullText as y}from"../../adapters/utils/markdoc.js";import{toElementId as D}from"../../utils/url.js";import{appendArraySuffix as j,appendVariantSuffix as $,buildGraphqlSuffix as O,buildOpenApiSectionSuffix as V,makeDeepLink as I}from"../../utils/deep-link.js";const _=10,R="message payload",w="message headers",x=200;function F(k){return k.length>x?`${k.slice(0,x)}\u2026`:k}class H{#a=[];#i;#r;#s;#o;constructor(e,n,t){this.#i=e,this.#r=n,this.#s=t}addItem(e){if(!(!e.link||!e.content))try{switch(e.content.contentType){case S.OVERVIEW:this.#d(e,this.#i);break;case S.GROUP:case S.ITEM:this.#d(e,e.link);break}}catch(n){console.error(`Cannot add item to api-docs search indexer [${e.label}, ${e.link}]:`,n.message)}}#d(e,n){if(!e.content)return;const t=D(n,this.#i)??"",r=e.content.children,i=this.#l(r),o=this.#y(r,t),s=e,a={id:n,url:n,title:e.label??"",text:i,path:[],deprecated:e.content.meta?.deprecated,..."httpVerb"in e&&e.httpVerb?{httpMethod:e.httpVerb}:{},..."httpPath"in e&&e.httpPath?{httpPath:e.httpPath}:{},..."badges"in e&&Array.isArray(e.badges)&&e.badges.length?{badges:e.badges}:{},..."isAdditionalOperation"in e&&e.isAdditionalOperation?{isAdditionalOperation:!0}:{},[f]:s[f],...o.length&&{parameters:o}};this.#a.push(a)}#l(e){const n=[],t=r=>{for(const i of r)if(i.nodeType===P.MARKDOC){const o=i;if(this.#h(o.content))continue;const s=y(o.content);s&&n.push(s)}else(i.nodeType===P.CONTAINER||i.nodeType===P.OVERVIEW_SECTION_WRAPPER)&&t(i.children)};return t(e),n.join(" ").trim()}#h(e){let n=!1,t=!1;const r=o=>{o.type==="code"&&o.attributes?.content?n=!0:o.type==="text"&&o.attributes?.content&&(t=!0);for(const s of o.children??[])r(s)},i=Array.isArray(e)?e:[e];for(const o of i)r(o);return n&&!t}#y(e,n){const t={},r=new Set,i=o=>{for(const s of o)if(s.nodeType===P.ITEM){const a=s;if(a[f])continue;this.#m(a,t,n),this.#S(a,t,r,n)}else if(s.nodeType===P.CONTAINER){const a=s;if(a[f])continue;i(a.children)}else s.nodeType===P.OVERVIEW_SECTION_WRAPPER&&i(s.children)};return i(e),Object.values(t)}#m(e,n,t){if(e.parameters?.length)for(const r of e.parameters){if(r[f])continue;const i=this.#$(e.variant),o=this.#k(e.variant),s=r.description?y(r.description):"",a=this.#g(r.schemaId),d={name:r.name,description:s,place:i,mediaType:void 0,type:a,required:r.required??!1,deepLink:this.#c(t,"request",o,void 0,void 0,[r.name]),example:void 0,enum:void 0};n[this.#t(d)]=d}}#t(e){return[...Array.isArray(e.path)?e.path:[],e.name.toString()].join(".")+e.description+e.place}#c(e,n,t,r,i,o){if(!e)return"";const s=o.join("/"),a=[`t=${n}`];return t&&a.push(`in=${t}`),i&&a.push(`c=${i}`),r&&a.push(`ct=${r}`),s&&a.push(`path=${s}`),`/${e}#${e}/${a.join("&")}`.toLowerCase()}#P(e,n,t,r){if(!e)return"";let i="messages";n&&(i+=`&m=${n}`),i+=`&t=${t}`;const o=r.join("/");return o&&(i+=`&path=${o}`),`/${e}#${e}/${i}`.toLowerCase()}#k(e){switch(e){case"query":return"query";case"path":return"path";case"headers":return"header";case"cookies":return"cookie";default:return}}#$(e){switch(e){case"query":return"query parameters";case"path":return"path parameters";case"headers":return"header parameters";case"cookies":return"cookie parameters";case"parameters":return"channel parameters";default:return e?`${e} parameters`:"parameters"}}#g(e){const n=this.#r?.[e];if(!n||n.kind!==E.JSON_SCHEMA)return"unknown";const t=n.data,r=this.#p(t);return this.#f(r)}#f(e){return Array.isArray(e.type)?e.type.join(" | "):e.type?e.type:e.properties||e.additionalProperties?"object":e.items?"array":e.enum?"string":"any"}#S(e,n,t,r){const i=this.#A(e);if(e.graphqlSchema&&Array.isArray(e.graphqlSchema)){this.#I(e.graphqlSchema,i,n,e,r);return}const o=!!this.#r&&!!this.#s;o&&this.#O(e,i,n,t,r);for(const s of e.responses??[])s[f]||(this.#T(s,n,r),o&&this.#b(s,n,r));if(o)for(const s of e.messages??[])s[f]||this.#q(s,n,r)}#O(e,n,t,r,i){const o=n.startsWith("response");if(e.mediaTypeSchemas){const s=Object.entries(e.mediaTypeSchemas),a=s.find(([,d])=>!d[f]);if(a){const[d,c]=a;c.schemaId&&this.#n(c.schemaId,n,d,s.length>1,o,t,[],r,i)}}else e.schemaId&&this.#n(e.schemaId,n,void 0,!1,o,t,[],r,i)}#T(e,n,t){const r=e.description?y(e.description):"",o=[e.summary?y(e.summary):"",r].filter(Boolean).join(" ").trim();if(!o)return;const s={name:e.code,description:o,place:`response ${e.code}`,mediaType:void 0,type:"unknown",required:!1,deepLink:t?I(t,V("response",void 0,e.code)):void 0,example:void 0,enum:void 0};n[this.#t(s)]=s}#b(e,n,t){const r=`response ${e.code} fields`,i=new Set;if(e.mediaTypeContent){const o=Object.entries(e.mediaTypeContent),s=o.find(([,a])=>!a[f]);if(s){const[a,d]=s;d.schemaId&&this.#n(d.schemaId,r,a,o.length>1,!0,n,[],i,t)}}else e.schemaId&&this.#n(e.schemaId,r,e.mediaType,!1,!0,n,[],i,t)}#q(e,n,t){const r=e.description?y(e.description):"",i=e.summary??"",o={name:e.name,description:(r+i).trim(),place:"message",mediaType:void 0,type:"unknown",required:!1,example:void 0,enum:void 0};n[this.#t(o)]=o,this.#o=e.name;const s=new Set;e.schemaId&&this.#n(e.schemaId,R,e.contentType,!1,!1,n,[],s,t),e.headerSchemaId&&this.#n(e.headerSchemaId,w,void 0,!1,!1,n,[],s,t),this.#o=void 0}#A(e){switch(e.variant){case"body":return"request fields";case"responses":return"response fields";case"graphql-fields":return"fields";case"graphql-args":return"arguments";case"return-type":return"return type fields";default:return e.variant??"fields"}}#E(e){return e.variant!=="graphql-args"?e.graphqlTypeName:e.graphqlFieldName?e.graphqlFieldName:e.graphqlTypeName?`@${e.graphqlTypeName}`:void 0}#I(e,n,t,r,i){const o=r.variant==="graphql-args",s=this.#E(r),a=d=>i&&s?I(i,d):void 0;for(const d of e){const c=d.description?y(d.description):"",u=`${s}.${d.name}`,l={name:d.name,description:c,place:n,mediaType:void 0,path:[],type:d.type??"unknown",required:!1,deepLink:a(o?O({t:"argument",path:u,arg:d.name}):O({t:"field",path:u})),example:void 0,enum:void 0};if(t[this.#t(l)]=l,d.args?.length)for(const p of d.args){const m=p.description?y(p.description):"",h={name:p.name,description:m,place:"arguments",mediaType:void 0,path:[d.name],type:p.type??"unknown",required:!1,deepLink:a(O({t:"argument",path:`${u}.${p.name}`,arg:p.name})),example:void 0,enum:void 0};t[this.#t(h)]=h}}}#n(e,n,t,r,i,o,s,a,d=""){const c=this.#r?.[e];if(!c||c.kind!==E.JSON_SCHEMA||c[f])return;const u=c.data,l=r?t:void 0;this.#u(u,n,t,l,i,o,{path:s,linkPath:[...s],depth:0},a,d)}#R(e){const n=e.match(/^response (\d+)/);return n?n[1]:void 0}#p(e){if(e.allOf){const n={};for(const t of e.allOf){const r=t.$ref?this.#e(t.$ref):t;if(r){const i=n.properties,o=n.required;Object.assign(n,r),(i||r.properties)&&(n.properties={...i||{},...r.properties||{}}),(o||r.required)&&(n.required=[...o||[],...r.required||[]])}}return delete n.allOf,e.description&&(n.description=e.description),n}if(e.$ref){const n=this.#e(e.$ref);if(n){const t={...n};return e.description&&(t.description=e.description),t}}return e}#e(e){if(!e.startsWith("#/"))return;const n=e.slice(2).split("/");let t=this.#s;for(const r of n){if(t==null||typeof t!="object")return;t=t[r]}return t!=null&&typeof t=="object"?t:void 0}#u(e,n,t,r,i,o,s,a,d=""){if(s.depth>_||e[f])return;const c=(p,m)=>this.#u(p,n,t,r,i,o,m,a,d);if(e.$ref){this.#w(e.$ref,c,s,a);return}if(e.allOf){c(this.#x(e,a),s);return}const u=e.discriminator??e["x-discriminator"];if(u?.propertyName&&!s.inDiscriminatorVariant){this.#W(e,u,c,s);return}const l=e.oneOf??e.anyOf;if(l){this.#C(e,l,c,s,a);return}if(e.if&&(e.then||e.else)){this.#L(e,c,s);return}e.properties&&this.#D(e,c,{place:n,mediaType:t,deepLinkContentType:r,isResponse:i,paramsMap:o,frame:s,visited:a,slug:d}),this.#v(e,c,s,a)}#w(e,n,t,r){if(r.has(e))return;r.add(e);const i=this.#e(e);i&&n(i,t)}#x(e,n){const t={};for(const r of e.allOf??[]){let i=r;if(r.$ref){if(n.has(r.$ref))continue;n.add(r.$ref),i=this.#e(r.$ref)}if(i){const o=t.properties,s=t.required;Object.assign(t,i),(o||i.properties)&&(t.properties={...o||{},...i.properties||{}}),(s||i.required)&&(t.required=[...s||[],...i.required||[]])}}return delete t.allOf,t}#C(e,n,t,r,i){e.properties&&t({...e,oneOf:void 0,anyOf:void 0},{...r,linkPath:$(r.linkPath,"&oneof=0")}),n.forEach((o,s)=>{if(o.$ref){if(i.has(o.$ref))return;i.add(o.$ref)}const a=o.$ref?this.#e(o.$ref):o;a&&t(a,{...r,linkPath:$(r.linkPath,`&oneof=${s}`),depth:r.depth+1})})}#L(e,n,t){const{if:r,then:i,else:o,...s}=e;[{allOf:[s,i??{},r??{}]},{allOf:[s,o??{}]}].forEach((d,c)=>{n(d,{...t,linkPath:$(t.linkPath,`&oneof=${c}`),depth:t.depth+1})})}#D(e,n,t){const{isResponse:r,paramsMap:i,frame:o,visited:s}=t,a=e.required||[],d=this.#R(t.place),c=r?"response":"request",u=t.place===R?"payload":t.place===w?"headers":void 0,l={requiredList:a,responseCode:d,type:c,asyncSubsection:u,...t};for(const[p,m]of Object.entries(e.properties??{})){if(m[f])continue;const h=this.#j(m,s);if(!h)continue;const C=this.#V(h,s),g=this.#p(h);if(!this.#_(h,g,r))continue;const T=p===o.discriminatorPropertyName,L=[...o.path,p],b=this.#F(p,T,o),q=this.#M(p,h,g,b,l),A=this.#t(q);i[A]==null&&(i[A]=q,!C&&!T&&n(g,{path:L,linkPath:b,depth:o.depth+1}))}}#j(e,n){if(!e.$ref)return e;if(!n.has(e.$ref))return n.add(e.$ref),this.#e(e.$ref)}#V(e,n){if(!e.allOf)return!1;let t=!1;for(const r of e.allOf)r.$ref?n.has(r.$ref)||(n.add(r.$ref),t=!0):t=!0;return!t}#_(e,n,t){return!(e[f]||n[f]||n.readOnly&&!t||n.writeOnly&&t||e.additionalProperties!==void 0&&!e.properties)}#F(e,n,t){return[...n&&t.discriminatorLinkPath?t.discriminatorLinkPath:t.linkPath,e]}#M(e,n,t,r,i){const o=n.description??t.description,s=o?y(o):"",a=n.example??t.example,d=a!==void 0?F(typeof a=="string"?a:JSON.stringify(a)):void 0,c=Array.isArray(t.enum)&&t.enum.length?t.enum:void 0;return{name:e,description:s,place:i.place,mediaType:i.mediaType,path:i.frame.path,type:this.#f(t),required:i.requiredList.includes(e),deepLink:i.asyncSubsection?this.#P(i.slug,this.#o,i.asyncSubsection,r):this.#c(i.slug,i.type,void 0,i.deepLinkContentType,i.responseCode,r),example:d,enum:c}}#v(e,n,t,r){if(!e.items||typeof e.items!="object"||Array.isArray(e.items))return;if(e.items.$ref){if(r.has(e.items.$ref))return;r.add(e.items.$ref)}const i=e.items.$ref?this.#e(e.items.$ref):e.items;i&&n(i,{...t,linkPath:j(t.linkPath),depth:t.depth+1})}#W(e,n,t,r){const i=this.#G(e,n),o=s=>({...r,linkPath:$(r.linkPath,`&d=${s}`),inDiscriminatorVariant:!0,discriminatorPropertyName:n.propertyName,discriminatorLinkPath:r.linkPath});e.properties&&t({...e,discriminator:void 0,"x-discriminator":void 0,oneOf:void 0,anyOf:void 0},i.length?o(0):r),i.forEach((s,a)=>{t(s,{...o(a),depth:r.depth+1})})}#G(e,n){const t=e.oneOf??e.anyOf??[],r=Object.values(n.mapping??{});if(r.length===0)return t;const i=s=>t.find(a=>a.$ref===s||a["x-original-ref"]===s)??this.#e(s)??{},o=r.filter(s=>s!==n.defaultMapping).map(i);return n.defaultMapping&&o.push(i(n.defaultMapping)),o}getResult(){return this.#a}}export{H as ApiDocsSearchIndexer};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/api-docs",
3
- "version": "0.2.0-next.7",
3
+ "version": "0.2.0-next.8",
4
4
  "description": "Redocly API Documentation Library",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -31,7 +31,12 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@markdoc/markdoc": "0.5.2",
34
+ "@redocly/allof-merge": "0.6.9",
35
+ "@redocly/config": "0.55.0",
34
36
  "@redocly/openapi-core": "2.47.0",
37
+ "@redocly/redoc-opentelemetry": "0.2.4",
38
+ "@redocly/replay": "0.28.0-next.7",
39
+ "@redocly/theme": "^0.69.0-next.7",
35
40
  "dompurify": "3.4.13",
36
41
  "fast-xml-parser": "5.7.3",
37
42
  "graphql": "16.14.2",
@@ -47,12 +52,7 @@
47
52
  "slugify": "^1.4.7",
48
53
  "swagger2openapi": "^7.0.8",
49
54
  "url-template": "^2.0.8",
50
- "web-vitals": "3.3.1",
51
- "@redocly/allof-merge": "0.6.9",
52
- "@redocly/config": "0.55.0",
53
- "@redocly/redoc-opentelemetry": "0.2.4",
54
- "@redocly/replay": "0.28.0-next.6",
55
- "@redocly/theme": "^0.69.0-next.6"
55
+ "web-vitals": "3.3.1"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@microsoft/api-extractor": "7.58.2",
@@ -68,8 +68,8 @@
68
68
  "@types/react-dom": "^19.2.3",
69
69
  "@types/swagger2openapi": "^7.0.4",
70
70
  "@vitejs/plugin-react": "6.0.1",
71
- "@vitest/browser-playwright": "4.1.10",
72
- "@vitest/coverage-v8": "4.1.10",
71
+ "@vitest/browser-playwright": "4.1.11",
72
+ "@vitest/coverage-v8": "4.1.11",
73
73
  "esbuild": "0.28.1",
74
74
  "flexsearch": "^0.8.2",
75
75
  "globals": "^16.5.0",
@@ -82,8 +82,8 @@
82
82
  "tsx": "^4.20.6",
83
83
  "typescript": "6.0.3",
84
84
  "url": "~0.11.0",
85
- "vite": "8.1.0",
86
- "vitest": "4.1.10",
85
+ "vite": "8.2.2",
86
+ "vitest": "4.1.11",
87
87
  "vitest-browser-react": "^2.0.2"
88
88
  },
89
89
  "nx": {