@redocly/api-docs 0.2.0-next.3 → 0.2.0-next.5
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/lib/adapters/helpers.d.ts +2 -0
- package/lib/adapters/helpers.js +1 -1
- package/lib/adapters/openapi/build-code-sample-source.js +1 -1
- package/lib/adapters/openapi/items/operation/content.js +1 -1
- package/lib/adapters/openapi/store.js +1 -1
- package/lib/components/panels/ExampleItem/CallbackPayloadItem.js +2 -2
- package/lib/components/panels/ExampleItem/CodeSampleItem.js +1 -1
- package/lib/components/panels/ExampleItem/PayloadExampleItem.js +2 -2
- package/lib/components/panels/ExampleItem/ResponseExampleItem.js +1 -1
- package/lib/components/panels/ExampleItem/ServerDropdown.js +1 -1
- package/lib/components/panels/ExampleItem/selectors.d.ts +5 -2
- package/lib/components/panels/ExampleItem/selectors.js +1 -1
- package/lib/components/panels/ExampleItem/styled.d.ts +1 -0
- package/lib/components/panels/ExampleItem/styled.js +11 -5
- package/lib/components/pluggable/RedocExample.js +5 -2
- package/lib/jotai/itemStore.d.ts +1 -0
- package/lib/jotai/itemStore.js +1 -1
- package/lib/services/code-samples/builder.d.ts +3 -5
- package/lib/services/code-samples/builder.js +1 -1
- package/lib/services/code-samples/discriminator.d.ts +16 -10
- package/lib/services/code-samples/discriminator.js +1 -1
- package/lib/services/code-samples/resolvers.js +1 -1
- package/lib/services/schema/dialects/jsonSchema.d.ts +5 -1
- package/lib/services/schema/dialects/jsonSchema.js +1 -1
- package/lib/services/schema/propertyTreeBuilder.js +1 -1
- package/lib/types/store.d.ts +1 -1
- package/lib/utils/scroll-anchoring.d.ts +2 -1
- package/package.json +14 -5
|
@@ -15,6 +15,8 @@ export declare function splitRbacSection<T>(map: Record<string, T> | undefined):
|
|
|
15
15
|
sectionRbac: Record<string, string> | undefined;
|
|
16
16
|
entries: [string, T][];
|
|
17
17
|
};
|
|
18
|
+
/** Accepts a raw markdown string or a host-pre-parsed AST node; drops anything else. */
|
|
19
|
+
export declare function pickRenderableDescription(value: unknown): ExampleEntry['description'];
|
|
18
20
|
export declare function registerExample(exampleStore: Record<string, ExampleEntry>, entry: Omit<ExampleEntry, 'id'> & {
|
|
19
21
|
id?: string;
|
|
20
22
|
}): string;
|
package/lib/adapters/helpers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{REDOCLY_TEAMS_RBAC as u}from"@redocly/config";import{getDefinitionName as l}from"./openapi/utils/helpers.js";let d=0,x=0;function C(){d=0,x=0}function s(e,r){return e==null?String(e):typeof e!="object"?JSON.stringify(e):(r||(r=new Set),r.has(e)?'"[Circular]"':(r.add(e),Array.isArray(e)?"["+e.map(n=>s(n,r)).join(",")+"]":c(e)?"{"+Object.keys(e).sort().map(n=>JSON.stringify(n)+":"+s(e[n],r)).join(",")+"}":"{}"))}function O(e,r,t){const n=g(t);if(t.id&&e[t.id])return t.id;if(!t.id){const o=s(t.data),p=r[o];if(p)return p;const f=`schema_${d++}`;return e[f]={...n,id:f},r[o]=f,f}e[t.id]={...n,id:t.id};const i=s(t.data);return r[i]||(r[i]=t.id),t.id}function g(e){const r=m(e.data);return r?{...e,[u]:r}:e}function m(e){if(!c(e))return;const r=e[u];return c(r)?r:void 0}function A(e){return e?{[u]:e}:{}}function E(e){return e?{sectionRbac:m(e),entries:Object.entries(e).filter(([r])=>r!==u)}:{sectionRbac:void 0,entries:[]}}function
|
|
1
|
+
import{REDOCLY_TEAMS_RBAC as u}from"@redocly/config";import{getDefinitionName as l}from"./openapi/utils/helpers.js";let d=0,x=0;function C(){d=0,x=0}function s(e,r){return e==null?String(e):typeof e!="object"?JSON.stringify(e):(r||(r=new Set),r.has(e)?'"[Circular]"':(r.add(e),Array.isArray(e)?"["+e.map(n=>s(n,r)).join(",")+"]":c(e)?"{"+Object.keys(e).sort().map(n=>JSON.stringify(n)+":"+s(e[n],r)).join(",")+"}":"{}"))}function O(e,r,t){const n=g(t);if(t.id&&e[t.id])return t.id;if(!t.id){const o=s(t.data),p=r[o];if(p)return p;const f=`schema_${d++}`;return e[f]={...n,id:f},r[o]=f,f}e[t.id]={...n,id:t.id};const i=s(t.data);return r[i]||(r[i]=t.id),t.id}function g(e){const r=m(e.data);return r?{...e,[u]:r}:e}function m(e){if(!c(e))return;const r=e[u];return c(r)?r:void 0}function A(e){return e?{[u]:e}:{}}function E(e){return e?{sectionRbac:m(e),entries:Object.entries(e).filter(([r])=>r!==u)}:{sectionRbac:void 0,entries:[]}}function y(e){return typeof e=="string"||typeof e=="object"&&e!==null?e:void 0}function k(e,r){const t=r.id??`example_${x++}`;return e[t]||(e[t]={...r,id:t}),t}function $(e,r){return e[r.id]||(e[r.id]=r),r.id}function N(e){return{schemaStore:{},exampleStore:{},securitySchemeStore:{},hashIndex:{},document:e}}function c(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function _(e){return c(e)?e:{}}function b(e,r,t){if(c(r)){if(typeof r.$ref=="string"){const n=r.$ref,i=l(n);return i&&t?.has(i)?{type:"object",title:i}:R(e,n)}return r}}function a(e){return c(e)&&typeof e.$ref=="string"}function D(e,r,t){const n=r?.content;if(!n)return;const i=a(n)?b(e,n,t):n;return S(i,r)}function S(e,r){if(!e)return e;const t=r["x-examples"];if(t){const i={...e};for(const o of Object.keys(t))i[o]={...i[o],examples:t[o]};return i}const n=r["x-example"];if(n){const i={...e};for(const o of Object.keys(n))i[o]={...i[o],example:n[o]};return i}return e}function R(e,r){if(!r.startsWith("#/"))return;const t=r.slice(2).split("/").map(i=>i.replace(/~1/g,"/").replace(/~0/g,"~"));let n=e;for(const i of t){if(!c(n))return;n=n[i]}return c(n)?n:void 0}export{N as createStoreContext,a as isOpenAPIRef,c as isRecord,y as pickRenderableDescription,A as rbacProp,m as readRbacScope,k as registerExample,O as registerSchema,$ as registerSecurityScheme,C as resetStoreCounters,D as resolveContent,R as resolveJsonPointer,b as resolveRef,E as splitRbacSection,s as stableStringify,_ as toRecord};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{REDOCLY_TEAMS_RBAC as w}from"@redocly/config";import{registerExample as O,registerSchema as R,resolveContent as
|
|
1
|
+
import{REDOCLY_TEAMS_RBAC as w}from"@redocly/config";import{registerExample as O,pickRenderableDescription as M,registerSchema as R,resolveContent as A,resolveRef as S,readRbacScope as q,rbacProp as P}from"../helpers.js";import{panelKind as T,schemaKind as j}from"../../types/common.js";import{isStatusCode as C}from"../../utils/status-code.js";import{encodeJsonPointerSegment as B}from"../../utils/refPointer.js";import{applyIgnoreNamedSchemasDeep as U}from"./utils/applyIgnoreNamedSchemasDeep.js";import{mergeInMockServer as L,pickOperationServers as _}from"./utils/merge-mock-server.js";import{mergeSecurityIntoScheme as E}from"./configure/merge-utils.js";import{hasOpenApiExampleValue as $,resolveOpenApiExampleValue as g}from"./resolve-openapi-example-value.js";function D(r,n,t){const a=S(n,r,t)??r;return U(a,t)}function re(r,n,t,a,o,i){const u=n?.document??{},l=F(r,u,t),s=K(r,u,n,a),e=N(r,n),c=G(r,u,n,a),y=J(r),d=r.responses,p=d?Object.keys(d).filter(C):void 0,f=r.security;return{kind:T.CODE_SAMPLE,operationType:o?"webhook":"http",method:r.httpVerb?.toUpperCase()??"GET",path:r.pathName??"/",servers:l,parameters:s,security:e,requestBody:c,responseCodes:p,requestValues:y,pointer:r.pathName,...i&&{href:i},...r.operationId&&{openApiOperationId:r.operationId},...r.summary&&{summary:r.summary},...f&&f.length>1&&{securityGroups:f}}}function F(r,n,t){const a=n.servers,o=_(r.servers,a),u=L(o.filter(l=>typeof l?.url=="string"),t.mockServer).map(l=>({url:l.url??"",name:l.name,description:typeof l.description=="string"?l.description:void 0,...l.isMockServer&&{isMockServer:!0},variables:l.variables&&Object.keys(l.variables).length>0?Object.fromEntries(Object.entries(l.variables).map(([s,e])=>[s,{default:e.default,enum:e.enum}])):void 0}));return u.length>0?u:[{url:"/"}]}function K(r,n,t,a){const i=(r.parameters??[]).map(s=>D(s,n,a)),u={path:[],query:[],querystring:[],header:[],cookie:[]},l=r.requestValues?.serverRequestValues;for(const s of i){const e=s.in;if(!e||!u[e])continue;const c=s.content,y=c?Object.keys(c)[0]:void 0,d=y&&c?c[y]?.schema:s.schema,p=d&&typeof d=="object"?S(n,d,a)??d:d;let f;p&&t&&(f=R(t.schemaStore,t.hashIndex,{kind:j.JSON_SCHEMA,data:p}));const V=p&&typeof p=="object"&&"example"in p?p.example:void 0;let v;if(s.examples&&typeof s.examples=="object")for(const m of Object.values(s.examples)){if(!m||typeof m!="object")continue;const x=S(n,m,a)??m;if($(x)){v=g(x);break}}const b={};if(l&&s.name)for(const[m,x]of Object.entries(l)){const k=x?.[e==="querystring"?"queryString":e==="header"?"headers":e==="cookie"?"cookies":e]?.[s.name];k!=null&&(b[m]={example:k})}u[e].push({name:s.name??"",in:e,required:s.required,example:s.example??v??V,schemaId:f,serializationMime:y,style:s.style,explode:s.explode,...Object.keys(b).length>0&&{serverValues:b}})}return u}function N(r,n){const t=r.requestValues?.security,a=r.requestValues?.serverRequestValues,o=r.security,i=[];if(!o||!n)return i;for(const u of o){const l=Object.keys(u),s=l.map(e=>n.securitySchemeStore[e]).filter(Boolean).map(e=>{let c={id:e.id,type:e.type,name:e.paramName,in:e.in,scheme:e.scheme,bearerFormat:e.bearerFormat,openIdConnectUrl:e.openIdConnectUrl,flows:e.flows,"x-defaultClientId":e["x-defaultClientId"],"x-defaultAccessToken":e["x-defaultAccessToken"],"x-defaultTokenType":e["x-defaultTokenType"],"x-defaultClientSecret":e["x-defaultClientSecret"],"x-defaultUsername":e["x-defaultUsername"],"x-defaultPassword":e["x-defaultPassword"],serverValues:e.serverValues?{...e.serverValues}:void 0};if(t&&(c=E(c,t)),a)for(const[y,d]of Object.entries(a))d?.security&&(c=E(c,d.security,y));return c});if(s.length>0){const e=l.flatMap(c=>u[c]??[]);i.push({schemes:s,scopes:e})}}return i}function G(r,n,t,a){const o=r.requestBody,i=o?S(n,o,a)??o:void 0,u=A(n,i,a);if(!u||!t)return;const l={};for(const[s,e]of Object.entries(u)){let c;const y=e.itemSchema,d=e.schema??y;if(d){const V=S(n,d,a)??d;c=R(t.schemaStore,t.hashIndex,{kind:j.JSON_SCHEMA,data:V})}const p=r.pointer?`${r.pointer}/requestBody/content/${B(s)}`.replace(/^\//,""):void 0,f=[];if(e.example!==void 0&&f.push(O(t.exampleStore,{value:e.example,...p&&{id:`${p}/example`}})),e.examples){const V=q(e.examples);for(const[v,b]of Object.entries(e.examples)){if(v===w)continue;const m=S(n,b,a);if(m){const x=q(b)??q(m)??V,h=O(t.exampleStore,{value:g(m),key:v,summary:typeof m.summary=="string"?m.summary:v,description:M(m.description),externalValue:typeof m.externalValue=="string"?m.externalValue:void 0,...P(x),...p&&{id:`${p}/examples/${B(v)}`}});f.push(h)}}}l[s]={schemaId:c,...f.length>0&&{exampleIds:f}}}return l}function J(r){const n=r.requestValues?.serverRequestValues,t=r.requestValues?.envVariables;let a,o;if(t&&typeof t=="object")if("values"in t){const s=t;a=s.values,o=s.serverValues}else a=t;const i=r.requestValues?.body;let u;if(n)for(const[s,e]of Object.entries(n))e?.body!==void 0&&(u=u??{},u[s]=e.body),e?.envVariables&&(o=o??{},o[s]={...o[s],...e.envVariables});return a||o||r.requestValues?.security||i!==void 0||u?{...r.requestValues?.security&&{security:r.requestValues.security},...a&&{envVariables:a},...o&&{serverEnvVariables:o},...i!==void 0&&{body:i},...u&&{serverBody:u}}:void 0}export{re as buildCodeSampleSource};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{REDOCLY_TEAMS_RBAC as U}from"@redocly/config";import{contentType as pe,itemVariant as le,nodeTypes as f,panelKind as Y,schemaKind as B}from"../../../../types/common.js";import{readRbacScope as E,rbacProp as A,registerExample as J,registerSchema as H,resolveContent as z,resolveRef as P}from"../../../helpers.js";import{applyIgnoreNamedSchemasDeep as ee}from"../../utils/applyIgnoreNamedSchemasDeep.js";import{isStatusCode as ue}from"../../../../utils/status-code.js";import{parseMarkdown as K}from"../../../utils/parseMarkdown.js";import{extractDescriptionSegments as me,resolveMarkdocHeadingIds as W}from"../../../utils/markdoc.js";import{getExtensionsForDisplay as G}from"../../../../utils/extract-extensions.js";import{openApiContext as $}from"../../buildContext.js";import{buildCodeSampleSource as ye}from"../../build-code-sample-source.js";import{mergeInMockServer as he,pickOperationServers as fe}from"../../utils/merge-mock-server.js";import{normalizePath as be,toRelativePath as te}from"../../../../utils/url.js";import{encodeJsonPointerSegment as N}from"../../../../utils/refPointer.js";import{hasOpenApiExampleValue as se,resolveOpenApiExampleValue as Z}from"../../resolve-openapi-example-value.js";const Q="request",ne="responses",re="callbacks";function xe(){const e=new Map;return(r,s)=>{const o=`${r}/${s}`,n=e.get(o)??0;return e.set(o,n+1),n===0?o:`${o}~${n}`}}function we(e,r){const{options:s,storeCtx:o,basePath:n}=$.get(),t=e.summary||e.operationId||e.pathName||"Unknown Operation",c=[],{feedback:l}=s,i=e.isWebhook||!1,p=[{nodeType:f.HEADER,level:2,label:t,badges:e["x-badges"],isWebhook:i,deprecated:e.deprecated,showPageActions:!0}],a=G(e,s.showExtensions);Object.keys(a).length>0&&p.push({nodeType:f.EXTENSIONS,extensions:a}),c.push({nodeType:f.CONTAINER,children:p,panels:[]});const m=s.ignoreNamedSchemas,h=e["x-codeSamples"]?.map(({lang:u,label:v,source:D})=>({lang:u,label:v,source:D})),b=fe(e.servers,o?.document?.servers),x=he(b.filter(u=>typeof u?.url=="string"),s.mockServer).map(u=>{const v=E(u);return{url:u.url??"",name:u.name,description:typeof u.description=="string"?u.description:void 0,...u.isMockServer&&{isMockServer:!0},variables:u.variables&&Object.keys(u.variables).length>0?Object.fromEntries(Object.entries(u.variables).map(([D,L])=>[D,{default:L.default}])):void 0,...A(v)}}),y=ie(e,m),S=te(r,n);let d=[];e.description&&(W(e.description,S,Q),d=me(e.description,s));const g=d.some(u=>u.kind==="schemaDefinition"),T=y.find(u=>u.nodeType===f.ITEM&&u.variant==="body"),C=Ae(e,m,i,S||void 0),q=T?.schemaId,O=T?.mediaTypes,k=T?.mediaTypeSchemas,M=E(T),R=[{children:[{kind:Y.CODE_SAMPLE,source:C,definitionSamples:h?.length?h:void 0,isWebhook:i,hideReplay:e["x-hideReplay"]===!0,servers:x?.length?x:void 0,schemaId:q,exampleIds:T?.exampleIds,mediaTypes:O,mediaTypeSchemas:k,examples:T?.exampleIds?.map(()=>({}))??[]}],...A(M)}];if(y.length>0||d.length>0)if(g){c.push({nodeType:f.CONTAINER,children:[{nodeType:f.HEADER,level:4,label:"Request",labelTranslationKey:"request",deepLinkSuffix:Q}],panels:[]});for(const u of d)u.kind==="schemaDefinition"?c.push(u.node):c.push({nodeType:f.CONTAINER,children:[u.node],panels:[]});c.push({nodeType:f.CONTAINER,children:[...y],panels:R})}else c.push({nodeType:f.CONTAINER,children:[{nodeType:f.HEADER,level:4,label:"Request",labelTranslationKey:"request",deepLinkSuffix:Q},...d.map(u=>u.node),...y],panels:R});else c.push({nodeType:f.CONTAINER,children:[{nodeType:f.HEADER,level:4,label:"Request",labelTranslationKey:"request",deepLinkSuffix:Q},{nodeType:f.EMPTY_MESSAGE,label:"No request data",labelTranslationKey:"noRequestData"}],panels:R});if(e.responses){const u=ce(e,s,S,m);if(u){const v=u.responses?.some(j=>j.schemaId||(j.exampleIds?.length??0)>0),D=u?.responses?.map(j=>{const de=j[U];return{code:j.code,schemaId:j.schemaId,exampleIds:j.exampleIds,mediaTypes:j.mediaTypes,mediaTypeContent:j.mediaTypeContent,...A(de)}}),L=[];v&&L.push({children:[{kind:Y.RESPONSE,headerTitle:"Response",responseCodes:D,examples:[]}]});const ae=E(e.responses);c.push({nodeType:f.CONTAINER,children:[{nodeType:f.HEADER,level:4,label:"Responses",labelTranslationKey:"responses",deepLinkSuffix:"responses"},u],panels:L.length>0?L:[],...A(ae)})}}Array.isArray(e.callbacks)&&e.callbacks.length>0&&c.push(...Se(e,S,m)),l?.hide!==!0&&c.push({nodeType:f.CONTAINER,children:[{nodeType:f.FEEDBACK,pageSlug:be(te(r,n))}],panels:[]});const _=y.some(u=>{const v=u;return v.variant==="body"&&((v.exampleIds?.length??0)>0||!!v.schemaId)})||(h?.length??0)>0;return{contentType:pe.ITEM,itemVariant:le.HTTP_ITEM,seo:e["x-seo"],meta:{sourceId:e.operationId,name:t,deprecated:e.deprecated,isWebhook:e.isWebhook||!1,pointer:e.pointer,hasSamples:_},children:c}}function Se(e,r,s){const o=[{nodeType:f.CONTAINER,children:[{nodeType:f.HEADER,level:4,label:"Callbacks",labelTranslationKey:"callbacks",deepLinkSuffix:re}],panels:[]}],n=xe();for(const t of e.callbacks??[])if(t.operations)for(const c of t.operations){const l=c.httpVerb??"post",i=n(t.name,l);o.push(Te(e,t,c,i,r,s))}return o}function Te(e,r,s,o,n,t){const{options:c}=$.get(),l=s.httpVerb??"post",i={pointer:e.pointer+"/callbacks/"+r.name+"/"+l,pathName:s.pathName??r.url??"",httpVerb:l,summary:s.summary,deprecated:s.deprecated,isWebhook:!1,isAdditionalOperation:!1,tags:[],parameters:s.parameters,requestBody:s.requestBody,responses:s.responses,servers:s.servers,security:s.security},p=ie(i,t),a=ce(i,c,`${n}/callbacks/${o}`,t),m=[...p];a&&m.push(a);const h=s.externalDocs,b=G(s,c.showExtensions);let x;s.description&&(x=K(s.description,c),W(x??[],n,`${re}/${o}`));const y={httpVerb:l,pathName:i.pathName,summary:i.summary,operationId:typeof s.operationId=="string"?s.operationId:void 0,description:x,deprecated:i.deprecated,callbackName:r.name,callbackId:o,externalDocs:h?{url:h.url,description:h.description}:void 0,extensions:Object.keys(b).length>0?b:void 0,contentChildren:m.length>0?m:void 0},S=Ee(s,i,o,t),d=E(r);return{nodeType:f.CONTAINER,children:[{nodeType:f.ITEM,variant:"callback",callback:y,pointer:e.pointer+"/callbacks"}],panels:S,...A(d)}}function Ee(e,r,s,o){const{storeCtx:n}=$.get(),t=[];if(!e.requestBody||!("content"in e.requestBody))return t;const c=n?.document??{},l=P(c,e.requestBody,o)??e.requestBody,i=z(c,l,o);if(!i)return t;const p=Object.keys(i);let a=!1;const m={};for(const[y,S]of Object.entries(i)){let d;if(S.schema){const C=S.schema;d=H(n.schemaStore,n.hashIndex,{kind:B.JSON_SCHEMA,data:C})}const g=`${r.pointer}/requestBody/content/${N(y)}`.replace(/^\//,""),T=[];if(S.example!==void 0){const C=J(n.exampleStore,{value:S.example,id:`${g}/example`});T.push(C),a=!0}if(S.examples)for(const[C,q]of Object.entries(S.examples)){const O=P(c,q,o);if(O&&se(O)){const k=J(n.exampleStore,{value:Z(O),summary:O.summary??C,id:`${g}/examples/${N(C)}`});T.push(k),a=!0}}m[y]={schemaId:d,exampleIds:T.length>0?T:void 0},d&&(a=!0)}const h=e["x-codeSamples"];if(!(a||(h?.length??0)>0))return t;const x=e.servers?.filter(y=>y.url).map(({url:y,name:S,description:d,variables:g})=>({url:y,name:S,description:d,variables:g}));return t.push({children:[{kind:Y.CALLBACK_PAYLOAD,callbackName:s,path:r.pathName,httpVerb:r.httpVerb,servers:x?.length?x:void 0,definitionSamples:h,mediaTypes:p.length>0?p:void 0,mediaTypeSchemas:Object.keys(m).length>0?m:void 0,examples:[]}]}),t}function Ce(e,r,s){const o=P(r,e,s)??e,{$ref:n,...t}=e,c=typeof n=="string"?{...o,...t}:o;return ee(c,s)}function V(e,r,s){if(!e||typeof e!="object")return;const o=e,n=P(r,o,s)??o;return ee(n,s)}function ge(e,r,s){if(!e||typeof e!="object")return;const o=E(e),n={},t=[];for(const[c,l]of Object.entries(e)){if(c===U)continue;const i=P(r,l,s)??l,p=i.content,a=p?p[Object.keys(p)[0]]:void 0,m=i.schema??a?.schema??a?.itemSchema,h=V(m,r,s);if(!h)continue;const b=oe(i.examples,r,s),x=E(l)??E(i)??o;n[c]={...h,...i.description!==void 0&&{description:i.description},...i.example!==void 0&&{example:i.example},...b&&{examples:b},...A(x)},i.required&&t.push(c)}if(Object.keys(n).length!==0)return{type:"object",properties:n,...t.length>0?{required:t}:{}}}function Oe(e){if(typeof e=="string"||e&&typeof e=="object"&&"$$mdtype"in e||Array.isArray(e)&&e.length>0&&e.every(r=>!!r&&typeof r=="object"&&"$$mdtype"in r))return e}function F(e,r){const{storeCtx:s,options:o}=$.get(),n=s.document;return e.map(t=>{const c=t.schema;let l={};if(c&&typeof c=="object")l=c;else if(t.content&&typeof t.content=="object"){const b=t.content,x=Object.keys(b)[0],y=x?b[x]?.schema:void 0;y&&typeof y=="object"&&(l=y)}const i=H(s.schemaStore,s.hashIndex,{kind:B.JSON_SCHEMA,data:l}),p=t["x-badges"],a=l["x-badges"],m=Array.isArray(p)?p:Array.isArray(a)?a:void 0,h=G(t,o.showExtensions);return{name:String(t.name??""),in:typeof t.in=="string"?t.in:void 0,schemaId:i,description:Oe(t.description),required:t.required===!0?!0:void 0,deprecated:t.deprecated===!0?!0:void 0,example:t.example,examples:oe(t.examples,n,r),...m?.length?{badges:m}:{},...Object.keys(h).length?{extensions:h}:{},...A(E(t))}})}function oe(e,r,s){if(!e||typeof e!="object")return;const o={};for(const[n,t]of Object.entries(e)){if(!t||typeof t!="object")continue;const c=P(r,t,s)??t;if(!se(c))continue;const l=Z(c);o[n]={...typeof c.summary=="string"&&{summary:c.summary},...typeof c.description=="string"&&{description:c.description},...l!==void 0&&{value:typeof l=="string"?l:JSON.stringify(l)}}}return Object.keys(o).length>0?o:void 0}function ie(e,r){const{storeCtx:s,options:o}=$.get(),n=[],t=s.document,c=Re(e);if(c&&n.push(c),e.parameters&&Array.isArray(e.parameters)){const i=e.parameters.map(d=>Ce(d,t,r)),p=i.filter(d=>d.in==="header"),a=i.filter(d=>d.in==="query"),m=i.filter(d=>d.in==="path"),h=i.filter(d=>d.in==="cookie"),b=i.filter(d=>d.in==="querystring"),x=b.filter(d=>!d.content||typeof d.content!="object"),y=b.filter(d=>d.content&&typeof d.content=="object"),S=b.length>0;m.length>0&&n.push({nodeType:f.ITEM,variant:"path",label:"Path",labelTranslationKey:"path",parameters:F(m,r),pointer:e.pointer+"/parameters"}),a.length>0&&!S&&n.push({nodeType:f.ITEM,variant:"query",label:"Query",labelTranslationKey:"query",parameters:F(a,r),pointer:e.pointer+"/parameters"}),x.length>0&&n.push({nodeType:f.ITEM,variant:"querystring",label:"Query String",labelTranslationKey:"querystring",parameters:F(x,r),pointer:e.pointer+"/parameters"});for(const d of y){const g=d.content,T=Object.keys(g),C={};for(const M of T){const R=g[M];if(!R)continue;let I;const w=R.itemSchema,_=R.schema??w,u=V(_,t,r);u&&(I=H(s.schemaStore,s.hashIndex,{kind:B.JSON_SCHEMA,data:u}));const v=X(R,r);C[M]={schemaId:I,exampleIds:v,...A(E(_))}}const q=T[0],O=q?C[q]:void 0,k=K(d.description,o);n.push({nodeType:f.ITEM,variant:"querystring-body",label:String(d.name??""),required:d.required===!0?!0:void 0,mediaTypes:T.length>0?T:void 0,mediaTypeSchemas:Object.keys(C).length>0?C:void 0,schemaId:O?.schemaId,exampleIds:O?.exampleIds,pointer:e.pointer+"/parameters",...k!==void 0?{description:k}:{},...A(E(d))})}h.length>0&&n.push({nodeType:f.ITEM,variant:"cookies",label:"Cookies",labelTranslationKey:"cookie",parameters:F(h,r),pointer:e.pointer+"/parameters"}),p.length>0&&n.push({nodeType:f.ITEM,variant:"headers",label:"Headers",labelTranslationKey:"header",parameters:F(p,r),pointer:e.pointer+"/parameters"})}if(e.requestBody){const l=P(t,e.requestBody,r)??e.requestBody,i=z(t,l,r),p=i?Object.keys(i):void 0;let a,m,h;if(i&&p){h={};for(const d of p){const g=i[d];if(!g)continue;let T;const C=g.itemSchema,q=g.schema??C,O=V(q,t,r);O&&(T=H(s.schemaStore,s.hashIndex,{kind:B.JSON_SCHEMA,data:O}));const k=X(g,r,`${e.pointer}/requestBody/content/${N(d)}`);h[d]={schemaId:T,exampleIds:k,...A(E(q))}}const y=p[0],S=y?h[y]:void 0;a=S?.schemaId,m=S?.exampleIds}const b=K(l.description,o),x=E(e.requestBody)??E(l);n.push({nodeType:f.ITEM,variant:"body",label:"Request Body",labelTranslationKey:"body",required:l.required,mediaTypes:p,mediaTypeSchemas:h,schemaId:a,exampleIds:m,pointer:e.pointer+"/requestBody",...b!==void 0?{description:b}:{},...A(x)})}return n}function ce(e,r,s,o){if(!e.responses)return;const{storeCtx:n}=$.get(),t=n?.document??{},c=e.responses,i=Object.entries(c).filter(([p])=>ue(p)).map(([p,a])=>{const m=P(t,a,o)??a;let h=E(a)??E(m);const b=z(t,m,o),x=b?Object.keys(b):[],y=x[0],S=y&&b?b[y]:void 0;let d,g,T,C;if(b&&x.length>0){C={};for(const R of x){const I=b[R];if(!I)continue;let w;const _=I.itemSchema,u=I.schema??_,v=V(u,t,o);v&&(w=H(n.schemaStore,n.hashIndex,{kind:B.JSON_SCHEMA,data:v}));const D=X(I,o,`${e.pointer}/responses/${N(p)}/content/${N(R)}`);C[R]={schemaId:w,exampleIds:D,...A(E(u))}}const M=y?C[y]:void 0;d=M?.schemaId,g=M?.exampleIds}else if(S){const M=S.itemSchema,R=S.schema??M,I=V(R,t,o);I&&(h=h??E(R),d=H(n.schemaStore,n.hashIndex,{kind:B.JSON_SCHEMA,data:I})),g=X(S,o,y?`${e.pointer}/responses/${N(p)}/content/${N(y)}`:void 0)}const q=ge(m.headers,t,o);q&&(T=H(n.schemaStore,n.hashIndex,{kind:B.JSON_SCHEMA,data:q}));let O;m.description&&(O=K(m.description,r),W(O??[],s,`${ne}/${p}`));const k=m["x-summary"]?K(m["x-summary"],r):void 0;return k&&W(k,s,`${ne}/${p}/summary`),{code:p,summary:k,description:O,mediaType:y,mediaTypes:x.length>0?x:void 0,mediaTypeContent:C,schemaId:d,exampleIds:g,headers:m.headers,headerSchemaId:T,...A(h)}});return{nodeType:f.ITEM,variant:"responses",responses:i,pointer:e.pointer+"/responses"}}function X(e,r,s){const{storeCtx:o}=$.get(),n=[],t=o.document,c=s?.replace(/^\//,"");if(e.example!==void 0){const l=J(o.exampleStore,{value:e.example,...c&&{id:`${c}/example`}});n.push(l)}if(e.examples&&typeof e.examples=="object"){const l=E(e.examples);for(const[i,p]of Object.entries(e.examples)){if(i===U||!p||typeof p!="object")continue;const a=P(t,p,r)??p,m=E(p)??E(a)??l,h=J(o.exampleStore,{value:Z(a),key:i,summary:typeof a.summary=="string"?a.summary:i,description:typeof a.description=="string"?a.description:void 0,externalValue:typeof a.externalValue=="string"?a.externalValue:void 0,...A(m),...c&&{id:`${c}/examples/${N(i)}`}});n.push(h)}}return n.length>0?n:void 0}function Re(e){const{storeCtx:r,options:s}=$.get();if(!e.security||!Array.isArray(e.security)||e.security.length===0)return;const o=e.security.map(n=>{const t=Object.entries(n);if(t.length===0)return null;const c=r?.document?.components?.securitySchemes,l=t.map(([i,p])=>{const a=r?.securitySchemeStore[i],m=E(c?.[i])??a?.[U];return{name:i,scopes:Array.isArray(p)?p:void 0,type:a?.type,scheme:a?.scheme,bearerFormat:a?.bearerFormat,in:a?.in,paramName:a?.paramName,description:a?.description?K(a.description,s):a?.description,openIdConnectUrl:a?.openIdConnectUrl,oauth2MetadataUrl:a?.oauth2MetadataUrl,deprecated:a?.deprecated,flows:a?.flows,...A(m)}}).filter(i=>i.name);return l.length>0?{schemes:l}:null}).filter(n=>n!==null);if(o.length!==0)return{nodeType:f.SECURITY,requirements:o}}function Ae(e,r,s,o){const{storeCtx:n,options:t}=$.get();if(!n)throw new Error("OpenAPI store context is not initialized");return ye(e,n,t,r,s,o)}export{we as buildItemContent,xe as createCallbackIdFactory};
|
|
1
|
+
import{REDOCLY_TEAMS_RBAC as U}from"@redocly/config";import{contentType as le,itemVariant as me,nodeTypes as f,panelKind as Y,schemaKind as B}from"../../../../types/common.js";import{readRbacScope as E,rbacProp as A,registerExample as J,pickRenderableDescription as ee,registerSchema as H,resolveContent as z,resolveRef as P}from"../../../helpers.js";import{applyIgnoreNamedSchemasDeep as te}from"../../utils/applyIgnoreNamedSchemasDeep.js";import{isStatusCode as ue}from"../../../../utils/status-code.js";import{parseMarkdown as K}from"../../../utils/parseMarkdown.js";import{extractDescriptionSegments as ye,resolveMarkdocHeadingIds as W}from"../../../utils/markdoc.js";import{getExtensionsForDisplay as G}from"../../../../utils/extract-extensions.js";import{openApiContext as $}from"../../buildContext.js";import{buildCodeSampleSource as he}from"../../build-code-sample-source.js";import{mergeInMockServer as fe,pickOperationServers as be}from"../../utils/merge-mock-server.js";import{normalizePath as xe,toRelativePath as se}from"../../../../utils/url.js";import{encodeJsonPointerSegment as N}from"../../../../utils/refPointer.js";import{hasOpenApiExampleValue as ne,resolveOpenApiExampleValue as Z}from"../../resolve-openapi-example-value.js";const Q="request",re="responses",oe="callbacks";function Se(){const e=new Map;return(r,s)=>{const o=`${r}/${s}`,n=e.get(o)??0;return e.set(o,n+1),n===0?o:`${o}~${n}`}}function Le(e,r){const{options:s,storeCtx:o,basePath:n}=$.get(),t=e.summary||e.operationId||e.pathName||"Unknown Operation",c=[],{feedback:l}=s,i=e.isWebhook||!1,p=[{nodeType:f.HEADER,level:2,label:t,badges:e["x-badges"],isWebhook:i,deprecated:e.deprecated,showPageActions:!0}],a=G(e,s.showExtensions);Object.keys(a).length>0&&p.push({nodeType:f.EXTENSIONS,extensions:a}),c.push({nodeType:f.CONTAINER,children:p,panels:[]});const u=s.ignoreNamedSchemas,h=e["x-codeSamples"]?.map(({lang:m,label:v,source:D})=>({lang:m,label:v,source:D})),b=be(e.servers,o?.document?.servers),x=fe(b.filter(m=>typeof m?.url=="string"),s.mockServer).map(m=>{const v=E(m);return{url:m.url??"",name:m.name,description:typeof m.description=="string"?m.description:void 0,...m.isMockServer&&{isMockServer:!0},variables:m.variables&&Object.keys(m.variables).length>0?Object.fromEntries(Object.entries(m.variables).map(([D,L])=>[D,{default:L.default}])):void 0,...A(v)}}),y=ce(e,u),S=se(r,n);let d=[];e.description&&(W(e.description,S,Q),d=ye(e.description,s));const g=d.some(m=>m.kind==="schemaDefinition"),T=y.find(m=>m.nodeType===f.ITEM&&m.variant==="body"),C=ve(e,u,i,S||void 0),q=T?.schemaId,R=T?.mediaTypes,k=T?.mediaTypeSchemas,M=E(T),O=[{children:[{kind:Y.CODE_SAMPLE,source:C,definitionSamples:h?.length?h:void 0,isWebhook:i,hideReplay:e["x-hideReplay"]===!0,servers:x?.length?x:void 0,schemaId:q,exampleIds:T?.exampleIds,mediaTypes:R,mediaTypeSchemas:k,examples:T?.exampleIds?.map(()=>({}))??[]}],...A(M)}];if(y.length>0||d.length>0)if(g){c.push({nodeType:f.CONTAINER,children:[{nodeType:f.HEADER,level:4,label:"Request",labelTranslationKey:"request",deepLinkSuffix:Q}],panels:[]});for(const m of d)m.kind==="schemaDefinition"?c.push(m.node):c.push({nodeType:f.CONTAINER,children:[m.node],panels:[]});c.push({nodeType:f.CONTAINER,children:[...y],panels:O})}else c.push({nodeType:f.CONTAINER,children:[{nodeType:f.HEADER,level:4,label:"Request",labelTranslationKey:"request",deepLinkSuffix:Q},...d.map(m=>m.node),...y],panels:O});else c.push({nodeType:f.CONTAINER,children:[{nodeType:f.HEADER,level:4,label:"Request",labelTranslationKey:"request",deepLinkSuffix:Q},{nodeType:f.EMPTY_MESSAGE,label:"No request data",labelTranslationKey:"noRequestData"}],panels:O});if(e.responses){const m=ae(e,s,S,u);if(m){const v=m.responses?.some(j=>j.schemaId||(j.exampleIds?.length??0)>0),D=m?.responses?.map(j=>{const pe=j[U];return{code:j.code,schemaId:j.schemaId,exampleIds:j.exampleIds,mediaTypes:j.mediaTypes,mediaTypeContent:j.mediaTypeContent,...A(pe)}}),L=[];v&&L.push({children:[{kind:Y.RESPONSE,headerTitle:"Response",responseCodes:D,examples:[]}]});const de=E(e.responses);c.push({nodeType:f.CONTAINER,children:[{nodeType:f.HEADER,level:4,label:"Responses",labelTranslationKey:"responses",deepLinkSuffix:"responses"},m],panels:L.length>0?L:[],...A(de)})}}Array.isArray(e.callbacks)&&e.callbacks.length>0&&c.push(...Te(e,S,u)),l?.hide!==!0&&c.push({nodeType:f.CONTAINER,children:[{nodeType:f.FEEDBACK,pageSlug:xe(se(r,n))}],panels:[]});const _=y.some(m=>{const v=m;return v.variant==="body"&&((v.exampleIds?.length??0)>0||!!v.schemaId)})||(h?.length??0)>0;return{contentType:le.ITEM,itemVariant:me.HTTP_ITEM,seo:e["x-seo"],meta:{sourceId:e.operationId,name:t,deprecated:e.deprecated,isWebhook:e.isWebhook||!1,pointer:e.pointer,hasSamples:_},children:c}}function Te(e,r,s){const o=[{nodeType:f.CONTAINER,children:[{nodeType:f.HEADER,level:4,label:"Callbacks",labelTranslationKey:"callbacks",deepLinkSuffix:oe}],panels:[]}],n=Se();for(const t of e.callbacks??[])if(t.operations)for(const c of t.operations){const l=c.httpVerb??"post",i=n(t.name,l);o.push(Ee(e,t,c,i,r,s))}return o}function Ee(e,r,s,o,n,t){const{options:c}=$.get(),l=s.httpVerb??"post",i={pointer:e.pointer+"/callbacks/"+r.name+"/"+l,pathName:s.pathName??r.url??"",httpVerb:l,summary:s.summary,deprecated:s.deprecated,isWebhook:!1,isAdditionalOperation:!1,tags:[],parameters:s.parameters,requestBody:s.requestBody,responses:s.responses,servers:s.servers,security:s.security},p=ce(i,t),a=ae(i,c,`${n}/callbacks/${o}`,t),u=[...p];a&&u.push(a);const h=s.externalDocs,b=G(s,c.showExtensions);let x;s.description&&(x=K(s.description,c),W(x??[],n,`${oe}/${o}`));const y={httpVerb:l,pathName:i.pathName,summary:i.summary,operationId:typeof s.operationId=="string"?s.operationId:void 0,description:x,deprecated:i.deprecated,callbackName:r.name,callbackId:o,externalDocs:h?{url:h.url,description:h.description}:void 0,extensions:Object.keys(b).length>0?b:void 0,contentChildren:u.length>0?u:void 0},S=Ce(s,i,o,t),d=E(r);return{nodeType:f.CONTAINER,children:[{nodeType:f.ITEM,variant:"callback",callback:y,pointer:e.pointer+"/callbacks"}],panels:S,...A(d)}}function Ce(e,r,s,o){const{storeCtx:n}=$.get(),t=[];if(!e.requestBody||!("content"in e.requestBody))return t;const c=n?.document??{},l=P(c,e.requestBody,o)??e.requestBody,i=z(c,l,o);if(!i)return t;const p=Object.keys(i);let a=!1;const u={};for(const[y,S]of Object.entries(i)){let d;if(S.schema){const C=S.schema;d=H(n.schemaStore,n.hashIndex,{kind:B.JSON_SCHEMA,data:C})}const g=`${r.pointer}/requestBody/content/${N(y)}`.replace(/^\//,""),T=[];if(S.example!==void 0){const C=J(n.exampleStore,{value:S.example,id:`${g}/example`});T.push(C),a=!0}if(S.examples)for(const[C,q]of Object.entries(S.examples)){const R=P(c,q,o);if(R&&ne(R)){const k=J(n.exampleStore,{value:Z(R),summary:R.summary??C,description:ee(R.description),id:`${g}/examples/${N(C)}`});T.push(k),a=!0}}u[y]={schemaId:d,exampleIds:T.length>0?T:void 0},d&&(a=!0)}const h=e["x-codeSamples"];if(!(a||(h?.length??0)>0))return t;const x=e.servers?.filter(y=>y.url).map(({url:y,name:S,description:d,variables:g})=>({url:y,name:S,description:d,variables:g}));return t.push({children:[{kind:Y.CALLBACK_PAYLOAD,callbackName:s,path:r.pathName,httpVerb:r.httpVerb,servers:x?.length?x:void 0,definitionSamples:h,mediaTypes:p.length>0?p:void 0,mediaTypeSchemas:Object.keys(u).length>0?u:void 0,examples:[]}]}),t}function ge(e,r,s){const o=P(r,e,s)??e,{$ref:n,...t}=e,c=typeof n=="string"?{...o,...t}:o;return te(c,s)}function V(e,r,s){if(!e||typeof e!="object")return;const o=e,n=P(r,o,s)??o;return te(n,s)}function Re(e,r,s){if(!e||typeof e!="object")return;const o=E(e),n={},t=[];for(const[c,l]of Object.entries(e)){if(c===U)continue;const i=P(r,l,s)??l,p=i.content,a=p?p[Object.keys(p)[0]]:void 0,u=i.schema??a?.schema??a?.itemSchema,h=V(u,r,s);if(!h)continue;const b=ie(i.examples,r,s),x=E(l)??E(i)??o;n[c]={...h,...i.description!==void 0&&{description:i.description},...i.example!==void 0&&{example:i.example},...b&&{examples:b},...A(x)},i.required&&t.push(c)}if(Object.keys(n).length!==0)return{type:"object",properties:n,...t.length>0?{required:t}:{}}}function Oe(e){if(typeof e=="string"||e&&typeof e=="object"&&"$$mdtype"in e||Array.isArray(e)&&e.length>0&&e.every(r=>!!r&&typeof r=="object"&&"$$mdtype"in r))return e}function F(e,r){const{storeCtx:s,options:o}=$.get(),n=s.document;return e.map(t=>{const c=t.schema;let l={};if(c&&typeof c=="object")l=c;else if(t.content&&typeof t.content=="object"){const b=t.content,x=Object.keys(b)[0],y=x?b[x]?.schema:void 0;y&&typeof y=="object"&&(l=y)}const i=H(s.schemaStore,s.hashIndex,{kind:B.JSON_SCHEMA,data:l}),p=t["x-badges"],a=l["x-badges"],u=Array.isArray(p)?p:Array.isArray(a)?a:void 0,h=G(t,o.showExtensions);return{name:String(t.name??""),in:typeof t.in=="string"?t.in:void 0,schemaId:i,description:Oe(t.description),required:t.required===!0?!0:void 0,deprecated:t.deprecated===!0?!0:void 0,example:t.example,examples:ie(t.examples,n,r),...u?.length?{badges:u}:{},...Object.keys(h).length?{extensions:h}:{},...A(E(t))}})}function ie(e,r,s){if(!e||typeof e!="object")return;const o={};for(const[n,t]of Object.entries(e)){if(!t||typeof t!="object")continue;const c=P(r,t,s)??t;if(!ne(c))continue;const l=Z(c);o[n]={...typeof c.summary=="string"&&{summary:c.summary},...typeof c.description=="string"&&{description:c.description},...l!==void 0&&{value:typeof l=="string"?l:JSON.stringify(l)}}}return Object.keys(o).length>0?o:void 0}function ce(e,r){const{storeCtx:s,options:o}=$.get(),n=[],t=s.document,c=Ae(e);if(c&&n.push(c),e.parameters&&Array.isArray(e.parameters)){const i=e.parameters.map(d=>ge(d,t,r)),p=i.filter(d=>d.in==="header"),a=i.filter(d=>d.in==="query"),u=i.filter(d=>d.in==="path"),h=i.filter(d=>d.in==="cookie"),b=i.filter(d=>d.in==="querystring"),x=b.filter(d=>!d.content||typeof d.content!="object"),y=b.filter(d=>d.content&&typeof d.content=="object"),S=b.length>0;u.length>0&&n.push({nodeType:f.ITEM,variant:"path",label:"Path",labelTranslationKey:"path",parameters:F(u,r),pointer:e.pointer+"/parameters"}),a.length>0&&!S&&n.push({nodeType:f.ITEM,variant:"query",label:"Query",labelTranslationKey:"query",parameters:F(a,r),pointer:e.pointer+"/parameters"}),x.length>0&&n.push({nodeType:f.ITEM,variant:"querystring",label:"Query String",labelTranslationKey:"querystring",parameters:F(x,r),pointer:e.pointer+"/parameters"});for(const d of y){const g=d.content,T=Object.keys(g),C={};for(const M of T){const O=g[M];if(!O)continue;let I;const w=O.itemSchema,_=O.schema??w,m=V(_,t,r);m&&(I=H(s.schemaStore,s.hashIndex,{kind:B.JSON_SCHEMA,data:m}));const v=X(O,r);C[M]={schemaId:I,exampleIds:v,...A(E(_))}}const q=T[0],R=q?C[q]:void 0,k=K(d.description,o);n.push({nodeType:f.ITEM,variant:"querystring-body",label:String(d.name??""),required:d.required===!0?!0:void 0,mediaTypes:T.length>0?T:void 0,mediaTypeSchemas:Object.keys(C).length>0?C:void 0,schemaId:R?.schemaId,exampleIds:R?.exampleIds,pointer:e.pointer+"/parameters",...k!==void 0?{description:k}:{},...A(E(d))})}h.length>0&&n.push({nodeType:f.ITEM,variant:"cookies",label:"Cookies",labelTranslationKey:"cookie",parameters:F(h,r),pointer:e.pointer+"/parameters"}),p.length>0&&n.push({nodeType:f.ITEM,variant:"headers",label:"Headers",labelTranslationKey:"header",parameters:F(p,r),pointer:e.pointer+"/parameters"})}if(e.requestBody){const l=P(t,e.requestBody,r)??e.requestBody,i=z(t,l,r),p=i?Object.keys(i):void 0;let a,u,h;if(i&&p){h={};for(const d of p){const g=i[d];if(!g)continue;let T;const C=g.itemSchema,q=g.schema??C,R=V(q,t,r);R&&(T=H(s.schemaStore,s.hashIndex,{kind:B.JSON_SCHEMA,data:R}));const k=X(g,r,`${e.pointer}/requestBody/content/${N(d)}`);h[d]={schemaId:T,exampleIds:k,...A(E(q))}}const y=p[0],S=y?h[y]:void 0;a=S?.schemaId,u=S?.exampleIds}const b=K(l.description,o),x=E(e.requestBody)??E(l);n.push({nodeType:f.ITEM,variant:"body",label:"Request Body",labelTranslationKey:"body",required:l.required,mediaTypes:p,mediaTypeSchemas:h,schemaId:a,exampleIds:u,pointer:e.pointer+"/requestBody",...b!==void 0?{description:b}:{},...A(x)})}return n}function ae(e,r,s,o){if(!e.responses)return;const{storeCtx:n}=$.get(),t=n?.document??{},c=e.responses,i=Object.entries(c).filter(([p])=>ue(p)).map(([p,a])=>{const u=P(t,a,o)??a;let h=E(a)??E(u);const b=z(t,u,o),x=b?Object.keys(b):[],y=x[0],S=y&&b?b[y]:void 0;let d,g,T,C;if(b&&x.length>0){C={};for(const O of x){const I=b[O];if(!I)continue;let w;const _=I.itemSchema,m=I.schema??_,v=V(m,t,o);v&&(w=H(n.schemaStore,n.hashIndex,{kind:B.JSON_SCHEMA,data:v}));const D=X(I,o,`${e.pointer}/responses/${N(p)}/content/${N(O)}`);C[O]={schemaId:w,exampleIds:D,...A(E(m))}}const M=y?C[y]:void 0;d=M?.schemaId,g=M?.exampleIds}else if(S){const M=S.itemSchema,O=S.schema??M,I=V(O,t,o);I&&(h=h??E(O),d=H(n.schemaStore,n.hashIndex,{kind:B.JSON_SCHEMA,data:I})),g=X(S,o,y?`${e.pointer}/responses/${N(p)}/content/${N(y)}`:void 0)}const q=Re(u.headers,t,o);q&&(T=H(n.schemaStore,n.hashIndex,{kind:B.JSON_SCHEMA,data:q}));let R;u.description&&(R=K(u.description,r),W(R??[],s,`${re}/${p}`));const k=u["x-summary"]?K(u["x-summary"],r):void 0;return k&&W(k,s,`${re}/${p}/summary`),{code:p,summary:k,description:R,mediaType:y,mediaTypes:x.length>0?x:void 0,mediaTypeContent:C,schemaId:d,exampleIds:g,headers:u.headers,headerSchemaId:T,...A(h)}});return{nodeType:f.ITEM,variant:"responses",responses:i,pointer:e.pointer+"/responses"}}function X(e,r,s){const{storeCtx:o}=$.get(),n=[],t=o.document,c=s?.replace(/^\//,"");if(e.example!==void 0){const l=J(o.exampleStore,{value:e.example,...c&&{id:`${c}/example`}});n.push(l)}if(e.examples&&typeof e.examples=="object"){const l=E(e.examples);for(const[i,p]of Object.entries(e.examples)){if(i===U||!p||typeof p!="object")continue;const a=P(t,p,r)??p,u=E(p)??E(a)??l,h=J(o.exampleStore,{value:Z(a),key:i,summary:typeof a.summary=="string"?a.summary:i,description:ee(a.description),externalValue:typeof a.externalValue=="string"?a.externalValue:void 0,...A(u),...c&&{id:`${c}/examples/${N(i)}`}});n.push(h)}}return n.length>0?n:void 0}function Ae(e){const{storeCtx:r,options:s}=$.get();if(!e.security||!Array.isArray(e.security)||e.security.length===0)return;const o=e.security.map(n=>{const t=Object.entries(n);if(t.length===0)return null;const c=r?.document?.components?.securitySchemes,l=t.map(([i,p])=>{const a=r?.securitySchemeStore[i],u=E(c?.[i])??a?.[U];return{name:i,scopes:Array.isArray(p)?p:void 0,type:a?.type,scheme:a?.scheme,bearerFormat:a?.bearerFormat,in:a?.in,paramName:a?.paramName,description:a?.description?K(a.description,s):a?.description,openIdConnectUrl:a?.openIdConnectUrl,oauth2MetadataUrl:a?.oauth2MetadataUrl,deprecated:a?.deprecated,flows:a?.flows,...A(u)}}).filter(i=>i.name);return l.length>0?{schemes:l}:null}).filter(n=>n!==null);if(o.length!==0)return{nodeType:f.SECURITY,requirements:o}}function ve(e,r,s,o){const{storeCtx:n,options:t}=$.get();if(!n)throw new Error("OpenAPI store context is not initialized");return he(e,n,t,r,s,o)}export{Le as buildItemContent,Se as createCallbackIdFactory};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{schemaKind as w}from"../../types/common.js";import{registerSchema as
|
|
1
|
+
import{schemaKind as w}from"../../types/common.js";import{encodeJsonPointerSegment as O}from"../../utils/refPointer.js";import{getImplicitDiscriminatorChildren as k}from"../../services/schema/dialects/jsonSchema.js";import{registerSchema as A,registerExample as C,pickRenderableDescription as I,registerSecurityScheme as E,resolveRef as g,isRecord as y,readRbacScope as S,rbacProp as b,splitRbacSection as R}from"../helpers.js";import{applyIgnoreNamedSchemasDeep as v}from"./utils/applyIgnoreNamedSchemasDeep.js";import{parseMarkdown as M}from"../utils/parseMarkdown.js";import{resolveOpenApiExampleValue as N}from"./resolve-openapi-example-value.js";const V=["x-defaultClientId","x-defaultAccessToken","x-defaultTokenType","x-defaultClientSecret","x-defaultUsername","x-defaultPassword"];function U(c){const o={},r=c;for(const n of V)r[n]&&(o[n]=r[n]);return r["x-serverValues"]&&(o.serverValues=r["x-serverValues"]),o}function j(c){const o=c.components?.schemas;if(!o||typeof o!="object")return;const r=k(c);for(const[n,l]of Object.entries(o)){if(!y(l))continue;const a=l,{discriminator:f}=a;if(!f?.propertyName||f.mapping||f["x-explicitMappingOnly"]||Array.isArray(a.oneOf)||Array.isArray(a.anyOf))continue;const m=r[`#/components/schemas/${O(n)}`];if(!m?.length)continue;const d={};for(const{ref:s,value:x}of m)d[x]=s;o[n]={...a,discriminator:{...f,mapping:d}}}}function K(c,o,r){const{schemaStore:n,exampleStore:l,securitySchemeStore:a,hashIndex:f}=o,{ignoreNamedSchemas:m}=r,d=o.document;j(c);const s=c.components,x=c["x-root"];if(y(x)){const p=v(x,m),i=y(p)?p:x;A(n,f,{id:"x-root",kind:w.JSON_SCHEMA,title:typeof i.title=="string"?i.title:"Root",data:i})}if(!s)return{schemaStore:n,exampleStore:l,securitySchemeStore:a};if(s.schemas){const{sectionRbac:p,entries:i}=R(s.schemas);for(const[u,t]of i){const e=g(d,t,m)??t,h=v(e,m);y(h)&&A(n,f,{id:`components/schemas/${u}`,kind:w.JSON_SCHEMA,title:typeof h.title=="string"?h.title:u,data:h,...b(p)})}}if(s.examples){const{sectionRbac:p,entries:i}=R(s.examples);for(const[u,t]of i){const e=g(d,t,m)??t;!e||typeof e!="object"||C(l,{id:`components/examples/${u}`,value:N(e),summary:typeof e.summary=="string"?e.summary:void 0,description:I(e.description),externalValue:e.externalValue,...b(S(t)??S(e)??p)})}}if(s.securitySchemes){const{sectionRbac:p,entries:i}=R(s.securitySchemes);for(const[u,t]of i){if(!t||typeof t!="object")continue;const e=g(d,t,m)??t;if(!e)continue;const h={id:u,type:e.type,scheme:e.scheme,bearerFormat:e.bearerFormat,description:e.description?M(e.description,r):void 0,in:e.in,paramName:e.name,openIdConnectUrl:e.openIdConnectUrl,oauth2MetadataUrl:e.oauth2MetadataUrl,deprecated:e.deprecated,flows:e.flows,...U(e),...b(S(t)??S(e)??p)};E(a,h)}}return{schemaStore:n,exampleStore:l,securitySchemeStore:a}}export{K as populateOpenApiStore};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{Fragment as N,jsx as e,jsxs as y}from"react/jsx-runtime";import{useState as u,useContext as L,useEffect as _,useMemo as g,useCallback as B}from"react";import{styled as F}from"styled-components";import{useAtomValue as K}from"jotai";import{CodeBlockPanel as V,StyledCodeBlock as H}from"../styled.js";import{useResolvedExamples as Y,useExampleEntries as $}from"../../ItemContent/hooks.js";import{useBodySamplingSchemaId as O,useMediaTypeContent as R}from"./hooks.js";import{
|
|
1
|
+
import{Fragment as N,jsx as e,jsxs as y}from"react/jsx-runtime";import{useState as u,useContext as L,useEffect as _,useMemo as g,useCallback as B}from"react";import{styled as F}from"styled-components";import{useAtomValue as K}from"jotai";import{CodeBlockPanel as V,StyledCodeBlock as H}from"../styled.js";import{useResolvedExamples as Y,useExampleEntries as $}from"../../ItemContent/hooks.js";import{useBodySamplingSchemaId as O,useMediaTypeContent as R}from"./hooks.js";import{ExampleDescription as U,ExampleSelector as W,MediaTypeSelector as q,PayloadDisplay as z}from"./selectors.js";import{StyledPanelHeader as G}from"./styled.js";import{ServerDropdown as J}from"./ServerDropdown.js";import{LanguageDropdown as Q}from"../LanguageItem/LanguageDropdown.js";import{itemStoreFieldAtom as X}from"../../../jotai/itemStore.js";import{ItemIdContext as Z}from"../../../hooks/useDeepLinkSection.js";import{getSyntaxHighlightLang as ee}from"../../../utils/languages.js";import{useSpecTranslate as ae}from"../../../hooks/useTranslate.js";import{useCopyCodeTelemetry as te}from"../../../hooks/useCopyCodeTelemetry.js";const m="payload",oe=F.div`
|
|
2
2
|
min-width: 0;
|
|
3
3
|
overflow: hidden;
|
|
4
4
|
flex: 1 1 auto;
|
|
5
|
-
`;function
|
|
5
|
+
`;function Ce({node:a}){const x=ae(),h=L(Z)??"",S=K(X({itemId:h,key:"selectedCallback"})),p=a.callbackName,t=a.definitionSamples,C=p!=null&&S===p,{mediaTypes:b,activeMediaType:l,effectiveSchemaId:v,effectiveExampleIds:s,onMediaTypeChange:k}=R(a),E=O(v,l),d=Y(E,s,"response",l),I=$(s),[i,f]=u(0),[n,T]=u(m);_(()=>f(0),[s,l]);const D=d[i]??d[0],P=I[i]?.description,M=g(()=>{const o=[{key:m,lang:"json",title:"Payload"}];if(t)for(const c of t){const A=`x-${c.lang}`;o.push({key:A,lang:c.lang,title:c.label||c.lang})}return o},[t]),r=g(()=>{if(!(n===m||!t))return t.find(o=>`x-${o.lang}`===n)},[n,t]),j=te("response"),w=B(o=>T(o),[]);return C?e(V,{className:"panel-callback-samples",header:()=>y(G,{isExpandable:!1,children:[e(oe,{children:e(J,{servers:a.servers??[],method:(a.httpVerb??"post").toUpperCase(),path:a.path??"Callback"})}),e(Q,{activeTab:n,samples:M,onChange:w})]}),isExpandable:!1,children:r?e(H,{lang:ee(r.lang),source:r.source,header:{className:"code-block-header",controls:{copy:{onClick:j(r.lang)}}}}):y(N,{children:[e(q,{mediaTypes:b,value:l,onChange:k,label:x("contentType","Payload media type")}),e(W,{exampleIds:s,selectedIdx:i,onSelect:f}),e(U,{description:P}),e(z,{payload:D,emptyMessage:"// No callback payload",mediaType:l})]})}):null}export{Ce as CallbackPayloadItem};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Fragment as
|
|
1
|
+
import{Fragment as je,jsx as n,jsxs as ie}from"react/jsx-runtime";import{useState as Ge,useMemo as m,useCallback as W,useEffect as Fe,useContext as We}from"react";import{useAtom as ce}from"jotai";import{useAtomValue as L,useSetAtom as _e}from"jotai";import{buildCodeSampleHAR as He,tryGenerateCodeSample as ze,mapReplayAtomValuesToHarRequestValues as Je,useCodeSampleResolvers as Ye}from"../../../services/code-samples/index.js";import{findExampleIdByKey as Qe}from"../../../services/code-samples/example-key.js";import{exampleStoreAtom as Xe}from"../../../jotai/examples.js";import{itemStoreAtom as Ze,itemStoreFieldAtom as et}from"../../../jotai/itemStore.js";import{ItemIdContext as tt}from"../../../hooks/useDeepLinkSection.js";import{DEFAULT_LANGUAGES as pe,getGeneratorKey as rt,getLangKey as B,getSyntaxHighlightLang as at}from"../../../utils/languages.js";import{useSpecTranslate as ot}from"../../../hooks/useTranslate.js";import{CodeBlockPanel as st,StyledCodeBlock as nt}from"../styled.js";import{useResolvedExamples as lt}from"../../ItemContent/hooks.js";import{languageAtom as it,environmentAtom as ct,selectedSecuritySchemeIdxAtom as pt,requestValuesAtom as mt}from"../../../jotai/app.js";import{useActiveVariantSchemaId as dt,useSchemaVariantSelection as ut,useMediaTypeContent as yt}from"./hooks.js";import{isSequentialMediaType as ft}from"../../../utils/media-type.js";import{isRecord as me}from"../../../adapters/helpers.js";import{updateObjectProperties as ht}from"../../../adapters/openapi/configure/merge-utils.js";import{useCopyCodeTelemetry as St}from"../../../hooks/useCopyCodeTelemetry.js";import{VariantPicker as gt,ExampleDescription as vt,ExampleSelector as xt,MediaTypeSelector as kt,PanelDropdownSelect as bt,PayloadDisplay as Et}from"./selectors.js";import{LanguageDropdown as Vt}from"../LanguageItem/LanguageDropdown.js";import{StyledPanelHeader as At,TryItPanelFooter as Ct}from"./styled.js";import{MediaTypeRow as qt}from"./styled.js";import{ServerDropdown as Lt}from"./ServerDropdown.js";import{replaceServerVariables as It,serverMatchesUrl as Tt}from"../../../services/code-samples/server-variables.js";import{globalOptionsAtom as Rt}from"../../../jotai/store.js";import{createLanguageSwitchEvent as Ut}from"../../../events/languageSwitch.js";import{createCodeSampleCopyEvent as $t}from"../../../events/codeSampleCopy.js";import{Replay as Dt}from"../../Replay/index.js";import{useOpenApiDefinition as Ot}from"../../../hoc/withReplayPrefetch.js";import{pickReplayDefinitionDownloadUrl as Pt}from"../../../utils/fetch-openapi-definition.js";const _=pe.find(r=>r.key==="payload")??pe[0],de=[{key:_.key,lang:_.lang,title:_.label}];function Sr({node:r}){const[{activeLanguage:g,languages:c},v]=ce(it),s=L(Rt),x=ot(),ue=Ot(),K=r.isWebhook?"payload":g||"curl",H=Ye(),t=r.source,E=r.definitionSamples,ye=L(mt),S=L(Xe),fe=`${t.method.toLowerCase()}:${t.path}`,I=ye[fe],z=I?.activeExampleName,T=typeof z=="string"?z:void 0,{mediaTypes:J,activeMediaType:d,effectiveSchemaId:R,effectiveExampleIds:i,onMediaTypeChange:he}=yt(r),Se=r.isWebhook?"response":"request",ge=ut(i?.length?void 0:R),ve=dt(R),xe=ft(d)?R:ve,Y=lt(xe,i,Se,d),Q=We(tt)??"",U=_e(Ze(Q)),ke=L(et({itemId:Q,key:"activeExampleKey"}));Fe(()=>{if(!T)return;const e=S[T]?.key??T;U({activeExampleKey:e})},[T,S,U]);const k=`${d}|${i?.join(",")}`,X=Qe(i,ke||void 0,e=>S[e]),Z=X?i?.indexOf(X)??-1:-1,[$,ee]=Ge({contentKey:k,idx:0}),V=Z>=0?Z:$.contentKey===k?$.idx:0;($.idx!==V||$.contentKey!==k)&&ee({contentKey:k,idx:V});const be=W(e=>{ee({contentKey:k,idx:e});const a=i?.[e],o=a?S[a]?.key:void 0;U({activeExampleKey:o??""})},[k,i,S,U]),A=Y[V]??Y[0],te=(i?.length??0)>0||!!R,D=m(()=>{if(!E?.length)return E;const e=new Set((c??[]).map(a=>a.key));return E.filter(a=>e.has(B(a)))},[E,c]),f=m(()=>{const e=(c??[]).map(({key:o,lang:l,title:q})=>({key:o,lang:l,title:q}));let a=te?e:e.filter(o=>o.key!=="payload");if(r.isWebhook){const o=new Set(D?.map(l=>B(l))??[]);a=a.filter(l=>l.key==="payload"||o.has(l.key))}return a},[te,c,r.isWebhook,D]),u=m(()=>(f.some(e=>e.key===K)?K:f[0]?.key)??"curl",[f,K]),O=L(ct),{activeServerUrl:re,activeServerSpecUrl:h}=m(()=>{const e=O[0].server,a=e?r.servers?.find(l=>Tt(l,e)):void 0;if(e&&a)return{activeServerUrl:e,activeServerSpecUrl:a.url};const o=r.servers?.[0];return o?{activeServerUrl:It(o),activeServerSpecUrl:o.url}:{activeServerUrl:t.servers[0]?.url,activeServerSpecUrl:t.servers[0]?.url}},[O,r.servers,t.servers]),[M,Ee]=ce(pt),p=t.securityGroups,Ve=!!(p&&p.length>1),ae=m(()=>{if(!p?.length)return;const e=p.length>1?p[M]??p[0]:p[0];return Object.keys(e)},[p,M]),oe=m(()=>{const e=Je(I??{});return t.requestValues?.security?{...e,security:t.requestValues.security}:e},[I,t.requestValues?.security]),C=I?.body,P=i?.[V],w=P?S[P]?.key??P:void 0,b=m(()=>{const e=t.requestValues?.serverBody;return(h&&e?.[h])??t.requestValues?.body},[h,t.requestValues?.body,t.requestValues?.serverBody]),Ae=m(()=>C!==void 0?wt(C):b!==void 0?A===void 0?b:me(A)&&me(b)?ht(A,b):b:A,[C,A,b]),Ce=m(()=>{if(u==="payload")return"";const e=D?.find(y=>B(y)===u);if(e){let y=e.source;const F=t.requestValues?.envVariables,Be=t.requestValues?.serverEnvVariables,Ke={...F,...h&&Be?.[h]};for(const[Me,Ne]of Object.entries(Ke))y=y.replaceAll(`{{${Me}}}`,Ne);return y}const a=He(t,{serverUrl:re,mediaType:d,environment:O[0]??{},requestValues:oe,activeSecuritySchemeIds:ae,replayBody:C,exampleName:w},{skipOptionalParameters:s.codeSamples?.skipOptionalParameters,withOAuth2Call:s.codeSamples?.withOAuth2Call,generatedPayloadSamplesMaxDepth:s.generatedSamplesMaxDepth},H),o=s.codeSamples?.languages?.find(y=>y.key===u),l=ze(o?rt(o):u,a,o?.options);if(l.kind==="unsupported-language")return`// ${x("unsupportedLanguage","Language is not supported.")}`;if(l.kind==="error")return console.error(l.error),`// ${x("failedToGenerateCodeSample","Failed to generate code sample.")}`;let q=l.source;const Oe=t.requestValues?.envVariables,Pe=t.requestValues?.serverEnvVariables,we={...Oe,...h&&Pe?.[h]};for(const[y,F]of Object.entries(we))q=q.replaceAll(`{{${y}}}`,F);return q},[u,D,t,re,h,d,O,s,H,oe,ae,C,w,x]),N=f.find(e=>e.key===u)??f[0],se=E?.find(e=>B(e)===u),j=se?.lang??N?.lang,qe=j&&at(j),ne=St("request"),Le=W(e=>()=>{ne(e)(),s.events?.codeSamplesCopy?.($t({operation:{id:`${t.method}:${t.path}`,path:t.path,httpVerb:t.method,name:`${t.method.toUpperCase()} ${t.path}`},type:"request",lang:e??"",label:N?.title??"",activeMimeName:d??"",activeExampleName:w}))},[ne,s.events,t.method,t.path,N,d,w]),Ie=W(e=>{v(e);const a=(r.isWebhook?de:f).find(o=>o.key===e);s.events?.codeSamplesLanguageSwitch&&a&&s.events.codeSamplesLanguageSwitch(Ut({operation:{id:`${t.method}:${t.path}`,path:t.path,httpVerb:t.method,name:`${t.method.toUpperCase()} ${t.path}`},sample:{lang:a.lang,label:a.title}}))},[v,f,r.isWebhook,s.events,t.method,t.path]),Te=t.method,Re=t.path,le=!(s.hideReplay||r.hideReplay)&&!r.isWebhook&&!!(ue??Pt(s.downloadUrls)),G=u==="payload",Ue=!G&&!!se,$e=(i?.length??0)>0,De=m(()=>le?n(Ct,{children:n(Dt,{node:r})}):void 0,[le,r]);return n(je,{children:ie(st,{className:"panel-request-samples",footer:De,header:()=>ie(At,{isExpandable:!1,children:[n(Lt,{servers:r.servers??[],method:Te,path:Re}),n(Vt,{activeTab:u,samples:r.isWebhook?de:f,onChange:Ie})]}),isExpandable:!1,children:[Ve&&p&&n(Bt,{requirements:p,activeIdx:M,onSelect:Ee}),J.length>1&&n(kt,{mediaTypes:J,value:d,onChange:he,label:G?x("contentType","Payload media type"):x("contentType","Request media type")}),!Ue&&!$e&&n(gt,{selection:ge}),n(xt,{exampleIds:i,selectedIdx:V,onSelect:be}),n(vt,{description:S[P??""]?.description}),G?n(Et,{payload:Ae,emptyMessage:`// ${x("noRequestPayload","No request payload")}`,mediaType:d,snippetType:"request"}):n(nt,{lang:qe,source:Ce,header:{className:"code-block-header",controls:{copy:{onClick:Le(j)}}}})]})})}function wt(r){if(typeof r!="string")return r;const g=r.trim();if(!g)return r;try{const c=JSON.parse(g);if(c!==null&&typeof c=="object")return c}catch{}return r}function Bt({requirements:r,activeIdx:g,onSelect:c}){return n(qt,{children:n(bt,{value:String(g),onChange:v=>c(Number(v)),"aria-label":"Security scheme",options:r.map((v,s)=>({key:String(s),value:String(s),label:Object.keys(v).join(" + ")||`Scheme ${s+1}`}))})})}export{Sr as CodeSampleItem};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Fragment as g,jsx as e,jsxs as
|
|
1
|
+
import{Fragment as g,jsx as e,jsxs as h}from"react/jsx-runtime";import{styled as u}from"styled-components";import{useState as E,useEffect as S}from"react";import{PanelHeader as v}from"@redocly/theme/components/Panel/PanelHeader";import{CodeBlockPanel as I}from"../styled.js";import{useResolvedExamples as T,useExampleEntries as P}from"../../ItemContent/hooks.js";import{useBodySamplingSchemaId as M,useSchemaVariantSelection as b,useMediaTypeContent as j}from"./hooks.js";import{VariantPicker as C,ExampleDescription as D,ExampleSelector as _,MediaTypeSelector as k,PayloadDisplay as w}from"./selectors.js";import{useSpecTranslate as B}from"../../../hooks/useTranslate.js";function J({node:n}){const{mediaTypes:r,activeMediaType:s,effectiveSchemaId:l,effectiveExampleIds:a,onMediaTypeChange:m}=j(n),p=B(),d=b(a?.length?void 0:l),c=M(l,s),t=T(c,a,"response",s),f=P(a),[o,i]=E(0);S(()=>i(0),[a,s]);const x=t[o]??t[0],y=f[o]?.description;return t.length===0?e(g,{}):h(I,{className:"panel-response-samples",header:()=>e(F,{isExpandable:!1,children:n.panelLabel??p("payload","Payload")}),isExpandable:!1,children:[e(k,{mediaTypes:r,value:s,onChange:m,label:p("contentType","Payload media type")}),!a?.length&&e(C,{selection:d}),e(_,{exampleIds:a,selectedIdx:o,onSelect:i}),e(D,{description:y}),e(w,{payload:x,emptyMessage:"// No payload sample",mediaType:s})]})}const F=u(v)`
|
|
2
2
|
font-weight: var(--font-weight-regular);
|
|
3
3
|
padding: var(--spacing-sm) var(--spacing-md) var(--spacing-xs);
|
|
4
|
-
`;export{
|
|
4
|
+
`;export{J as PayloadExampleItem};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Fragment as
|
|
1
|
+
import{Fragment as Z,jsx as a,jsxs as B}from"react/jsx-runtime";import{useState as D,useMemo as H,useCallback as O,useContext as ee}from"react";import{useAtom as te,useAtomValue as M,useSetAtom as oe}from"jotai";import{PanelHeaderTitle as ne}from"@redocly/theme/components/Panel/PanelHeaderTitle";import{CodeBlockPanel as se}from"../styled.js";import{findExampleIdByKey as T}from"../../../services/code-samples/example-key.js";import{useResolvedExamples as ae,useExampleEntries as ie}from"../../ItemContent/hooks.js";import{useBodySamplingSchemaId as de,useSchemaVariantSelection as ce}from"./hooks.js";import{activeMediaTypeAtom as pe}from"../../../jotai/app.js";import{exampleStoreAtom as me}from"../../../jotai/examples.js";import{itemStoreAtom as le,itemStoreFieldAtom as F}from"../../../jotai/itemStore.js";import{ItemIdContext as re}from"../../../hooks/useDeepLinkSection.js";import{VariantPicker as ye,ExampleDescription as fe,ExampleSelector as xe,MediaTypeSelector as ue,PayloadDisplay as he}from"./selectors.js";import{ResponsePanelHeader as Te}from"./styled.js";import{ResponseCodesTabList as Ie,ResponseCodeTab as ve}from"../../common/ResponseCodeTabs.js";import{useSpecTranslate as Ce}from"../../../hooks/useTranslate.js";function Se(n,e,y){if(e===void 0||!n?.length)return;const d=s=>y[s];for(const s of n){for(const[I,v]of Object.entries(s.mediaTypeContent??{}))if(T(v.exampleIds,e,d))return{code:s.code,mediaType:I};if(T(s.exampleIds,e,d))return{code:s.code}}}function Ne({node:n}){const{responseCodes:e}=n,y=Ce(),d=ee(re)??"",s=oe(le(d)),I=M(F({itemId:d,key:"activeResponseCode"})),v=M(F({itemId:d,key:"activeExampleKey"})),c=M(me),p=H(()=>Se(e,n.exampleKey,c),[e,n.exampleKey,c]),f=I||p?.code||e?.[0]?.code,i=e?.find(t=>t.code===f)??e?.[0],m=H(()=>i?.mediaTypeContent?Object.keys(i.mediaTypeContent):i?.mediaTypes??[],[i]),[C,N]=te(pe),[V,_]=D(!1),S=p&&p.code===f&&p.mediaType&&m.includes(p.mediaType)?p.mediaType:void 0,u=!V&&S?S:C&&m.includes(C)?C:S??m[0],R=i?.mediaTypeContent?.[u??""],K=!!e?.length,E=R?.schemaId??i?.schemaId??(K?void 0:n.schemaId),o=R?.exampleIds??i?.exampleIds??(K?void 0:n.exampleIds),G=!e?.length||!!(E||o?.length),g=m.length>0?u??m[0]:"application/json",L=ce(o?.length?void 0:E),U=de(E,g),k=ae(U,o,"response",g),q=ie(o),h=`${f}|${u}|${o?.join(",")}`,b=T(o,v||void 0,t=>c[t]),j=b?o?.indexOf(b)??-1:-1,A=T(o,n.exampleKey,t=>c[t]),P=A?o?.indexOf(A)??-1:-1,[w,$]=D({}),l=w[h],x=j>=0?j:l?.picked?l.idx:P>=0?P:l?.idx??0;if(!l||l.idx!==x){const t=l?.picked??!1;$(r=>({...r,[h]:{idx:x,picked:t}}))}const z=O(t=>{$(Y=>({...Y,[h]:{idx:t,picked:!0}}));const r=o?.[t],X=r?c[r]?.key:void 0;s({activeExampleKey:X??""})},[h,o,c,s]),J=k[x]??k[0],Q=q[x]?.description,W=O(()=>{if(!(!n.headerTitle&&!e?.length))return B(Te,{children:[a(ne,{children:n.headerTitle}),e&&e.length>0&&a(Ie,{children:e.map(t=>{const r=t.code===(f??e[0]?.code);return a(ve,{type:"button",$active:r,$code:t.code,onClick:()=>s({activeResponseCode:t.code}),children:t.code},t.code)})})]})},[e,f,n.headerTitle,s]);return k.length===0&&!e?.length?a(Z,{}):B(se,{className:"panel-response-samples",header:W,isExpandable:!1,children:[a(ue,{mediaTypes:m,value:u,onChange:t=>{_(!0),N(t)},label:y("contentType","Response media type")}),!o?.length&&a(ye,{selection:L}),a(xe,{exampleIds:o,selectedIdx:x,onSelect:z}),a(fe,{description:Q}),a(he,{payload:J,emptyMessage:G?`// ${y("noResponseExample","No response sample")}`:y("noResponseContent","No content"),mediaType:g})]})}export{Ne as ResponseExampleItem};
|
|
@@ -8,4 +8,4 @@ import{jsx as i,jsxs as p}from"react/jsx-runtime";import{useCallback as f,useEff
|
|
|
8
8
|
:hover {
|
|
9
9
|
background-color: var(--dropdown-menu-item-bg-color-hover);
|
|
10
10
|
}
|
|
11
|
-
`;function gr({servers:o,method:n,path:t}){const[y,s]=$(L),{events:v}=h(_),d=H(),c=y[0],a=h(O),x=!["get","post","put","delete","patch","head","options","trace","query","x-query"].includes(n.toLowerCase()),u=D({httpVerb:n.toLowerCase(),isAdditionalOperation:x}),l=g(()=>o.map(r=>{const e=w(r.url);return{...r,resolvedUrl:q(r),envUrl:e,envName:String(T({...r,url:e}))}}),[o]),N=g(()=>{const r=l.find(e=>e.url===c.server||e.resolvedUrl===c.server||e.envUrl===c.server);return r?r.resolvedUrl:l[0]?.resolvedUrl??""},[c.server,l]);P(()=>{if(!c.server&&l.length>0){const e=(a?l.find(m=>m.envName===a):void 0)??l[0];s({...!a&&{environment:e.envName},environments:{[e.envName]:{server:e.envUrl}}})}},[]);const k=f(r=>{r.stopPropagation()},[]),A=f(r=>()=>{if(o.length<=1)return;const e=r.envName;d.sendSwitchServersClickedMessage([{id:"switchServersButton",object:"button",uri:"urn:redocly:redoc:ui:button:switchServersButton",server:e}]),s({environment:e,environments:{[e]:{server:r.envUrl}}}),v?.targetServerSwitch?.(R({operation:{id:`${n}:${t}`,path:t,httpVerb:n,name:`${n.toUpperCase()} ${t}`},serverUrl:r.url}))},[o.length,s,d,v,n,t]),E=t.includes("{$");if(o.length
|
|
11
|
+
`;function gr({servers:o,method:n,path:t}){const[y,s]=$(L),{events:v}=h(_),d=H(),c=y[0],a=h(O),x=!["get","post","put","delete","patch","head","options","trace","query","x-query"].includes(n.toLowerCase()),u=D({httpVerb:n.toLowerCase(),isAdditionalOperation:x}),l=g(()=>o.map(r=>{const e=w(r.url);return{...r,resolvedUrl:q(r),envUrl:e,envName:String(T({...r,url:e}))}}),[o]),N=g(()=>{const r=l.find(e=>e.url===c.server||e.resolvedUrl===c.server||e.envUrl===c.server);return r?r.resolvedUrl:l[0]?.resolvedUrl??""},[c.server,l]);P(()=>{if(!c.server&&l.length>0){const e=(a?l.find(m=>m.envName===a):void 0)??l[0];s({...!a&&{environment:e.envName},environments:{[e.envName]:{server:e.envUrl}}})}},[]);const k=f(r=>{r.stopPropagation()},[]),A=f(r=>()=>{if(o.length<=1)return;const e=r.envName;d.sendSwitchServersClickedMessage([{id:"switchServersButton",object:"button",uri:"urn:redocly:redoc:ui:button:switchServersButton",server:e}]),s({environment:e,environments:{[e]:{server:r.envUrl}}}),v?.targetServerSwitch?.(R({operation:{id:`${n}:${t}`,path:t,httpVerb:n,name:`${n.toUpperCase()} ${t}`},serverUrl:r.url}))},[o.length,s,d,v,n,t]),E=t.includes("{$");if(o.length===0||E)return p(G,{children:[i(U,{color:u,children:n}),i(C,{children:t})]});const b=p(F,{variant:"ghost",children:[i(U,{color:u,children:n}),i(C,{children:t})]}),j=l.map(r=>{const e=w(r.resolvedUrl),m=J(e,t);return i(K,{onAction:A(r),children:i(z,{header:r.name||r.description||e,title:m,actions:[i(Q,{data:m,toasterPlacement:"left",onCopyClick:k},m)],active:r.resolvedUrl===N,withCheckmark:!0})},r.url)});return i(V,{trigger:b,withArrow:!0,alignment:"start",children:i(W,{children:j})})}export{gr as ServerDropdown};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import type { ExampleEntry } from '../../../types/store.js';
|
|
2
3
|
import type { SchemaVariantSelection } from './hooks.js';
|
|
3
4
|
export declare function VariantPicker({ selection, label, }: {
|
|
4
5
|
selection?: SchemaVariantSelection;
|
|
@@ -27,10 +28,12 @@ export declare function PanelDropdownSelect({ value, onChange, options, 'aria-la
|
|
|
27
28
|
options: PanelSelectOption[];
|
|
28
29
|
'aria-label'?: string;
|
|
29
30
|
}): ReactElement;
|
|
30
|
-
export declare function
|
|
31
|
+
export declare function ExampleDescription({ description, }: {
|
|
32
|
+
description?: ExampleEntry['description'];
|
|
33
|
+
}): ReactElement | null;
|
|
34
|
+
export declare function PayloadDisplay({ payload, emptyMessage, mediaType, snippetType, }: {
|
|
31
35
|
payload: unknown;
|
|
32
36
|
emptyMessage?: string;
|
|
33
37
|
mediaType?: string;
|
|
34
38
|
snippetType?: 'request' | 'response';
|
|
35
|
-
description?: string;
|
|
36
39
|
}): ReactElement;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{jsx as t}from"react/jsx-runtime";import{useAtomValue as d}from"jotai";import{exampleStoreAtom as k}from"../../../jotai/examples.js";import{globalOptionsAtom as v,specTypeAtom as w}from"../../../jotai/store.js";import{useTelemetry as D}from"../../../hooks/useTelemetry.js";import{useCopyCodeTelemetry as E}from"../../../hooks/useCopyCodeTelemetry.js";import{MAX_DISPLAYED_STRING_LENGTH as f}from"../../../constants/rendering.js";import{isJsonLikeMediaType as C,isSequentialMediaType as M,langFromMime as h}from"../../../utils/media-type.js";import{StyledCodeBlock as m,StyledJsonViewer as b}from"../styled.js";import{Markdown as N}from"../../common/Markdown.js";import{DisabledMimeSelect as L,ExampleDescriptionWrap as y,SelectDropdownCheckmarkIcon as A,MediaTypeRow as p,SelectDropdownLabel as x,SelectDropdownMenu as j,SelectDropdownMenuItem as B,SelectDropdownTriggerButton as J,StyledSelectDropdown as O}from"./styled.js";import{DefaultMappingOptionLabel as P}from"../../Schema/views/DefaultMappingOptionLabel.js";import{jsonToXml as V}from"../../../utils/xml.js";import{formUrlEncodeValue as _}from"../../../utils/form-urlencoded.js";import{apiSpecType as H}from"../../../types/common.js";function le({selection:e,label:a}){if(!e)return null;const{options:r,activeIdx:c,onSelect:o,kind:n,optionMeta:s}=e,u=a??(n==="discriminator"?"Discriminator":"Variant");return t(p,{children:t(g,{value:String(c),onChange:l=>o(Number(l)),"aria-label":u,options:r.map((l,i)=>{const S=s[i]?.isDefaultMapping?t(P,{label:l.label}):void 0;return{key:l.key,value:String(i),label:l.label,labelNode:S}})})})}function oe({exampleIds:e,selectedIdx:a,onSelect:r}){const c=d(k),o=d(w),n=D();if(!e||e.length<2)return null;const s=u=>{const l=Number(u),i=e[l];o===H.ASYNCAPI?n.sendSwitchExampleClickedMessage([{id:"switchExampleButton",object:"button",uri:"urn:redocly:redoc:ui:button:switchExampleButton",example:i,numberOfExamples:e.length}]):n.sendExamplesSwitcherClickedMessage([{object:"button",id:"examplesSwitcherButton",uri:"urn:redocly:redoc:ui:button:examplesSwitcherButton",exampleNumber:l,totalExamples:e.length}]),r(l)};return t(p,{children:t(g,{value:String(a),onChange:s,"aria-label":"Example",options:e.map((u,l)=>({key:u,value:String(l),label:c[u]?.summary??`Example ${l+1}`}))})})}function ae({mediaTypes:e,value:a,onChange:r,label:c}){return e.length===0?null:e.length===1?t(p,{children:t(L,{value:e[0],"aria-label":c,disabled:!0,children:t("option",{value:e[0],children:e[0]})})}):t(p,{children:t(g,{value:a,onChange:r,"aria-label":c,options:e.map(o=>({value:o,label:o}))})})}function g({value:e,onChange:a,options:r,"aria-label":c}){const o=r.find(n=>n.value===e)??r[0];return t(O,{withArrow:!0,alignment:"start",portalled:!0,trigger:t(J,{variant:"outlined",size:"small",type:"button","aria-label":c,children:t(x,{children:o?.labelNode??o?.label})}),children:t(j,{children:r.map(n=>t(B,{active:n.value===o?.value,onAction:()=>a(n.value),suffix:n.value===o?.value?t(A,{}):void 0,children:t(x,{children:n.labelNode??n.label})},n.key??n.value))})})}function ie({description:e}){return e?t(y,{children:t(N,{source:e})}):null}function ce({payload:e,emptyMessage:a="// No sample",mediaType:r,snippetType:c="response"}){const{jsonSamplesExpandLevel:o}=d(v),n=E(c);if(e==null)return t(m,{lang:"text",source:a,header:{controls:!1}});const s=M(r),u=C(r);if(u&&!s){const i=typeof e=="string"?F(e)??e:e;return t(b,{data:i,expandLevel:o,maxStringLength:f})}if(typeof e=="object"&&e!==null){if(r?.includes("xml")){const i=V(e);return t(m,{lang:"xml",source:i,highlightedHtml:G(i),header:{className:"code-block-header",controls:{copy:{onClick:n("xml")}}}})}if(q(r))return t(m,{lang:"text",source:_(e),header:{className:"code-block-header",controls:{copy:{onClick:n("text")}}}});if(s||r&&!u){const i=JSON.stringify(e,null,2);return t(m,{lang:h(r),source:i,header:{className:"code-block-header",controls:{copy:{onClick:n(h(r))}}}})}return t(b,{data:e,expandLevel:o,maxStringLength:f})}const l=r?h(r):"text";return t(m,{lang:l,source:String(e),maxDisplayLength:f,header:{className:"code-block-header",controls:{copy:{onClick:n(l)}}}})}function q(e){return!!e&&/x-www-form-urlencoded/i.test(e)}function F(e){const a=e.trim();if(!(!a||!/^[{[]/.test(a)))try{return JSON.parse(a)}catch{return}}function G(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}export{ie as ExampleDescription,oe as ExampleSelector,ae as MediaTypeSelector,g as PanelDropdownSelect,ce as PayloadDisplay,le as VariantPicker};
|
|
@@ -161,4 +161,5 @@ export declare const SelectDropdownTriggerButton: import("styled-components/dist
|
|
|
161
161
|
}, never>>> & string;
|
|
162
162
|
export declare const VariablesContainer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never> & Partial<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>> & string;
|
|
163
163
|
export declare const VariablesTitle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never> & Partial<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>> & string;
|
|
164
|
+
export declare const ExampleDescriptionWrap: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never> & Partial<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>> & string;
|
|
164
165
|
export declare const TryItPanelFooter: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never> & Partial<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>> & string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{styled as e}from"styled-components";import{PanelHeader as
|
|
1
|
+
import{styled as e}from"styled-components";import{PanelHeader as o}from"@redocly/theme/components/Panel/PanelHeader";import{Tag as a}from"@redocly/theme/components/Tag/Tag";import{Button as r}from"@redocly/theme/components/Button/Button";import{Dropdown as n}from"@redocly/theme/components/Dropdown/Dropdown";import{DropdownMenu as t}from"@redocly/theme/components/Dropdown/DropdownMenu";import{DropdownMenuItem as i}from"@redocly/theme/components/Dropdown/DropdownMenuItem";import{CheckmarkIcon as p}from"@redocly/theme/icons/CheckmarkIcon/CheckmarkIcon";const v=e(o)`
|
|
2
2
|
flex-wrap: nowrap;
|
|
3
3
|
column-gap: var(--spacing-xs);
|
|
4
4
|
padding: var(--spacing-sm) var(--spacing-md) var(--spacing-xs);
|
|
@@ -10,7 +10,7 @@ import{styled as e}from"styled-components";import{PanelHeader as r}from"@redocly
|
|
|
10
10
|
> :last-child {
|
|
11
11
|
flex-shrink: 0;
|
|
12
12
|
}
|
|
13
|
-
`,
|
|
13
|
+
`,x=e(r)`
|
|
14
14
|
display: inline-flex;
|
|
15
15
|
overflow-x: hidden;
|
|
16
16
|
font-weight: var(--font-weight-regular);
|
|
@@ -75,6 +75,10 @@ import{styled as e}from"styled-components";import{PanelHeader as r}from"@redocly
|
|
|
75
75
|
max-width: 100%;
|
|
76
76
|
}
|
|
77
77
|
`,S=e(t)`
|
|
78
|
+
/* The portalled menu wrapper gets the trigger width as an inline min-width;
|
|
79
|
+
width: 0 keeps the menu content from growing the wrapper past it, so the
|
|
80
|
+
menu ends up exactly as wide as the trigger. */
|
|
81
|
+
width: 0;
|
|
78
82
|
min-width: 100%;
|
|
79
83
|
`,P=e(i)`
|
|
80
84
|
--dropdown-menu-item-justify-content: space-between;
|
|
@@ -90,12 +94,12 @@ import{styled as e}from"styled-components";import{PanelHeader as r}from"@redocly
|
|
|
90
94
|
overflow: hidden;
|
|
91
95
|
text-overflow: ellipsis;
|
|
92
96
|
white-space: nowrap;
|
|
93
|
-
`,
|
|
97
|
+
`,T=e(p)`
|
|
94
98
|
width: 16px;
|
|
95
99
|
height: 16px;
|
|
96
100
|
margin-left: auto;
|
|
97
101
|
flex-shrink: 0;
|
|
98
|
-
`,
|
|
102
|
+
`,I=e(r)`
|
|
99
103
|
width: 100%;
|
|
100
104
|
justify-content: space-between;
|
|
101
105
|
background-color: var(--bg-color);
|
|
@@ -120,9 +124,11 @@ import{styled as e}from"styled-components";import{PanelHeader as r}from"@redocly
|
|
|
120
124
|
font-weight: var(--font-weight-semibold);
|
|
121
125
|
color: var(--panel-samples-text-color, #cfd8dc);
|
|
122
126
|
`,C=e.div`
|
|
127
|
+
margin: 0 var(--spacing-md) var(--spacing-sm);
|
|
128
|
+
`,V=e.div`
|
|
123
129
|
display: flex;
|
|
124
130
|
justify-content: flex-end;
|
|
125
131
|
align-items: center;
|
|
126
132
|
border-top: var(--panel-border);
|
|
127
133
|
padding: var(--spacing-xs) var(--spacing-md) var(--spacing-sm) var(--spacing-md);
|
|
128
|
-
`;export{z as DisabledMimeSelect,b as HttpVerb,k as MediaTypeRow,u as PathLabel,
|
|
134
|
+
`;export{z as DisabledMimeSelect,C as ExampleDescriptionWrap,b as HttpVerb,k as MediaTypeRow,u as PathLabel,x as PathWrapper,y as ResponsePanelHeader,T as SelectDropdownCheckmarkIcon,M as SelectDropdownLabel,S as SelectDropdownMenu,P as SelectDropdownMenuItem,I as SelectDropdownTriggerButton,w as StaticPathWrapper,v as StyledPanelHeader,D as StyledSelectDropdown,V as TryItPanelFooter,j as VariablesContainer,H as VariablesTitle};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import{Fragment as
|
|
1
|
+
import{Fragment as i,jsx as e,jsxs as c}from"react/jsx-runtime";import{useAtomValue as u}from"jotai";import{styled as n}from"styled-components";import{refPointerToStoreId as s}from"../../utils/refPointer.js";import{ContentWrapper as f}from"../common/ContentWrapper.js";import{exampleStoreAtom as x}from"../../jotai/examples.js";import{ExampleDescription as b,PayloadDisplay as v}from"../panels/ExampleItem/selectors.js";const _=({pointer:r,value:o,mimeType:p})=>{const t=u(x);if(o===void 0&&!r)return e(i,{});const m=r?s(r):void 0,l=r&&/\/value$/.test(r)?s(r.replace(/\/value$/,"")):void 0,a=t[m??""]??t[l??""],d=o!==void 0?o:a?.value;return d===void 0?e(i,{}):e(f,{children:c(g,{children:[a?.description?e(y,{children:e(b,{description:a.description})}):null,e(v,{payload:d,mediaType:p})]})})},g=n.div`
|
|
2
2
|
padding: calc(var(--spacing-unit) * 4);
|
|
3
3
|
border-radius: var(--panel-border-radius);
|
|
4
4
|
border: var(--panel-samples-border);
|
|
5
5
|
background-color: var(--panel-samples-bg-color);
|
|
6
6
|
width: 100%;
|
|
7
|
-
|
|
7
|
+
`,y=n.div`
|
|
8
|
+
border-bottom: 1px solid var(--border-color-primary);
|
|
9
|
+
margin-bottom: var(--spacing-sm);
|
|
10
|
+
`;export{_ as RedocExample};
|
package/lib/jotai/itemStore.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type ItemStore = {
|
|
|
3
3
|
activeDiscriminator: Record<string, number>;
|
|
4
4
|
activeOneOf: Record<string, number>;
|
|
5
5
|
activeResponseCode: string;
|
|
6
|
+
activeExampleKey: string;
|
|
6
7
|
activeMessageKey: string;
|
|
7
8
|
selectedCallback: string;
|
|
8
9
|
expandableSections: Record<string, boolean | undefined>;
|
package/lib/jotai/itemStore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{atom as p}from"jotai";import{selectAtom as
|
|
1
|
+
import{atom as p}from"jotai";import{selectAtom as s}from"jotai/utils";import{atomFamily as c}from"jotai-family";import{keepReadingSectionAnchored as S}from"../utils/scroll-anchoring.js";const d=Object.freeze({activeDiscriminator:Object.freeze({}),activeOneOf:Object.freeze({}),activeResponseCode:"",activeExampleKey:"",activeMessageKey:"",selectedCallback:"",expandableSections:Object.freeze({}),collapsibles:Object.freeze({})});function u(){return d}const l=p({}),O=["activeResponseCode","activeMessageKey","activeExampleKey","activeOneOf","activeDiscriminator"],f=c(e=>p(t=>t(l)[e]??u(),(t,n,o)=>{const i=t(l),r=i[e]??u(),a=typeof o=="function"?o(r):o;O.some(m=>m in a&&a[m]!==r[m])&&S(),n(l,{...i,[e]:{...r,...a}})})),A=c(e=>s(f(e.itemId),t=>t[e.key]),(e,t)=>e.itemId===t.itemId&&e.key===t.key);function x(e){return A(e)}function g(e,t){const n=e?.length?e.join("/"):"";return n?`${n}/${t}`:t}function j(e){return x({itemId:e,key:"activeDiscriminator"})}function R(e){return x({itemId:e,key:"activeOneOf"})}const b=c(e=>s(f(e.itemId),t=>t.expandableSections[e.key]),(e,t)=>e.itemId===t.itemId&&e.key===t.key);function D(e,t){return b({itemId:e,key:t})}const y="#";function F(e,t){return`${e}${y}${t}`}function T(e){const t=e.indexOf(y);return t===-1?e:e.slice(0,t)}const v=c(e=>s(f(e),t=>Object.keys(t.expandableSections),(t,n)=>t.length===n.length&&t.every((o,i)=>o===n[i])));function _(e){return v(e)}export{j as activeDiscriminatorSelectAtom,R as activeOneOfSelectAtom,F as buildCollapsibleEntryKey,g as buildVariantStateKey,T as collapsibleEntrySection,D as expandableSectionAtom,_ as expandableSectionKeysAtom,f as itemStoreAtom,x as itemStoreFieldAtom};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CodeSampleHAR } from './sample-har.js';
|
|
2
2
|
import type { CodeSampleSource, ParameterEntry } from './source.js';
|
|
3
|
+
import type { HoistedVariant } from './discriminator.js';
|
|
3
4
|
export type HARBuildSelections = {
|
|
4
5
|
serverUrl?: string;
|
|
5
6
|
mediaType?: string;
|
|
@@ -29,10 +30,7 @@ export type HARBuildResolvers = {
|
|
|
29
30
|
format?: string;
|
|
30
31
|
}) => unknown;
|
|
31
32
|
serializeParameter?: (param: ParameterEntry, value: unknown) => string;
|
|
32
|
-
resolveVariantSchemaForSampling?: (schemaId: string) =>
|
|
33
|
-
|
|
34
|
-
variantSchemaId: string;
|
|
35
|
-
} | undefined;
|
|
36
|
-
applyDiscriminatorValue?: (sample: unknown, variantSchemaId: string) => void;
|
|
33
|
+
resolveVariantSchemaForSampling?: (schemaId: string) => HoistedVariant | undefined;
|
|
34
|
+
applyDiscriminatorValue?: (sample: unknown, variantSchemaId: string, mappingKey?: string) => void;
|
|
37
35
|
};
|
|
38
36
|
export declare function buildCodeSampleHAR(source: CodeSampleSource, selections: HARBuildSelections, options: HARBuildOptions, resolvers: HARBuildResolvers): CodeSampleHAR;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import $ from"url-template";import{SecurityVariablesEnvSuffix as g}from"@redocly/theme/core/openapi";import{mergeBodyValue as F}from"../../adapters/openapi/configure/merge-utils.js";import{formUrlEncodeValue as H,stringifyFormFieldValue as E}from"../../utils/form-urlencoded.js";import{isSequentialMediaType as K}from"../../utils/media-type.js";import{parseMultipartFormData as M}from"../../utils/multipart.js";import{objectToHarParams as J}from"../../utils/serialize-querystring.js";import{jsonToXml as L}from"../../utils/xml.js";import{MediaTypes as k}from"../../constants/openapi.js";import{convertSampleToString as Y}from"./convertSampleToString.js";import{findExampleIdByKey as Q,mediaTypeContainingKey as X}from"./example-key.js";import{resolveServerUrl as G}from"./replay/normalize-servers.js";import{serverMatchesUrl as W}from"./server-variables.js";function Ie(e,n,a,r){const o=e.servers.find(f=>W(f,n.serverUrl))||e.servers[0],u=o?.url?.replace(/\/$/,"")??"",c=u?G(u).replace(/\/$/,""):"",t={};if(o?.variables)for(const[f,A]of Object.entries(o.variables))t[f]=n.environment?.[f]||A.default||"";const l=e.path.replace(/^\//,""),i=`${c}/${l}`,d={skipReadOnly:!0,maxDepth:a.generatedPayloadSamplesMaxDepth??8,format:"json"},s=o?.url??n.serverUrl??"",p=n.requestValues??{},m=Z(e.security,n.activeSecuritySchemeIds),y=ee(m,n,a,s),S=b(e.parameters.header,"header",s,p,a,r,d).concat(y.headers),h=n.mediaType||X(e.requestBody,n.exampleName,r.resolveExample)||(e.requestBody?Object.keys(e.requestBody)[0]:void 0);let R=!1;for(const f of S)f.name.toLowerCase()==="content-type"&&h&&(f.value=h,R=!0);!R&&h&&S.unshift({name:"Content-Type",value:h});const v=b(e.parameters.cookie,"cookie",s,p,a,r,d).concat(y.cookies),O=e.parameters.querystring.length>0,C=b(O?e.parameters.querystring:e.parameters.query,O?"querystring":"query",s,p,a,r,d).concat(y.queries),U={};for(const f of e.parameters.path)U[f.name]=p.path?.[f.name]||f.serverValues?.[s]?.example||f.example||"";let x;if(h&&e.requestBody?.[h]){const f=e.requestBody[h],A=e.requestValues?.serverBody?.[s]??e.requestValues?.body;x=le(f,h,n,r,d,s,A)}const w={};for(const f of S)w[f.name]=f.value;const I={};v.length&&(I.cookie=v.map(f=>`${encodeURIComponent(f.name)}=${encodeURIComponent(f.value)}`).join("; ")),Object.assign(I,w);const j={};for(const f of C)V(j,f.name,f.value);const B=x?.text?ue(x.text):void 0;let _;if(x?.params?.length){_={};for(const f of x.params)V(_,f.name,f.value??"")}const P=C.map(f=>`${encodeURIComponent(f.name)}=${encodeURIComponent(f.value)}`).join("&"),q=P?`${i}?${P}`:i;return{method:e.method.toUpperCase(),url:i,pathname:q,httpVersion:"HTTP/1.1",cookies:v,headers:S,queryString:C,postData:x,headersSize:-1,bodySize:-1,fullUrl:q,headersObj:w,allHeaders:I,queryObj:j,jsonObj:B,paramsObj:_,basicAuth:y.basicAuth,pathParameters:U,serverVariables:t,responseCodes:e.responseCodes,allResponseCodes:e.responseCodes,oAuth2PreRequests:y.oAuth2PreRequests}}function V(e,n,a){const r=e[n];r===void 0?e[n]=a:Array.isArray(r)?r.push(a):e[n]=[r,a]}function Z(e,n){if(e.length){if(n?.length){const a=e.find(r=>{const o=r.schemes.map(u=>u.id);return o.length===n.length&&o.every(u=>n.includes(u))});if(a)return a}return e[0]}}function ee(e,n,a,r){const o={headers:[],cookies:[],queries:[]};if(!e)return o;for(const u of e.schemes)ne(u,o,n,a,r,e.scopes);return o}const te={"x-defaultUsername":g.Username,"x-defaultPassword":g.Password,"x-defaultClientId":g.ClientId,"x-defaultClientSecret":g.ClientSecret};function ne(e,n,a,r,o,u=[]){const c=a.requestValues?.security,t=l=>{const i=e.serverValues?.[o];if(i){const y=i[l];if(y!=null)return String(y)}const d=e[l];if(d!=null&&typeof d=="string")return d;const s=c?.[l];if(s!=null)return String(s);const p=l==="x-defaultAccessToken"?e.type==="apiKey"?g.APIKey:g.Token:te[l],m=p!==void 0?a.environment?.[e.id+p]:void 0;if(m)return m};if(e.type==="http"&&e.scheme==="basic")n.basicAuth={username:t("x-defaultUsername")||c?.username||"<username>",password:t("x-defaultPassword")||c?.password||"<password>"};else if(e.type==="http"){const l=t("x-defaultAccessToken"),i=e.scheme||"bearer",d=i.charAt(0).toUpperCase()+i.slice(1),s=e.bearerFormat?`<YOUR_${e.bearerFormat}_HERE>`:"<YOUR_TOKEN_HERE>";n.headers.push({name:"Authorization",value:l?`${d} ${l}`:`${d} ${s}`})}else if(e.type==="apiKey"&&e.name){const l=t("x-defaultAccessToken")||"YOUR_API_KEY_HERE",i={name:e.name,value:l};e.in==="header"?n.headers.push(i):e.in==="cookie"?n.cookies.push({name:e.name,value:l}):(e.in==="query"||e.in==="querystring"||e.in===void 0)&&n.queries.push({name:e.name,value:l})}else if(e.type==="oauth2"){const l=t("x-defaultAccessToken"),i=t("x-defaultTokenType")||"Bearer";if(n.headers.push({name:"Authorization",value:l?`${i} ${l}`:"Bearer <YOUR_TOKEN_HERE>"}),r.withOAuth2Call&&e.flows){const d=[];if(e.flows.deviceAuthorization){const s=e.flows.deviceAuthorization;d.push(ae(s.deviceAuthorizationUrl,s.tokenUrl,e,o,u))}else if(e.flows.clientCredentials){const s=e.flows.clientCredentials;d.push(z("clientCredentials",s.tokenUrl,e,o,u))}else if(e.flows.password){const s=e.flows.password;d.push(z("password",s.tokenUrl,e,o,u))}d.length>0&&(n.oAuth2PreRequests=(n.oAuth2PreRequests??[]).concat(d))}}else if(e.type==="openIdConnect"){const l=t("x-defaultAccessToken"),i=t("x-defaultTokenType")||"Bearer";n.headers.push({name:"Authorization",value:l?`${i} ${l}`:"Bearer <YOUR_TOKEN_HERE>"})}}function ae(e,n,a,r,o=[]){const u=a.serverValues?.[r]?.["x-defaultClientId"]||a["x-defaultClientId"]||"YOUR_CLIENT_ID",c=[{name:"client_id",value:u}];return o.length>0&&c.push({name:"scope",value:o.join(" ")}),{flowType:"deviceAuthorization",tokenUrl:n,clientId:u,scopes:o.length>0?o:void 0,method:"POST",url:e,httpVersion:"HTTP/1.1",cookies:[],headers:[{name:"Content-Type",value:"application/x-www-form-urlencoded"},{name:"Accept",value:"application/json"}],queryString:[],postData:{mimeType:"application/x-www-form-urlencoded",params:c,text:c.map(t=>`${encodeURIComponent(t.name)}=${encodeURIComponent(t.value??"")}`).join("&")},headersSize:-1,bodySize:-1}}function z(e,n,a,r,o=[]){const u=a.serverValues?.[r]?.["x-defaultClientId"]||a["x-defaultClientId"]||"YOUR_CLIENT_ID",c=a.serverValues?.[r]?.["x-defaultClientSecret"]||a["x-defaultClientSecret"],t=a.serverValues?.[r]?.["x-defaultUsername"]||a["x-defaultUsername"],l=a.serverValues?.[r]?.["x-defaultPassword"]||a["x-defaultPassword"],i=[];return e==="clientCredentials"?i.push({name:"grant_type",value:"client_credentials"}):e==="password"&&i.push({name:"grant_type",value:"password"}),i.push({name:"client_id",value:u}),i.push({name:"client_secret",value:c||"YOUR_CLIENT_SECRET"}),e==="password"&&(i.push({name:"username",value:t||"<username>"}),i.push({name:"password",value:l||"<password>"})),o.length>0&&i.push({name:"scope",value:o.join(" ")}),{flowType:e,tokenUrl:n,clientId:u,clientSecret:c,username:t,password:l,scopes:o.length>0?o:void 0,method:"POST",url:n,httpVersion:"HTTP/1.1",cookies:[],headers:[{name:"Content-Type",value:"application/x-www-form-urlencoded"},{name:"Accept",value:"application/json"}],queryString:[],postData:{mimeType:"application/x-www-form-urlencoded",params:i,text:i.map(d=>`${encodeURIComponent(d.name)}=${encodeURIComponent(d.value??"")}`).join("&")},headersSize:-1,bodySize:-1}}function N(e,n,a){return n==="querystring"&&e.serializationMime===k.URL_ENCODED&&typeof a=="object"&&a!==null?re(J(a)):null}function re(e){const n=new Map,a=[];for(const r of e){const o=n.get(r.name);o?o.push(r.value):(n.set(r.name,[r.value]),a.push(r.name))}return a.map(r=>({name:r,value:(n.get(r)??[]).join(",")}))}function b(e,n,a,r,o,u,c){return e.filter(t=>!o.skipOptionalParameters||t.required).flatMap(t=>{const i=r[n==="querystring"?"query":n]?.[t.name];if(i!=null)return[{name:t.name,value:String(i)}];const d=t.serverValues?.[a]?.example;if(d!=null)return[{name:t.name,value:T(t,d)}];if(t.example!=null){const s=N(t,n,t.example);return s||(t.serializationMime&&u.serializeParameter?[{name:t.name,value:u.serializeParameter(t,t.example)}]:[{name:t.name,value:T(t,t.example)}])}if(n==="querystring"&&t.serializationMime===k.URL_ENCODED&&t.schemaId){const s=u.resolveSchema(t.schemaId);if(s){const p=u.sampleFromSchema(s,c),m=N(t,n,p);if(m)return m}}return[{name:t.name,value:oe(t,u,c)}]})}function oe(e,n,a){if(e.schemaId){const r=n.resolveSchema(e.schemaId);if(r){const o=n.sampleFromSchema(r,a);if(o!=null)return e.serializationMime&&n.serializeParameter?n.serializeParameter(e,o):T(e,o)}}return`{${e.name}}`}function ie(e){switch(e){case"query":case"querystring":case"cookie":return"form";case"path":case"header":return"simple";default:return"form"}}function T(e,n){if(n==null)return"";if(typeof n!="object")return String(n);const a=e.style??ie(e.in),o=e.explode??a==="form"?"*":"",u="__redoc_param_name__";try{switch(a){case"form":{const l=$.parse(`{?${u}${o}}`).expand({[u]:n}).substring(1).replace(/__redoc_param_name__/g,e.name).split(`&${e.name}=`);return l[0]=l[0].replace(new RegExp(`^${se(e.name)}=`),""),l.map(D).join(",")}case"spaceDelimited":return Array.isArray(n)?n.map(String).join(" "):String(n);case"pipeDelimited":return Array.isArray(n)?n.map(String).join("|"):String(n);case"simple":case"label":case"matrix":{const c=a==="label"?".":a==="matrix"?";":"",t=$.parse(`{${c}${u}${o}}`);return D(t.expand({[u]:n}).replace(/__redoc_param_name__/g,e.name))}case"deepObject":return JSON.stringify(n);default:return JSON.stringify(n)}}catch{return Array.isArray(n)?n.map(String).join(","):JSON.stringify(n)}}function se(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function D(e){try{return decodeURIComponent(e)}catch{return e}}function le(e,n,a,r,o,u,c){let t;if(a.replayBody!==void 0&&(t=a.replayBody),t===void 0&&a.exampleName){const s=Q(e.exampleIds,a.exampleName,r.resolveExample),p=s?r.resolveExample(s):void 0;p&&(t=p.value)}if(t===void 0&&e.exampleIds?.length){const s=r.resolveExample(e.exampleIds[0]);s&&(t=s.value)}if(t===void 0&&e.schemaId){const s=r.resolveVariantSchemaForSampling?.(e.schemaId),p=s?.schema??r.resolveSchema(e.schemaId),m=s?.variantSchemaId??e.schemaId;if(p){const y=n.toLowerCase().includes("xml");t=r.sampleFromSchema(p,{...o,format:y?"xml":o.format}),t&&typeof t=="object"&&!Array.isArray(t)&&m!==e.schemaId&&r.applyDiscriminatorValue?.(t,m)}}if(c!==void 0&&a.replayBody===void 0&&(t===void 0?t=c:t=F(t,c)),t===void 0)return;const l=n.toLowerCase();let i,d=[];if(l.includes("x-www-form-urlencoded"))typeof t=="object"&&t!==null?(d=Object.entries(t).map(([s,p])=>({name:s,value:E(p)})),i=H(t)):i=String(t);else if(l.includes("multipart/form-data"))typeof t=="string"?(d=M(t)??[],i=t):(typeof t=="object"&&t!==null&&!Array.isArray(t)&&(d=Object.entries(t).map(([s,p])=>({name:s,value:E(p)}))),i=JSON.stringify(t,null,2));else if(K(l))if(typeof t=="string")i=t;else{const s=e.schemaId?r.resolveSchema(e.schemaId):void 0;i=String(Y(t,l,s,!0))}else l.includes("json")?i=typeof t=="string"?t:JSON.stringify(t,null,2):l.includes("xml")?i=typeof t=="string"?t:t&&typeof t=="object"?L(t):String(t):i=typeof t=="string"?t:JSON.stringify(t,null,2);return{mimeType:n,params:d,text:i}}function ue(e){try{const n=JSON.parse(e);if(n&&typeof n=="object"&&!Array.isArray(n))return n}catch{}}export{Ie as buildCodeSampleHAR};
|
|
1
|
+
import $ from"url-template";import{SecurityVariablesEnvSuffix as g}from"@redocly/theme/core/openapi";import{mergeBodyValue as F}from"../../adapters/openapi/configure/merge-utils.js";import{formUrlEncodeValue as K,stringifyFormFieldValue as E}from"../../utils/form-urlencoded.js";import{isSequentialMediaType as H}from"../../utils/media-type.js";import{parseMultipartFormData as M}from"../../utils/multipart.js";import{objectToHarParams as J}from"../../utils/serialize-querystring.js";import{jsonToXml as L}from"../../utils/xml.js";import{MediaTypes as k}from"../../constants/openapi.js";import{convertSampleToString as Y}from"./convertSampleToString.js";import{findExampleIdByKey as Q,mediaTypeContainingKey as X}from"./example-key.js";import{resolveServerUrl as G}from"./replay/normalize-servers.js";import{serverMatchesUrl as W}from"./server-variables.js";function Ie(e,n,a,r){const o=e.servers.find(f=>W(f,n.serverUrl))||e.servers[0],u=o?.url?.replace(/\/$/,"")??"",c=u?G(u).replace(/\/$/,""):"",t={};if(o?.variables)for(const[f,A]of Object.entries(o.variables))t[f]=n.environment?.[f]||A.default||"";const l=e.path.replace(/^\//,""),s=`${c}/${l}`,d={skipReadOnly:!0,maxDepth:a.generatedPayloadSamplesMaxDepth??8,format:"json"},i=o?.url??n.serverUrl??"",p=n.requestValues??{},m=Z(e.security,n.activeSecuritySchemeIds),y=ee(m,n,a,i),S=b(e.parameters.header,"header",i,p,a,r,d).concat(y.headers),h=n.mediaType||X(e.requestBody,n.exampleName,r.resolveExample)||(e.requestBody?Object.keys(e.requestBody)[0]:void 0);let R=!1;for(const f of S)f.name.toLowerCase()==="content-type"&&h&&(f.value=h,R=!0);!R&&h&&S.unshift({name:"Content-Type",value:h});const v=b(e.parameters.cookie,"cookie",i,p,a,r,d).concat(y.cookies),O=e.parameters.querystring.length>0,C=b(O?e.parameters.querystring:e.parameters.query,O?"querystring":"query",i,p,a,r,d).concat(y.queries),U={};for(const f of e.parameters.path)U[f.name]=p.path?.[f.name]||f.serverValues?.[i]?.example||f.example||"";let x;if(h&&e.requestBody?.[h]){const f=e.requestBody[h],A=e.requestValues?.serverBody?.[i]??e.requestValues?.body;x=le(f,h,n,r,d,i,A)}const w={};for(const f of S)w[f.name]=f.value;const I={};v.length&&(I.cookie=v.map(f=>`${encodeURIComponent(f.name)}=${encodeURIComponent(f.value)}`).join("; ")),Object.assign(I,w);const j={};for(const f of C)V(j,f.name,f.value);const B=x?.text?ue(x.text):void 0;let _;if(x?.params?.length){_={};for(const f of x.params)V(_,f.name,f.value??"")}const P=C.map(f=>`${encodeURIComponent(f.name)}=${encodeURIComponent(f.value)}`).join("&"),q=P?`${s}?${P}`:s;return{method:e.method.toUpperCase(),url:s,pathname:q,httpVersion:"HTTP/1.1",cookies:v,headers:S,queryString:C,postData:x,headersSize:-1,bodySize:-1,fullUrl:q,headersObj:w,allHeaders:I,queryObj:j,jsonObj:B,paramsObj:_,basicAuth:y.basicAuth,pathParameters:U,serverVariables:t,responseCodes:e.responseCodes,allResponseCodes:e.responseCodes,oAuth2PreRequests:y.oAuth2PreRequests}}function V(e,n,a){const r=e[n];r===void 0?e[n]=a:Array.isArray(r)?r.push(a):e[n]=[r,a]}function Z(e,n){if(e.length){if(n?.length){const a=e.find(r=>{const o=r.schemes.map(u=>u.id);return o.length===n.length&&o.every(u=>n.includes(u))});if(a)return a}return e[0]}}function ee(e,n,a,r){const o={headers:[],cookies:[],queries:[]};if(!e)return o;for(const u of e.schemes)ne(u,o,n,a,r,e.scopes);return o}const te={"x-defaultUsername":g.Username,"x-defaultPassword":g.Password,"x-defaultClientId":g.ClientId,"x-defaultClientSecret":g.ClientSecret};function ne(e,n,a,r,o,u=[]){const c=a.requestValues?.security,t=l=>{const s=e.serverValues?.[o];if(s){const y=s[l];if(y!=null)return String(y)}const d=e[l];if(d!=null&&typeof d=="string")return d;const i=c?.[l];if(i!=null)return String(i);const p=l==="x-defaultAccessToken"?e.type==="apiKey"?g.APIKey:g.Token:te[l],m=p!==void 0?a.environment?.[e.id+p]:void 0;if(m)return m};if(e.type==="http"&&e.scheme==="basic")n.basicAuth={username:t("x-defaultUsername")||c?.username||"<username>",password:t("x-defaultPassword")||c?.password||"<password>"};else if(e.type==="http"){const l=t("x-defaultAccessToken"),s=e.scheme||"bearer",d=s.charAt(0).toUpperCase()+s.slice(1),i=e.bearerFormat?`<YOUR_${e.bearerFormat}_HERE>`:"<YOUR_TOKEN_HERE>";n.headers.push({name:"Authorization",value:l?`${d} ${l}`:`${d} ${i}`})}else if(e.type==="apiKey"&&e.name){const l=t("x-defaultAccessToken")||"YOUR_API_KEY_HERE",s={name:e.name,value:l};e.in==="header"?n.headers.push(s):e.in==="cookie"?n.cookies.push({name:e.name,value:l}):(e.in==="query"||e.in==="querystring"||e.in===void 0)&&n.queries.push({name:e.name,value:l})}else if(e.type==="oauth2"){const l=t("x-defaultAccessToken"),s=t("x-defaultTokenType")||"Bearer";if(n.headers.push({name:"Authorization",value:l?`${s} ${l}`:"Bearer <YOUR_TOKEN_HERE>"}),r.withOAuth2Call&&e.flows){const d=[];if(e.flows.deviceAuthorization){const i=e.flows.deviceAuthorization;d.push(ae(i.deviceAuthorizationUrl,i.tokenUrl,e,o,u))}else if(e.flows.clientCredentials){const i=e.flows.clientCredentials;d.push(z("clientCredentials",i.tokenUrl,e,o,u))}else if(e.flows.password){const i=e.flows.password;d.push(z("password",i.tokenUrl,e,o,u))}d.length>0&&(n.oAuth2PreRequests=(n.oAuth2PreRequests??[]).concat(d))}}else if(e.type==="openIdConnect"){const l=t("x-defaultAccessToken"),s=t("x-defaultTokenType")||"Bearer";n.headers.push({name:"Authorization",value:l?`${s} ${l}`:"Bearer <YOUR_TOKEN_HERE>"})}}function ae(e,n,a,r,o=[]){const u=a.serverValues?.[r]?.["x-defaultClientId"]||a["x-defaultClientId"]||"YOUR_CLIENT_ID",c=[{name:"client_id",value:u}];return o.length>0&&c.push({name:"scope",value:o.join(" ")}),{flowType:"deviceAuthorization",tokenUrl:n,clientId:u,scopes:o.length>0?o:void 0,method:"POST",url:e,httpVersion:"HTTP/1.1",cookies:[],headers:[{name:"Content-Type",value:"application/x-www-form-urlencoded"},{name:"Accept",value:"application/json"}],queryString:[],postData:{mimeType:"application/x-www-form-urlencoded",params:c,text:c.map(t=>`${encodeURIComponent(t.name)}=${encodeURIComponent(t.value??"")}`).join("&")},headersSize:-1,bodySize:-1}}function z(e,n,a,r,o=[]){const u=a.serverValues?.[r]?.["x-defaultClientId"]||a["x-defaultClientId"]||"YOUR_CLIENT_ID",c=a.serverValues?.[r]?.["x-defaultClientSecret"]||a["x-defaultClientSecret"],t=a.serverValues?.[r]?.["x-defaultUsername"]||a["x-defaultUsername"],l=a.serverValues?.[r]?.["x-defaultPassword"]||a["x-defaultPassword"],s=[];return e==="clientCredentials"?s.push({name:"grant_type",value:"client_credentials"}):e==="password"&&s.push({name:"grant_type",value:"password"}),s.push({name:"client_id",value:u}),s.push({name:"client_secret",value:c||"YOUR_CLIENT_SECRET"}),e==="password"&&(s.push({name:"username",value:t||"<username>"}),s.push({name:"password",value:l||"<password>"})),o.length>0&&s.push({name:"scope",value:o.join(" ")}),{flowType:e,tokenUrl:n,clientId:u,clientSecret:c,username:t,password:l,scopes:o.length>0?o:void 0,method:"POST",url:n,httpVersion:"HTTP/1.1",cookies:[],headers:[{name:"Content-Type",value:"application/x-www-form-urlencoded"},{name:"Accept",value:"application/json"}],queryString:[],postData:{mimeType:"application/x-www-form-urlencoded",params:s,text:s.map(d=>`${encodeURIComponent(d.name)}=${encodeURIComponent(d.value??"")}`).join("&")},headersSize:-1,bodySize:-1}}function N(e,n,a){return n==="querystring"&&e.serializationMime===k.URL_ENCODED&&typeof a=="object"&&a!==null?re(J(a)):null}function re(e){const n=new Map,a=[];for(const r of e){const o=n.get(r.name);o?o.push(r.value):(n.set(r.name,[r.value]),a.push(r.name))}return a.map(r=>({name:r,value:(n.get(r)??[]).join(",")}))}function b(e,n,a,r,o,u,c){return e.filter(t=>!o.skipOptionalParameters||t.required).flatMap(t=>{const s=r[n==="querystring"?"query":n]?.[t.name];if(s!=null)return[{name:t.name,value:String(s)}];const d=t.serverValues?.[a]?.example;if(d!=null)return[{name:t.name,value:T(t,d)}];if(t.example!=null){const i=N(t,n,t.example);return i||(t.serializationMime&&u.serializeParameter?[{name:t.name,value:u.serializeParameter(t,t.example)}]:[{name:t.name,value:T(t,t.example)}])}if(n==="querystring"&&t.serializationMime===k.URL_ENCODED&&t.schemaId){const i=u.resolveSchema(t.schemaId);if(i){const p=u.sampleFromSchema(i,c),m=N(t,n,p);if(m)return m}}return[{name:t.name,value:oe(t,u,c)}]})}function oe(e,n,a){if(e.schemaId){const r=n.resolveSchema(e.schemaId);if(r){const o=n.sampleFromSchema(r,a);if(o!=null)return e.serializationMime&&n.serializeParameter?n.serializeParameter(e,o):T(e,o)}}return`{${e.name}}`}function ie(e){switch(e){case"query":case"querystring":case"cookie":return"form";case"path":case"header":return"simple";default:return"form"}}function T(e,n){if(n==null)return"";if(typeof n!="object")return String(n);const a=e.style??ie(e.in),o=e.explode??a==="form"?"*":"",u="__redoc_param_name__";try{switch(a){case"form":{const l=$.parse(`{?${u}${o}}`).expand({[u]:n}).substring(1).replace(/__redoc_param_name__/g,e.name).split(`&${e.name}=`);return l[0]=l[0].replace(new RegExp(`^${se(e.name)}=`),""),l.map(D).join(",")}case"spaceDelimited":return Array.isArray(n)?n.map(String).join(" "):String(n);case"pipeDelimited":return Array.isArray(n)?n.map(String).join("|"):String(n);case"simple":case"label":case"matrix":{const c=a==="label"?".":a==="matrix"?";":"",t=$.parse(`{${c}${u}${o}}`);return D(t.expand({[u]:n}).replace(/__redoc_param_name__/g,e.name))}case"deepObject":return JSON.stringify(n);default:return JSON.stringify(n)}}catch{return Array.isArray(n)?n.map(String).join(","):JSON.stringify(n)}}function se(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function D(e){try{return decodeURIComponent(e)}catch{return e}}function le(e,n,a,r,o,u,c){let t;if(a.replayBody!==void 0&&(t=a.replayBody),t===void 0&&a.exampleName){const i=Q(e.exampleIds,a.exampleName,r.resolveExample),p=i?r.resolveExample(i):void 0;p&&(t=p.value)}if(t===void 0&&e.exampleIds?.length){const i=r.resolveExample(e.exampleIds[0]);i&&(t=i.value)}if(t===void 0&&e.schemaId){const i=r.resolveVariantSchemaForSampling?.(e.schemaId),p=i?.schema??r.resolveSchema(e.schemaId),m=i?.variantSchemaId??e.schemaId;if(p){const y=n.toLowerCase().includes("xml");t=r.sampleFromSchema(p,{...o,format:y?"xml":o.format}),t&&typeof t=="object"&&!Array.isArray(t)&&m!==e.schemaId&&r.applyDiscriminatorValue?.(t,m,i?.mappingKey)}}if(c!==void 0&&a.replayBody===void 0&&(t===void 0?t=c:t=F(t,c)),t===void 0)return;const l=n.toLowerCase();let s,d=[];if(l.includes("x-www-form-urlencoded"))typeof t=="object"&&t!==null?(d=Object.entries(t).map(([i,p])=>({name:i,value:E(p)})),s=K(t)):s=String(t);else if(l.includes("multipart/form-data"))typeof t=="string"?(d=M(t)??[],s=t):(typeof t=="object"&&t!==null&&!Array.isArray(t)&&(d=Object.entries(t).map(([i,p])=>({name:i,value:E(p)}))),s=JSON.stringify(t,null,2));else if(H(l))if(typeof t=="string")s=t;else{const i=e.schemaId?r.resolveSchema(e.schemaId):void 0;s=String(Y(t,l,i,!0))}else l.includes("json")?s=typeof t=="string"?t:JSON.stringify(t,null,2):l.includes("xml")?s=typeof t=="string"?t:t&&typeof t=="object"?L(t):String(t):s=typeof t=="string"?t:JSON.stringify(t,null,2);return{mimeType:n,params:d,text:s}}function ue(e){try{const n=JSON.parse(e);if(n&&typeof n=="object"&&!Array.isArray(n))return n}catch{}}export{Ie as buildCodeSampleHAR};
|
|
@@ -2,9 +2,11 @@ import type { SchemaEntry } from '../../types/store.js';
|
|
|
2
2
|
export type EffectiveDiscriminator = {
|
|
3
3
|
propertyName: string;
|
|
4
4
|
mapping: Record<string, string>;
|
|
5
|
+
defaultMapping?: string;
|
|
6
|
+
variantsNode?: Record<string, unknown>;
|
|
5
7
|
};
|
|
6
8
|
export declare function findEffectiveDiscriminator(schemaData: Record<string, unknown> | undefined, schemaStore: Record<string, SchemaEntry>, visited?: Set<string>): EffectiveDiscriminator | undefined;
|
|
7
|
-
export declare function applyDiscriminatorValue(sample: Record<string, unknown>, variantSchemaId: string, schemaStore: Record<string, SchemaEntry
|
|
9
|
+
export declare function applyDiscriminatorValue(sample: Record<string, unknown>, variantSchemaId: string, schemaStore: Record<string, SchemaEntry>, mappingKey?: string): void;
|
|
8
10
|
export type SchemaVariantOption = {
|
|
9
11
|
label: string;
|
|
10
12
|
schemaId: string;
|
|
@@ -12,6 +14,11 @@ export type SchemaVariantOption = {
|
|
|
12
14
|
isDefaultMapping?: boolean;
|
|
13
15
|
isDeprecated?: boolean;
|
|
14
16
|
};
|
|
17
|
+
export type HoistedVariant = {
|
|
18
|
+
schema: Record<string, unknown>;
|
|
19
|
+
variantSchemaId: string;
|
|
20
|
+
mappingKey?: string;
|
|
21
|
+
};
|
|
15
22
|
export type SchemaVariantAxis = {
|
|
16
23
|
kind: 'discriminator' | 'oneOf' | 'anyOf';
|
|
17
24
|
stateKey: string;
|
|
@@ -25,15 +32,14 @@ export declare function findSchemaVariantAxis(schemaId: string, schemaStore: Rec
|
|
|
25
32
|
}): SchemaVariantAxis | undefined;
|
|
26
33
|
export declare function resolveActiveVariantIndex(axis: SchemaVariantAxis, activeDiscriminator?: Record<string, number>, activeOneOf?: Record<string, number>): number;
|
|
27
34
|
export declare function resolveActiveVariantSchemaId(schemaId: string, schemaStore: Record<string, SchemaEntry>, activeDiscriminator?: Record<string, number>, activeOneOf?: Record<string, number>): string;
|
|
28
|
-
export declare function hoistActiveVariantSchemaForSampling(schemaId: string, schemaStore: Record<string, SchemaEntry>, activeDiscriminator?: Record<string, number>, activeOneOf?: Record<string, number>):
|
|
29
|
-
schema: Record<string, unknown>;
|
|
30
|
-
variantSchemaId: string;
|
|
31
|
-
} | undefined;
|
|
35
|
+
export declare function hoistActiveVariantSchemaForSampling(schemaId: string, schemaStore: Record<string, SchemaEntry>, activeDiscriminator?: Record<string, number>, activeOneOf?: Record<string, number>): HoistedVariant | undefined;
|
|
32
36
|
/**
|
|
33
|
-
* Deep-collapse inline nested
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
+
* Deep-collapse inline nested variant axes to the active option so generated
|
|
38
|
+
* samples follow the switcher: oneOf/anyOf collapse to the active branch
|
|
39
|
+
* (default 0) — so null branches sample as `null`: the sampler turns any
|
|
40
|
+
* surviving `oneOf: [{type: 'null'}]` wrapper into `{}` — and inline
|
|
41
|
+
* discriminator hosts collapse to the active variant with its mapping key
|
|
42
|
+
* stamped. Returns a structural clone.
|
|
37
43
|
*/
|
|
38
|
-
export declare function applyActiveVariantsToSchema(data: Record<string, unknown>, schemaStore: Record<string, SchemaEntry>, activeOneOf?: Record<string, number>, parentPath?: string[]): Record<string, unknown>;
|
|
44
|
+
export declare function applyActiveVariantsToSchema(data: Record<string, unknown>, schemaStore: Record<string, SchemaEntry>, activeDiscriminator?: Record<string, number>, activeOneOf?: Record<string, number>, parentPath?: string[]): Record<string, unknown>;
|
|
39
45
|
export declare function applyActiveVariantsToStore(schemaStore: Record<string, SchemaEntry>, activeDiscriminator?: Record<string, number>, activeOneOf?: Record<string, number>): Record<string, Record<string, unknown>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{buildVariantStateKey as
|
|
1
|
+
import{buildVariantStateKey as j}from"../../jotai/itemStore.js";import{deriveVariantLabel as B}from"../schema/variant-label.js";function g(n){return n.discriminator}function O(n){return n.startsWith("#/")?n.slice(2):n}function _(n,r,o=new Set){if(!n)return;const i=g(n);if(i?.propertyName&&(i.mapping||n.oneOf||n.anyOf))return{propertyName:i.propertyName,mapping:i.mapping??{},...i.defaultMapping&&{defaultMapping:i.defaultMapping},...(Array.isArray(n.oneOf)||Array.isArray(n.anyOf))&&{variantsNode:n}};const t=n.allOf;if(Array.isArray(t))for(const e of t){if(!e||typeof e!="object")continue;const f=e;if(typeof f.$ref=="string"){const s=O(f.$ref);if(o.has(s))continue;o.add(s);const c=r[s];if(c){const p=_(c.data,r,o);if(p)return p}continue}const a=_(f,r,o);if(a)return a}}function tn(n,r,o,i){for(const t of Object.values(o)){const e=g(t.data);if(!(!e?.propertyName||!e.mapping)&&e.propertyName in n){if(i!==void 0){const f=e.mapping[i];if(f&&O(f)===r){n[e.propertyName]=i;return}continue}if(e.defaultMapping&&O(e.defaultMapping)===r)return;for(const[f,a]of Object.entries(e.mapping))if(O(a)===r){n[e.propertyName]=f;return}}}}function K({oneOfList:n,oneOfOwner:r,extraSiblings:o,fallbackSchemaId:i,schemaStore:t,activeIdx:e=0}){const f=e>=0&&e<n.length?e:0,a=n[f],s=M(a,t);if(!s)return;const{oneOf:c,anyOf:p,...d}=r,u=[...o,d].filter(V),y=[...Array.isArray(s.allOf)?s.allOf:[],...u],{allOf:m,...I}=s,E=y.length?{...I,allOf:y}:{...I},N=R(a,t)??i;return{schema:E,variantSchemaId:N}}function V(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&Object.keys(n).length>0}function M(n,r){if(!n||typeof n!="object")return;const o=n;if(typeof o.$ref!="string")return o;const i=O(o.$ref);return r[i]?.data}function R(n,r){if(!n||typeof n!="object")return;const o=n;if(typeof o.$ref!="string")return;const i=O(o.$ref);return r[i]?i:void 0}const P="One of:",z="Any of:",G="Default mapping";function v(n){return!!n?.deprecated}function U(n,r){if(!n||typeof n!="object")return{};const o=n;if(typeof o.$ref=="string"){const i=r[O(o.$ref)];if(!i)return{};const t={...i.data};return t["x-original-ref"]=o.$ref,t}return o}function T(n,r){const o=O(n),i=r[o];return i?{schemaId:o,entry:i}:void 0}function X(n,r,o){const i=Object.entries(n.mapping);if(i.length===0)return;const t=n.defaultMapping,e=[];for(const[a,s]of i){const c=T(s,r);c&&e.push({label:a,schemaId:c.schemaId,mappingKey:a,isDeprecated:v(c.entry.data)})}const f=t?T(t,r):void 0;if(t&&f){const a=t.split("/").pop(),s=e.findIndex(c=>c.label===a);s!==-1&&e.splice(s,1),e.push({label:G,schemaId:f.schemaId,isDefaultMapping:!0,isDeprecated:v(f.entry.data)})}return{kind:"discriminator",stateKey:j(o,n.propertyName),options:e,localPart:n.propertyName,parentPath:o}}function A(n,r,o,i,t){if(!n.length)return;const e=t==="anyOf"?z:P,f=[],a=new Map;for(let s=0;s<n.length;s++){const c=n[s],p=U(c,o),{label:d}=B(p,r),u=(a.get(d)??0)+1;a.set(d,u);const l=u===1?d:`${d} (${u})`,y=R(c,o)??"";f.push({label:l,schemaId:y,isDeprecated:v(o[y]?.data??c)})}return{kind:t,stateKey:j(i,e),options:f,localPart:e,parentPath:i}}function x(n,r,o){const i=_(n,r);if(i){const t=X(i,r,o);if(t&&t.options.length>0)return t;const e=i.variantsNode??n;for(const f of["oneOf","anyOf"]){const a=e[f];if(!Array.isArray(a)||a.length===0)continue;const s=A(a,e,r,o,f);if(s&&s.options.length>0)return{...s,kind:"discriminator",localPart:i.propertyName,stateKey:j(o,i.propertyName)}}}if(Array.isArray(n.oneOf)&&n.oneOf.length>0){const t=A(n.oneOf,n,r,o,"oneOf");if(t&&t.options.length>0)return t}if(Array.isArray(n.anyOf)&&n.anyOf.length>0){const t=A(n.anyOf,n,r,o,"anyOf");if(t&&t.options.length>0)return t}}function k(n,r,o=new Map,i=new Set,t=[]){if(!n)return o;const e=(s,c=t)=>{if(!s||typeof s!="object")return;const p=s;if(typeof p.$ref=="string"){const u=O(p.$ref);if(i.has(u))return;i.add(u);const l=r[u]?.data;if(!l)return;const y=x(l,r,c);y&&y.options.length>1&&o.set(y.stateKey,y),k(l,r,o,i,c);return}const d=x(p,r,c);d&&d.options.length>1&&o.set(d.stateKey,d),k(p,r,o,i,c)},f=n.properties;if(f&&typeof f=="object")for(const[s,c]of Object.entries(f))e(c,[...t,s]);const a=t.length>0?[...t.slice(0,-1),`${t[t.length-1]}[]`]:t;e(n.items,a);for(const s of["oneOf","anyOf","allOf"]){const c=n[s];if(Array.isArray(c))for(const p of c)e(p,t)}return o}function Y(n,r,{includeNested:o=!1}={}){const i=r[n];if(!i)return;const t=x(i.data,r,[]);if(t&&t.options.length>0)return t;if(!o)return;const e=k(i.data,r);if(e.size===1)return e.values().next().value}function b(n,r,o){const i=n.kind==="discriminator"?r:o;if(!i)return 0;const t=i[n.stateKey];if(t!==void 0&&t>=0&&t<n.options.length)return t;const e=Object.entries(i).filter(([f])=>f.endsWith(`/${n.stateKey}`)||f.includes("/")&&n.stateKey.endsWith(`/${f}`));if(e.length===1){const[,f]=e[0];if(f>=0&&f<n.options.length)return f}return 0}function w(n,r,o,i){const t=Y(n,r);if(!t)return;const e=b(t,o,i),f=t.options[e]??t.options[0];if(!(!f?.schemaId||!r[f.schemaId]))return f}function en(n,r,o,i){return w(n,r,o,i)?.schemaId??n}function rn(n,r,o,i){const t=q(n,r,i);if(t)return t;const e=w(n,r,o,i);if(!e||e.schemaId===n)return;const f=r[e.schemaId];if(f)return{schema:f.data,variantSchemaId:e.schemaId,mappingKey:e.mappingKey}}function q(n,r,o){const i=r[n];if(!i||g(i.data))return;const t=i.data;if(Array.isArray(t.oneOf)&&t.oneOf.length>0){const e=A(t.oneOf,t,r,[],"oneOf"),f=e?b(e,void 0,o):0;return K({oneOfList:t.oneOf,oneOfOwner:t,extraSiblings:[],fallbackSchemaId:n,schemaStore:r,activeIdx:f})}if(Array.isArray(t.anyOf)&&t.anyOf.length>0){const e=A(t.anyOf,t,r,[],"anyOf"),f=e?b(e,void 0,o):0;return K({oneOfList:t.anyOf,oneOfOwner:t,extraSiblings:[],fallbackSchemaId:n,schemaStore:r,activeIdx:f})}if(Array.isArray(t.allOf)){let e,f,a="oneOf";const s=[];for(const d of t.allOf){const u=M(d,r)??d,l=Array.isArray(u.oneOf)?u.oneOf:Array.isArray(u.anyOf)?u.anyOf:void 0;!f&&l?.length&&!g(u)?(e=u,f=l,a=Array.isArray(u.oneOf)?"oneOf":"anyOf"):s.push(d)}if(!f||!e)return;const c=A(f,e,r,[],a),p=c?b(c,void 0,o):0;return K({oneOfList:f,oneOfOwner:e,extraSiblings:s,fallbackSchemaId:n,schemaStore:r,activeIdx:p})}}function J(n){return n.length===0?n:[...n.slice(0,-1),`${n[n.length-1]}[]`]}function Q(n,r,o,i,t){const e=g(n);if(!e?.propertyName)return;const f=x(n,r,o);if(!f)return;const a=b(f,i,t),s=f.options[a]??f.options[0];if(!s?.schemaId||!r[s.schemaId])return;const{oneOf:c,anyOf:p,discriminator:d,...u}=n,l={allOf:[{$ref:`${$}${s.schemaId}`}]};return{...u,...H(l,e.propertyName,s.mappingKey)}}function Z(n,r,o,i,t=[]){const e=(f,a,s=!1)=>{if(!f||typeof f!="object")return f;if(Array.isArray(f))return f.map(d=>e(d,a));const c=f;if(typeof c.$ref=="string")return c;if(!s){const d=Q(c,r,a,o,i);if(d)return e(d,a)}if(!g(c))for(const d of["oneOf","anyOf"]){const u=c[d];if(!Array.isArray(u)||u.length===0)continue;const l=A(u,c,r,a,d),y=l?b(l,void 0,i):0,m=u[y]??u[0];if(!V(m))continue;const{oneOf:I,anyOf:E,...N}=c;return e({...N,...m},a)}const p={};for(const[d,u]of Object.entries(c))if(d==="properties"&&V(u)){const l={};for(const[y,m]of Object.entries(u))l[y]=e(m,[...a,y]);p[d]=l}else d==="items"?p[d]=e(u,J(a)):d==="allOf"||d==="oneOf"||d==="anyOf"?p[d]=e(u,a):p[d]=u;return p};return e(n,t,!0)}function C(n,r){return n.type!==void 0||r.type===void 0?n:{...n,type:r.type}}function on(n,r,o){const i={};for(const[t,e]of Object.entries(n)){if(!e.data)continue;const f=g(e.data);if(f?.propertyName&&(f.mapping||Array.isArray(e.data.oneOf)||Array.isArray(e.data.anyOf))){const s=w(t,n,r,o),c=s&&s.schemaId!==t?n[s.schemaId]?.data:void 0;if(c){const p=W(c,t,e.data);i[t]=C(H(p,f.propertyName,s?.mappingKey),e.data)}else i[t]=e.data;continue}let a=!1;for(const s of["oneOf","anyOf"]){const c=e.data[s];if(!Array.isArray(c))continue;const p=A(c,e.data,n,[],s);if(!p||p.options.length<=1)continue;const d=b(p,void 0,o),u=p.options[d]??p.options[0];if(!u?.schemaId||!n[u.schemaId])continue;const l=n[u.schemaId].data;i[t]=C(W(l,t,e.data),e.data),a=!0;break}a||(i[t]=e.data)}for(const[t,e]of Object.entries(i))i[t]=Z(e,n,r,o);return i}const $="#/";function H(n,r,o){if(!o)return n;const i={properties:{[r]:{enum:[o]}}};return Array.isArray(n.allOf)?{...n,allOf:[...n.allOf,i]}:{allOf:[n,i]}}function D(n){const r=new Set([`${$}${n}`]);return n.startsWith("components/schemas/")?r.add(`${$}${n.replace("components/schemas/","")}`):r.add(`${$}components/schemas/${n}`),Array.from(r)}function h(n){const{discriminator:r,oneOf:o,anyOf:i,...t}=n;return t}function W(n,r,o){const i=D(r);if(!L(n,i))return n;const t=h(o);return F(n,i,t)}function L(n,r){if(!n||typeof n!="object")return!1;if(Array.isArray(n))return n.some(i=>L(i,r));const o=n;if(typeof o.$ref=="string"&&r.includes(o.$ref))return!0;for(const i of Object.values(o))if(L(i,r))return!0;return!1}function F(n,r,o){if(!n||typeof n!="object")return n;if(Array.isArray(n))return n.map(e=>F(e,r,o));const i=n;if(typeof i.$ref=="string"&&r.includes(i.$ref))return{...o};const t={};for(const[e,f]of Object.entries(i))t[e]=F(f,r,o);return t}export{Z as applyActiveVariantsToSchema,on as applyActiveVariantsToStore,tn as applyDiscriminatorValue,k as collectNestedVariantAxes,_ as findEffectiveDiscriminator,Y as findSchemaVariantAxis,rn as hoistActiveVariantSchemaForSampling,b as resolveActiveVariantIndex,en as resolveActiveVariantSchemaId};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import*as s from"openapi-sampler";import{serializeParameterValue as l}from"../../utils/serialize-parameter.js";import{applyActiveVariantsToSchema as u,applyActiveVariantsToStore as c,applyDiscriminatorValue as y,hoistActiveVariantSchemaForSampling as d}from"./discriminator.js";function f(n,p,o){const a=c(n,p,o),t={};for(const[i,r]of Object.entries(a)){const e=i.startsWith("components/schemas/")?i.replace("components/schemas/",""):i;t[e]=r}return{openapi:"3.0.0",info:{title:"",version:""},paths:{},components:{schemas:t}}}function k(n,p,o,a,t){const i=f(n,a,t);return{resolveSchema(r){return n[r]?.data},resolveExample(r){const e=p[r];if(e)return{value:e.value,summary:e.summary,key:e.key}},sampleFromSchema(r,e){try{return s.sample(r,{skipReadOnly:e.skipReadOnly,skipWriteOnly:e.skipWriteOnly,quiet:!0,skipNonRequired:o.onlyRequiredInSamples,maxSampleDepth:e.maxDepth??o.generatedSamplesMaxDepth,...e.format==="xml"&&{format:"xml"}},i)}catch{return}},serializeParameter(r,e){return typeof e!="object"||e===null?String(e??""):l({name:r.name,in:r.in},e)},resolveVariantSchemaForSampling(r){const e=d(r,n,a,t),m=e?.schema??n[r]?.data;if(m)return{schema:u(m,n,a,t),variantSchemaId:e?.variantSchemaId??r,mappingKey:e?.mappingKey}},applyDiscriminatorValue(r,e,m){!r||typeof r!="object"||Array.isArray(r)||y(r,e,n,m)}}}export{f as buildOpenApiStubForSampler,k as createCodeSampleResolvers};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import type { SchemaProcessorDialect } from '../../../types/schema.js';
|
|
1
|
+
import type { SchemaProcessorDialect, Document } from '../../../types/schema.js';
|
|
2
|
+
export declare function getImplicitDiscriminatorChildren(document: Document): Record<string, Array<{
|
|
3
|
+
ref: string;
|
|
4
|
+
value: string;
|
|
5
|
+
}>>;
|
|
2
6
|
export declare const JsonSchemaDialectId: "json-schema";
|
|
3
7
|
export declare const jsonSchemaDialect: SchemaProcessorDialect;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{merge as
|
|
1
|
+
import{merge as M,openApiJsonSchemaMergeRules as j}from"@redocly/allof-merge";import{schemaKind as P}from"../../../types/common.js";import{isSchemaNode as l}from"../../../types/schema.js";import{encodeJsonPointerSegment as A}from"../../../utils/refPointer.js";import{buildPropertyTree as D}from"../propertyTreeBuilder.js";function J(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function O(e,r){if(!r.startsWith("#/"))return;const i=r.slice(2).split("/").map(J);let n=e;for(const t of i){if(!l(n))return;n=n[t]}return l(n)?n:void 0}function h(e,r,i,n,t,f=!1){if(!e||typeof e!="object")return e;if(Array.isArray(e)){const s=i??new Set;return e.map(o=>h(o,r,s,n,t,f))}if(!l(e))return e;const c=i??new Set;if(e.$ref!==void 0){const s=e.$ref;if(typeof s!="string")return e;if(c.has(s)){for(const k of c)t?.add(k);const g=O(r,s);if(!l(g))return{"x-circular-ref":!0};if(f&&g.allOf!==void 0)return{};const{allOf:u,oneOf:m,anyOf:x,...y}=g;return{...y,"x-circular-ref":!0,"x-original-ref":s}}const o=n?.get(s);if(o&&l(o)){const g={};for(const[u,m]of Object.entries(e))u!=="$ref"&&(g[u]=h(m,r,c,n,t));return w({...o,...g,"x-original-ref":s},r)}const p=O(r,s);if(!p)return e;c.add(s);const a=h(p,r,c,n,t,f);c.delete(s);const d={};for(const[g,u]of Object.entries(e))g!=="$ref"&&(d[g]=h(u,r,c,n,t));return l(a)?(t?.has(s)||n?.set(s,a),w({...a,...d,"x-original-ref":s},r)):a}return Object.fromEntries(Object.entries(e).map(([s,o])=>[s,h(o,r,c,n,t,s==="allOf"&&Array.isArray(o))]))}function b(e,r,i,n){const t="openapi"in r?r.openapi:void 0,f=typeof t=="string"&&t.startsWith("3.0")?"3.0.x":"3.1.x",s=h(e,r,n,i,new Set),o=l(s)?w(s,r):e,p=M(o,{mergeCombinarySibling:!0,applyAdditionalPropertiesToSiblings:!1,rules:j(f)});return l(p)?p:o}function C(e,r){const i=[],n=new Set,t=f=>{const c=O(e,f);if(!(!l(c)||!Array.isArray(c.allOf)))for(const s of c.allOf)l(s)&&typeof s.$ref=="string"&&i.push(s.$ref)};for(t(r);i.length>0;){const f=i.pop();if(f===r)return!0;n.has(f)||(n.add(f),t(f))}return!1}function $(e,r){if(!Array.isArray(e.allOf))return[];const i=[],n=t=>{i.includes(t)||i.push(t)};for(const t of e.allOf){if(!l(t))continue;if(Array.isArray(t.allOf)){const c=t["x-original-ref"];t.discriminator&&typeof c=="string"&&!C(r,c)&&n(c);for(const s of $(t,r))n(s);continue}const f=t["x-original-ref"];typeof f=="string"&&n(f)}return i}function w(e,r){const i=$(e,r);return i.length>0&&(e["x-parentRefs"]=i),e}const R=new WeakMap;function W(e){const r=R.get(e);if(r)return r;const i=e.components?.schemas,n={};if(i&&typeof i=="object")for(const[t,f]of Object.entries(i)){if(!l(f)||!Array.isArray(f.allOf))continue;const c=typeof f["x-discriminator-value"]=="string"?f["x-discriminator-value"]:t,s=`#/components/schemas/${A(t)}`;for(const o of f.allOf)l(o)&&typeof o.$ref=="string"&&(n[o.$ref]??=[]).push({ref:s,value:c})}return R.set(e,n),n}const v=new WeakMap;function S(e,r){if(!l(e)){if(Array.isArray(e))for(const t of e)S(t,r);return}for(const[t,f]of Object.entries(e))t==="$ref"&&typeof f=="string"?r.add(f):S(f,r);const i=e.discriminator??e["x-discriminator"],n=l(i)?i.mapping:void 0;if(l(n))for(const t of Object.values(n))typeof t=="string"&&r.add(t)}function I(e){const r=new Set;let i=0;const n=new Map,t=new Map,f=new Set,c=[];for(const s of e.keys()){if(n.has(s))continue;const o=[{node:s,edge:0}];for(;o.length>0;){const p=o[o.length-1],{node:a}=p;p.edge===0&&(n.set(a,i),t.set(a,i),i++,c.push(a),f.add(a));const d=e.get(a)??[];if(p.edge<d.length){const u=d[p.edge];if(p.edge++,!e.has(u))continue;n.has(u)?f.has(u)&&t.set(a,Math.min(t.get(a)??0,n.get(u)??0)):o.push({node:u,edge:0});continue}if((t.get(a)??0)===(n.get(a)??0)){const u=[];let m="";do m=c.pop()??a,f.delete(m),u.push(m);while(m!==a);const x=(e.get(u[0])??[]).includes(u[0]);if(u.length>1||x)for(const y of u)r.add(y)}o.pop();const g=o[o.length-1];g&&t.set(g.node,Math.min(t.get(g.node)??0,t.get(a)??0))}}return r}function N(e){const r=v.get(e);if(r)return r;const i=e.components?.schemas,n=new Map;if(i&&typeof i=="object"){const f=o=>`#/components/schemas/${A(o)}`,c=o=>o.replace(/^#\/components\/schemas\//,"").replace(/~1/g,"/").replace(/~0/g,"~"),s=o=>{const p=i[c(o)];return l(p)&&!!(p.discriminator||p["x-discriminator"])};for(const[o,p]of Object.entries(i)){const a=new Set;S(p,a),n.set(f(o),[...a])}for(const[o,p]of Object.entries(i))if(!(!l(p)||!Array.isArray(p.allOf)))for(const a of p.allOf)l(a)&&typeof a.$ref=="string"&&s(a.$ref)&&n.get(a.$ref)?.push(f(o))}const t=I(n);return v.set(e,t),t}const _=P.JSON_SCHEMA,F={id:_,process(e,r,i){const n=new Map,t=i?.rootJsonPointer??"#",f=t.startsWith("#/")&&e.$ref!==t?new Set([t]):void 0,c=b(e,r,n,f),s={prepareVariant:o=>b(o,r,n),propertyRefCache:new Map,variantResolutionCache:new Map,implicitDiscriminatorChildren:W(r),exampleSerializer:i?.exampleSerializer,sortRequiredPropsFirst:i?.sortRequiredPropsFirst,activeRefs:t.startsWith("#/")?new Set([t]):new Set,depth:0,recursiveRefs:N(r)};return D(c,s,t)}};export{_ as JsonSchemaDialectId,W as getImplicitDiscriminatorChildren,F as jsonSchemaDialect};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{encodeJsonPointerSegment as
|
|
1
|
+
import{encodeJsonPointerSegment as F}from"../../utils/refPointer.js";import{isSchemaNode as b,switcherLabel as S}from"../../types/schema.js";import{buildPropertyShell as Y,detectJsonSchemaType as D,getAccessMode as z,getDiscriminatorObject as j,getDocumentedPrimitiveArrayItems as G,getEnum as U,humanizeConstraints as W,isPrimitiveLikeSchema as x,isStructuredArrayItems as Q,primitiveArrayItemsHaveOwnInfo as Z,promotePrimitiveArrayMetadata as ee,schemaHasType as I,toPropertyExample as L}from"./propertyBuilder.js";import{deriveVariantLabel as ie}from"./variant-label.js";const te=10,re=200;function ne(e,i,r,t){const n=j(i)?`${e}:d`:e;return t?`${n}#rec`:`${n}@${r}`}function N(e){if(e.isCircular)return!0;if(e.properties){for(const i of Object.values(e.properties))if(N(i))return!0}if(e.items){for(const i of e.items)if(N(i))return!0}if(e.switcher)for(const i of Object.values(e.switcher.options)){if(i.isCircular)return!0;if(i.properties){for(const r of Object.values(i.properties))if(N(r))return!0}}return!1}const h=/^#\/components\/(schemas|pathItems)\/([^/]+)$/;function se(e){const i=e.match(h);if(i)return i[2].replace(/~1/g,"/").replace(/~0/g,"~")}function g(e,i,r={},t){const n=Y(e,{...r,exampleSerializer:i.exampleSerializer});if(!n.title){const o=se(t);o&&(n.title=o)}if(n.isCircular||n.isComplex)return n;const s=e["x-original-ref"];if(s&&i.activeRefs.has(s))return n.isCircular=!0,n;if(i.activeRefs.size>te||i.depth>re)return n.isComplex=!0,n;const f=s!==void 0&&i.recursiveRefs.has(s),l=s===void 0?void 0:ne(s,e,t,f);if(l){const o=i.propertyRefCache.get(l);if(o)return{...o,...n}}s&&i.activeRefs.add(s);try{oe(n,e,{...i,depth:i.depth+1},t)}finally{s&&i.activeRefs.delete(s)}return l&&(f||!N(n))&&i.propertyRefCache.set(l,n),n.isExpandable=fe(n),n}function fe(e){if(e.isCircular)return!1;const i=t=>!t.isCircular&&(!!t.switcher||!!t.items?.length||!!(t.properties&&Object.keys(t.properties).length)),r=t=>t.isCircular?!1:!!(t.properties&&Object.values(t.properties).some(i)||t.items?.some(r)||t.switcher&&Object.values(t.switcher.options).some(r));return!!(e.properties&&Object.values(e.properties).some(i)||e.switcher&&Object.values(e.switcher.options).some(r)||e.items?.some(r))}function k(e,i){if(!Array.isArray(e)||e.length===0)return;let r;for(let t=0;t<e.length;t++){const n=e[t];if(!b(n))return;const s=i(n);if(s===void 0)return;if(t===0)r=s;else if(s!==r)return}return r}function M(e,i,r){if(e.example!==void 0||k(i,s=>s.example===void 0?void 0:JSON.stringify(s.example))===void 0)return;const n=Array.isArray(i)?i[0]:void 0;b(n)&&(e.example=L(n.example,r))}function T(e,i){if(e.accessMode!==void 0)return;const r=k(i,z);r&&(e.accessMode=r)}function oe(e,i,r,t){const n=i.type||D(i),s=x(i,n),f=X(i,r,t);if(f){e.switcher=f,M(e,i.oneOf??i.anyOf,r.exampleSerializer),T(e,i.oneOf??i.anyOf),i.properties&&(e.properties=A(i,r,t));return}if(i.oneOf!==void 0){if(e.switcher=E(i.oneOf,S.ONE_OF,r,t,"oneOf",i),M(e,i.oneOf,r.exampleSerializer),T(e,i.oneOf),i.properties){const l=A(i,r,t);e.properties=l;for(const o of Object.values(e.switcher.options))o.properties={...l,...o.properties||{}}}return}if(i.anyOf!==void 0){if(e.switcher=E(i.anyOf,S.ANY_OF,r,t,"anyOf",i),M(e,i.anyOf,r.exampleSerializer),T(e,i.anyOf),i.properties){const l=A(i,r,t);e.properties=l;for(const o of Object.values(e.switcher.options))o.properties={...l,...o.properties||{}}}return}if(i.if&&i.then||i.if&&i.else){e.switcher=Oe(i,r,t);return}!s&&I(n,"object")&&(e.properties=A(i,r,t)),!s&&I(n,"array")&&(e.items=B(i,r,t),P(i)!==void 0&&delete e.example,e.example===void 0&&b(i.items)&&i.items.example!==void 0&&!G(i,n)&&(e.example=L([i.items.example],r.exampleSerializer))),ee(e,i,n,r.exampleSerializer)}function le(e,i){const r=[],t=[],n=[];for(const[s,f]of Object.entries(e))f.isRequired?i.includes(s)?r.push([s,f]):t.push([s,f]):n.push([s,f]);return r.sort(([s],[f])=>i.indexOf(s)-i.indexOf(f)),Object.fromEntries([...r,...t,...n])}function A(e,i,r){const t={},n={...i,isChild:!1},s=e.required||[],f=b(e.default)?e.default:{},l=b(e.example)?e.example:void 0,o=e.properties||{};for(const[u,d]of Object.entries(o)){const p={...d};p.default===void 0&&f[u]!==void 0&&(p.default=f[u]),p.example===void 0&&l?.[u]!==void 0&&(p.example=l[u]);const w=`${r}/properties/${F(u)}`;t[u]=g(p,n,{isRequired:s.includes(u)},w)}for(const[u,d]of Object.entries(e.patternProperties||{})){const p=`${r}/patternProperties/${F(u)}`;t[u]=g(d,n,{isPatternProperty:!0},p)}const a=e.additionalProperties??e.unevaluatedProperties;if(b(a)){const u=(a["x-additionalPropertiesName"]||"property name")+"*",d=`${r}/additionalProperties`;t[u]=g(a,n,{isAdditionalProperty:!0},d)}else a===!0&&(t["property name*"]=g({},n,{isAdditionalProperty:!0},`${r}/additionalProperties`));return i.sortRequiredPropsFirst?q(le(t,s)):q(t)}function q(e){const i={};for(const[r,t]of Object.entries(e).sort(([,n],[,s])=>+!!n.isDeprecated-+!!s.isDeprecated))i[r]=t;return i}function P(e){const i=Array.isArray(e.prefixItems)?e.prefixItems:Array.isArray(e.items)?e.items:void 0;return!i?.length||!Array.isArray(e.example)||!e.example.length||e.example.length>i.length||e.example.some((t,n)=>t!==void 0&&b(i[n])&&i[n].example!==void 0)?void 0:e.example}function B(e,i,r){const t={...i},n=P(e),s=(f,l)=>n?.[l]!==void 0?{...f,example:n[l]}:f;if(Array.isArray(e.prefixItems)){const f=e.prefixItems.map((l,o)=>H(g(s(l,o),t,{},`${r}/prefixItems/${o}`)));return f.push(...K(e.items,t,`${r}/items`)),f}if(Array.isArray(e.items)){const f=e.items.map((l,o)=>H(g(s(l,o),t,{},`${r}/items/${o}`)));return f.push(...K(e.additionalItems,t,`${r}/additionalItems`)),f}return b(e.items)&&(Q(e.items)||!x(e.items,e.items.type||D(e.items))||Z(e.items))?[g(e.items,t,{},`${r}/items`)]:[]}function K(e,i,r){return e!==!0&&!b(e)?[]:[ue(g(e===!0?{}:e,i,{},r))]}function ue(e){return{...e,isAdditionalItems:!0}}function H(e){return{...e,isTupleItem:!0}}function J(e,i){const r=i.prepareVariant({$ref:e});if(b(r))return typeof r.$ref=="string"?void 0:r}function de(e,i,r){if(!i)return!1;const t=J(e,r);return t!==void 0&&j(t)?.propertyName===i}function R(e,i){const r=i.variantResolutionCache.get(e);if(r)return r;const t=J(e,i);if(t){delete t.discriminator,delete t["x-discriminator"],delete t["x-original-ref"];for(const n of["oneOf","anyOf"]){const s=t[n];Array.isArray(s)&&s.some(f=>b(f)&&f["x-original-ref"]===e)&&delete t[n]}return i.variantResolutionCache.set(e,t),t}}const ae="Default mapping";function pe(e,i){if(typeof e["x-original-ref"]=="string")return e["x-original-ref"];if(h.test(i))return i}function X(e,i,r){const t=j(e);if(i.isChild||!t?.propertyName)return;const n=ce(e,t,i,r);return Object.keys(n.options).length>0?n:void 0}function ce(e,i,r,t){const n=i.mapping||{},s=i["x-explicitMappingOnly"]??Object.keys(n).length>0,f=e.oneOf||e.anyOf||[],l=pe(e,t),o={...r,isChild:!0},a=O=>O&&O===l?{...o,activeRefs:new Set([...r.activeRefs].filter(c=>c!==l))}:o,u=e.oneOf!==void 0?"oneOf":"anyOf",d={};if(Object.keys(n).length>0)for(const[O,c]of Object.entries(n)){const m=R(c,r);if(!m)continue;const y=f.findIndex(v=>v["x-original-ref"]===c),C=y>=0?`${t}/${u}/${y}`:t;d[O]=$(m,a(c),!1,C,c)}else for(let O=0;O<f.length;O++){const c=f[O],m=c["x-original-ref"],y=typeof m=="string"?R(m,r):c;if(!y)continue;const C=c.title||m?.split("/").pop()||"Variant",v=`${t}/${u}/${O}`;d[C]=$(y,a(m),!1,v,m)}if(f.length===0&&!s){const O=new Set(Object.values(n)),m=[...(e["x-parentRefs"]??[]).filter(y=>de(y,i.propertyName,r)),...l?[l]:[]];for(const y of m){const C=r.implicitDiscriminatorChildren?.[y];if(C)for(const{ref:v,value:_}of C){if(O.has(v)||Object.hasOwn(d,_))continue;const V=R(v,r);V&&(d[_]=$(V,a(v),!1,t,v))}}}const p=i.defaultMapping,w=p?R(p,r):void 0;if(p&&w){const O=p.split("/").pop();O&&delete d[O];const c=f.findIndex(y=>y["x-original-ref"]===p),m=c>=0?`${t}/${u}/${c}`:t;d[ae]=$(w,a(p),!0,m,p)}return{type:"discriminator",label:S.DISCRIMINATOR,propertyName:i.propertyName,jsonPointer:t,options:d}}function E(e,i,r,t,n,s){const f={},l={...r,isChild:!1};for(let o=0;o<e.length;o++){const a=e[o],u={type:s.type,...a},{label:d,typeLabel:p}=ie(a,s),w=`${t}/${n}/${o}`,O=f[d]?`${d} (${o+1})`:d,c=$(u,l,!1,w,a["x-original-ref"]);c.typeLabel=p,a.title&&(c.title=a.title),f[O]=c}return{type:"oneOf",label:i,jsonPointer:t,options:f}}function Oe(e,i,r){const{if:t,then:n={},else:s={},description:f,...l}=e,o={...i,isChild:!1},a=(...u)=>i.prepareVariant({allOf:u.filter(d=>d!=null)});return{type:"oneOf",label:S.ONE_OF,jsonPointer:r,options:{[t?.["x-displayName"]||t?.title||"case 1"]:$(a(l,n,t),o,!1,r),[s?.["x-displayName"]||s?.title||"case 2"]:$(a(l,s),o,!1,r)}}}function $(e,i,r,t,n){const s={isDeprecated:!!e.deprecated,isDefaultMapping:r};e.description&&(s.description=e.description);const f=(e["x-original-ref"]??n)?.split("/").pop();f&&(s.schemaName=f);const l=z(e);l&&(s.accessMode=l);const o=W(e);o.length&&(s.constraints=o);const a=U(e);if(a&&(s.enum=a),n&&i.activeRefs.has(n))return s.isCircular=!0,s;const u=e.type||D(e);n&&i.activeRefs.add(n);try{const d=X(e,i,t);if(d?(s.switcher=d,e.properties&&(s.properties=A(e,i,t))):e.oneOf!==void 0?(s.switcher=E(e.oneOf,S.ONE_OF,i,t,"oneOf",e),e.properties&&(s.properties=A(e,i,t))):e.anyOf!==void 0?(s.switcher=E(e.anyOf,S.ANY_OF,i,t,"anyOf",e),e.properties&&(s.properties=A(e,i,t))):!x(e,u)&&(I(u,"object")||e.properties)&&(s.properties=A(e,i,t)),!x(e,u)&&I(u,"array")){const p=B(e,i,t);p.length&&(s.items=p)}}finally{n&&i.activeRefs.delete(n)}return s}function ve(e,i,r){return delete e["x-original-ref"],g(e,i,{},r)}export{ve as buildPropertyTree};
|
package/lib/types/store.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
/** Keeps the section under the reading line in view across a content-height swap
|
|
2
|
-
* (response code, oneOf, media type). Call synchronously from
|
|
2
|
+
* (response code, oneOf, media type, example selection). Call synchronously from
|
|
3
|
+
* the state write. */
|
|
3
4
|
export declare function keepReadingSectionAnchored(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/api-docs",
|
|
3
|
-
"version": "0.2.0-next.
|
|
3
|
+
"version": "0.2.0-next.5",
|
|
4
4
|
"description": "Redocly API Documentation Library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@markdoc/markdoc": "0.5.2",
|
|
34
|
-
"@redocly/openapi-core": "2.
|
|
34
|
+
"@redocly/openapi-core": "2.47.0",
|
|
35
35
|
"dompurify": "3.4.13",
|
|
36
36
|
"fast-xml-parser": "5.7.3",
|
|
37
37
|
"graphql": "16.14.2",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"web-vitals": "3.3.1",
|
|
51
51
|
"@redocly/allof-merge": "0.6.9",
|
|
52
52
|
"@redocly/config": "0.53.1",
|
|
53
|
-
"@redocly/redoc-opentelemetry": "0.2.
|
|
54
|
-
"@redocly/replay": "0.28.0-next.
|
|
55
|
-
"@redocly/theme": "^0.69.0-next.
|
|
53
|
+
"@redocly/redoc-opentelemetry": "0.2.3",
|
|
54
|
+
"@redocly/replay": "0.28.0-next.5",
|
|
55
|
+
"@redocly/theme": "^0.69.0-next.5"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@testing-library/jest-dom": "6.6.3",
|
|
@@ -81,6 +81,15 @@
|
|
|
81
81
|
"vitest": "4.1.10",
|
|
82
82
|
"vitest-browser-react": "^2.0.2"
|
|
83
83
|
},
|
|
84
|
+
"nx": {
|
|
85
|
+
"targets": {
|
|
86
|
+
"vitest:test": {
|
|
87
|
+
"dependsOn": [
|
|
88
|
+
"build"
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
84
93
|
"scripts": {
|
|
85
94
|
"start": "vite --open /docs",
|
|
86
95
|
"build": "pnpm run clean && pnpm run ts:check && pnpm run build:lib && pnpm run build:standalone && pnpm run build:minify",
|