@redocly/api-docs 0.1.0-next.0 → 0.1.0-next.1
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{Fragment as se,jsx as o,jsxs as j}from"react/jsx-runtime";import{useAtom as _,useAtomValue as n}from"jotai";import{lazy as ie,memo as le,Suspense as
|
|
1
|
+
import{Fragment as se,jsx as o,jsxs as j}from"react/jsx-runtime";import{useAtom as _,useAtomValue as n}from"jotai";import{lazy as ie,memo as le,Suspense as pe,useCallback as d,useEffect as me,useMemo as f,useRef as ce,useState as B}from"react";import{Button as ue}from"@redocly/theme/components/Button/Button";import{useFocusTrap as de,useModalScrollLock as fe}from"@redocly/theme/core/openapi";import{RocketIcon as ye}from"@redocly/theme/icons/RocketIcon/RocketIcon";import{Spinner as N}from"@redocly/theme/icons/Spinner/Spinner";import{Portal as he}from"@redocly/theme/components/Portal/Portal";import{useConfigureReplay as Re}from"@redocly/theme/ext/use-configure-replay";import{ReplayGate as ve}from"@redocly/theme/components/ReplayGate/ReplayGate";import{ReplayTopBarActions as ge}from"@redocly/theme/components/ReplayTopBarActions/ReplayTopBarActions";import{createReplayOverlayConverter as Oe,handleReplayParamChange as Ie,pickRuntimeConfigureRequestValues as Ae,REPLAY_TRY_IT_LOADING_STATE as l,ReplayCodeSampleHTTPSnippet as Ce,useCodeSampleResolvers as Te}from"../../services/code-samples/index.js";import{useMarkdownAdapter as Se}from"../../contexts/markdownAdapter.js";import{adapterToMarkdownParser as Le}from"./adapterToMarkdownParser.js";import{resolveRequestValues as be}from"../../adapters/openapi/configure/resolve-request-values.js";import{createTryItOpenEvent as Ee,createTryItSentEvent as Pe}from"../../events/index.js";import{useSpecTranslate as xe}from"../../hooks/useTranslate.js";import{useTelemetry as ke}from"../../hooks/useTelemetry.js";import{useOpenApiDefinition as we}from"../../hoc/withReplayPrefetch.js";import{allowedEnvironmentsAtom as De,environmentAtom as Me,environmentsAtom as Ve,requestValuesAtom as $e,userClaimsAtom as qe}from"../../jotai/app.js";import{globalOptionsAtom as je,routingBasePathAtom as _e}from"../../jotai/store.js";import{routeIndexAtom as Be}from"../../jotai/routes.js";import{exampleStoreAtom as Ne}from"../../jotai/examples.js";import{joinWithSeparator as Ue}from"../../utils/url.js";import{encodeBackSlashes as Ge}from"../../utils/string.js";import{getDefaultCollectorUrl as Fe}from"../../utils/telemetry.js";const ze=ie(()=>import("@redocly/replay").then(p=>({default:p.ReplayOverlay})));function He({message:p}){return j("div",{style:{alignItems:"center",display:"flex",flexDirection:"column",gap:"1rem",justifyContent:"center",padding:"2rem"},children:[o(N,{color:"var(--primary-color, #333)"}),o("span",{children:p})]})}function We({node:p,onTryItLoadingStateChange:L,hideOtherSecuritySchemes:U}){const g=xe(),b=ce(null),a=n(je),{oAuth2RedirectURI:G,events:m}=a,E=Se(),O=f(()=>({...a,markdownParser:Le(E)}),[a,E]),F=ke(),c=n(_e),P=n(Be),I=n(qe),x=n(Ne),z=n(Ve),H=n(De),[[,W],k]=_(Me),[,w]=_($e),A=we(),[y,D]=B(!1),[u,C]=B(l.NOT_LOADED),M=Te();me(()=>{L?.(u)},[u,L]);const Y=d(()=>{C(l.LOADED)},[]),e=p.source,K=e.path,J=e.method,Q=`${e.method.toLowerCase()}:${e.path}`,h=e.openApiOperationId??Q,s=f(()=>({id:`${e.method}:${e.path}`,path:e.path,httpVerb:e.method,name:e.summary||`${e.method.toUpperCase()} ${e.path}`}),[e]),X=f(()=>e.servers.map(t=>({url:t.url,description:t.description,name:t.name,variables:t.variables?Object.fromEntries(Object.entries(t.variables).map(([i,r])=>[i,{default:r.default??"",enum:r.enum,description:r.description}])):void 0})),[e.servers]),{config:R,refresh:V}=Re({userClaims:I,info:A?.info??{},operation:{name:s.name,path:K,operationId:h,href:"",method:J},servers:X},y),Z=f(()=>{const t=new Map([[`${e.method.toLowerCase()}:${e.path}`,e]]);return Oe(t,M,O,R,x,(r,v)=>{const T=v.servers??[],S=r.servers??T;return be({operationInfo:r,info:v.info??{},servers:S,basePath:c,userClaims:I,dynamicRequestValues:O.dynamicRequestValues})})},[e,M,O,R,x,c,I]),ee=f(()=>Ae(a,R),[a,R]);de(b),fe(y);const te=d(()=>{V()},[V]),oe=d(t=>{m?.tryItSent&&s&&m.tryItSent(Pe({operation:s,isSuccess:t}))},[m,s]),re=d(t=>{Ie(t,k,(i,r,v)=>{const T=`${r.toLowerCase()}:${i}`;w(S=>({...S,[T]:v}))})},[k,w]),$=()=>{if(y){D(!1),C(l.NOT_LOADED);return}m?.tryItOpen&&s&&m.tryItOpen(Ee({operation:s})),F.sendTryItOpenedMessage([{id:"tryItButton",object:"button",uri:"urn:redocly:redoc:ui:button:tryItButton"}]),C(l.LOADING),D(!0)},ne=d(t=>{if(!t)return;if(t===h&&e.href)return Ue(c,e.href);const i=`/${Ge(t).toLowerCase()}`;return P?.allRoutes.find(r=>r.path.toLowerCase().endsWith(i))?.path},[c,e.href,h,P]),ae=A?.info,q=u===l.LOADING;return j(se,{children:[o(ue,{onClick:$,variant:"primary",iconPosition:"left",icon:q?o(N,{}):o(ye,{}),children:q?g("loading","Loading..."):g("tryIt","Try it")}),y&&o(he,{mountId:"api-content",children:o("div",{"aria-busy":u===l.LOADING,"data-try-it-loading-state":u,children:o(pe,{fallback:o(He,{message:g("loading","Loading...")}),children:o("div",{ref:b,children:o(ze,{ReplayGate:ve,ReplayTopBarActions:ge,activeOperationId:h,api:A,onLoad:Y,onRequestChange:re,onClose:$,settings:{corsProxyUrl:a.corsProxyUrl,selectedEnvironment:W,apiId:ae?.["x-metadata"]?.apiId,oAuth2RedirectURI:G,disableCollectionsTab:!0,storageKey:c,HTTPSnippet:Ce,convertOperationToReplayValue:Z,getOperationUrl:ne,onRequestReset:te,predefinedEnvValues:z,telemetry:{tracerName:"try-it",collectorUrl:Fe()},dynamicReplayValues:ee,onRequestSent:oe,hideOtherSecuritySchemes:U,allowedEnvironments:H??void 0}})})})})})]})}const Ot=le(We);export{Ot as Replay};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isRecord as h}from"../../../adapters/helpers.js";import{mergeBodyValue as
|
|
1
|
+
import{isRecord as h}from"../../../adapters/helpers.js";import{mergeBodyValue as O}from"../../../adapters/openapi/configure/merge-utils.js";import{mapToReplayServers as S}from"./map-servers.js";function x(e){return e.startsWith("#/")?e.slice(2):e}const g="#/components/schemas/";function k(e,i){if(!e)return;const t=Object.create(null),n=[e];for(;n.length;){const a=n.pop();if(Array.isArray(a)){n.push(...a);continue}if(h(a))for(const[r,o]of Object.entries(a)){if(r==="$ref"&&typeof o=="string"&&o.startsWith(g)){const s=o.slice(g.length);if(s in t)continue;const l=i.resolveSchema(x(o));if(!l)continue;t[s]=l,n.push(l);continue}n.push(o)}}return Object.keys(t).length>0?{...e,components:{schemas:t}}:e}function I(e,i){const t={},n=e.discriminator;if(n?.propertyName&&n.mapping){const r=n.propertyName;for(const[o,s]of Object.entries(n.mapping)){if(typeof s!="string")continue;const l=i.resolveSchema(x(s));if(!l)continue;const p=i.sampleFromSchema(l,{skipReadOnly:!0});p!=null&&(h(p)&&(p[r]=o),t[o]={value:p})}if(Object.keys(t).length>0)return t}if(Array.isArray(e.oneOf)&&e.oneOf.length>0){const r=e.oneOf;for(let o=0;o<r.length;o++){const s=r[o];let l;if(h(s)&&(l=s,typeof s.$ref=="string"&&(l=i.resolveSchema(x(s.$ref))??s)),!l)continue;const p=i.sampleFromSchema(l,{skipReadOnly:!0});if(p==null)continue;const c=typeof l.title=="string"?l.title:`option ${o+1}`;t[c]={value:p}}if(Object.keys(t).length>0)return t}const a=i.sampleFromSchema(e,{skipReadOnly:!0});return a!=null&&(t.default={value:a}),t}function b(e,i,t){const n={};if(e.exampleIds?.length)for(const a of e.exampleIds){const r=i.resolveExample(a);r&&(n[a]={value:r.value,summary:r.summary})}if(Object.keys(n).length===0&&e.schemaId){const a=i.resolveSchema(e.schemaId);a&&Object.assign(n,I(a,i))}if(t!==void 0)if(Object.keys(n).length===0)n.default={value:t};else for(const a of Object.keys(n)){const r=n[a];n[a]={...r,value:O(r.value,t)}}return n}function v(e,i){const t=[],n=(c,u)=>{for(const f of c){const d=f.example;let m;if(f.schemaId){const y=i.resolveSchema(f.schemaId);y&&(m={typePrefix:"",title:y.title??f.name,displayType:y.type??"string",displayFormat:y.format,constraints:[],enum:y.enum??void 0})}t.push({name:f.name,in:u,required:f.required??!1,example:d!=null?String(d):void 0,schema:m})}};n(e.parameters.path,"path"),n(e.parameters.query,"query"),n(e.parameters.header,"header"),n(e.parameters.cookie,"cookie");for(const c of e.parameters.querystring)t.push(R(c,i));const a=S(e.servers),r=e.security.map(c=>c.schemes.map(u=>q(u,c.scopes)));let o;if(e.requestBody){const c=e.requestValues?.body,u={};for(const[f,d]of Object.entries(e.requestBody)){const m=b(d,i,c);u[f]={name:f,examples:Object.keys(m).length>0?m:void 0,schema:d.schemaId?k(i.resolveSchema(d.schemaId),i):void 0,parameters:[]}}o={mediaTypes:u}}const s=e.method.toLowerCase(),l=`${s}:${e.path}`,p=e.openApiOperationId??l;return{id:p,name:e.summary||`${e.method.toUpperCase()} ${e.path}`,method:s,path:e.path,href:"",operationId:p,parameters:t,servers:a,security:r,body:o}}function R(e,i){const t=e.schemaId?i.resolveSchema(e.schemaId):void 0,n=e.example!=null?e.example:t?i.sampleFromSchema(t,{skipReadOnly:!0}):void 0,a=j(t,n),r={typePrefix:"",title:t?.title??e.name,displayType:t?.type??"object",constraints:[],...a&&a.length>0?{fields:a}:{},...n!==void 0?{example:n}:{}};return{name:e.name,in:"querystring",required:e.required??!1,schema:r}}function j(e,i){const t=e?.properties;if(!t)return;const n=h(i)?i:{};return Object.keys(t).map(a=>{const r=n[a]!==void 0?n[a]:t[a]?.example;return{name:a,example:r}})}function q(e,i){return{id:e.id,type:e.type,name:e.name,in:e.in==="querystring"?"query":e.in,scheme:e.scheme,openIdConnectUrl:e.openIdConnectUrl,scopes:i,flows:e.flows,"x-defaultAccessToken":e["x-defaultAccessToken"],"x-defaultTokenType":e["x-defaultTokenType"],"x-defaultClientId":e["x-defaultClientId"],"x-defaultClientSecret":e["x-defaultClientSecret"],"x-defaultUsername":e["x-defaultUsername"],"x-defaultPassword":e["x-defaultPassword"],serverValues:e.serverValues}}function $(e,i,t){return(n,a,r)=>{const o=`${a.toLowerCase()}:${n}`,s=e.get(o);if(!s)return;const l=t?t(s):s;return v(l,i)}}export{$ as createReplayConverter,v as toReplayOperation};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/api-docs",
|
|
3
|
-
"version": "0.1.0-next.
|
|
3
|
+
"version": "0.1.0-next.1",
|
|
4
4
|
"description": "Redocly API Documentation Library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"web-vitals": "3.3.1",
|
|
49
49
|
"@redocly/config": "0.53.1",
|
|
50
50
|
"@redocly/redoc-opentelemetry": "0.2.2",
|
|
51
|
-
"@redocly/replay": "0.27.0-next.
|
|
51
|
+
"@redocly/replay": "0.27.0-next.7",
|
|
52
52
|
"@redocly/theme": "^0.68.0-next.5",
|
|
53
53
|
"@redocly/allof-merge": "0.6.9"
|
|
54
54
|
},
|