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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{jsx as i}from"react/jsx-runtime";import{useAtomValue as l}from"jotai";import{XMLBuilder as m}from"fast-xml-parser";import{JsonViewer as c}from"@redocly/theme/components/JsonViewer/JsonViewer";import{isFormUrlEncoded as d,isJsonLike as f,isXmlLike as p,langFromMime as x,urlFormEncodePayload as g,isSequentialMediaType as y}from"../../utils/index.js";import{globalOptionsAtom as j}from"../../jotai/store.js";import{StyledCodeBlock as k}from"./styled.js";const L=new m({format:!0,cdataPropName:"#cdata"});function B({value:o,mimeType:r,encoding:n,onCopyClick:e,onPanelToggle:s}){const{jsonSamplesExpandLevel:a}=l(j);if(f(r)&&!y(r)){let t;try{t=typeof o=="string"?JSON.parse(o):o}catch{t=o}return i(c,{data:t,expandLevel:a,onCopyClick:e,onPanelToggle:s})}if(typeof o=="object")if(d(r))o=g(o,n);else if(p(r)){const t=Array.isArray(o)?o:{root:o};o=L.build(t)}else o=JSON.stringify(o,null,2);return i(k,{lang:x(r),source:o,header:{className:"code-block-header",controls:{copy:{onClick:e}}}})}export{B as ExampleValue};
1
+ import{jsx as a}from"react/jsx-runtime";import{useAtomValue as i}from"jotai";import{JsonViewer as m}from"@redocly/theme/components/JsonViewer/JsonViewer";import{isJsonLike as p,langFromMime as c,isSequentialMediaType as f}from"../../utils/index.js";import{getExampleValueByMimeType as d}from"../../services/index.js";import{globalOptionsAtom as g}from"../../jotai/store.js";import{StyledCodeBlock as x}from"./styled.js";function J({value:o,mimeType:e,encoding:n,onCopyClick:t,onPanelToggle:s}){const{jsonSamplesExpandLevel:l}=i(g);if(p(e)&&!f(e)){let r;try{r=typeof o=="string"?JSON.parse(o):o}catch{r=o}return a(m,{data:r,expandLevel:l,onCopyClick:t,onPanelToggle:s})}return a(x,{lang:c(e),source:d(o,e,n),header:{className:"code-block-header",controls:{copy:{onClick:t}}}})}export{J as ExampleValue};
@@ -1 +1 @@
1
- import{useAtomValue as u}from"jotai";import{getCodeSample as x}from"../../services/index.js";import{globalStoreAtom as D}from"../../jotai/store.js";import{operationStore as K}from"../../jotai/operation.js";import{environmentAtom as k,getLangKey as f,languageAtom as E,activeMimeNameAtom as j}from"../../jotai/app.js";import{useTranslate as N}from"../../hooks/index.js";function G({payload:t,isWebhook:s,definitionSamples:l,pointer:a,envVariables:r}){const{parser:m,options:{codeSamples:o,generatedSamplesMaxDepth:c}}=u(D),i=u(j),g=u(K(a)),{languages:d}=u(E),[S]=u(k),v=N(),p=new Map(d?.map(({key:e,order:n})=>[e,n])),M=l.filter(e=>p.has(f(e))),y=P(M,r,S),b=new Set(y.map(f));let C=[];if(!s){const e=o.languages?.filter(({lang:n,label:w})=>n!=="Payload"&&!b.has(f({lang:n,label:w})))||[];C=O(e,o,m.definition,c,g,S,v,i)}const L=[...y,...C],A=d?.find(({lang:e})=>e===t?.lang)?.title,h=t&&f({label:A,lang:t.lang});return t&&h&&p.has(h)&&L.push({...t,label:A,order:p.get(h)}),{samples:L.map(e=>{const n=e.label??e.lang;return{key:f(e),title:n,order:typeof p.get(n.toLowerCase())=="number"?p.get(n.toLowerCase()):9999,...e}}).sort((e,n)=>e.order-n.order)}}function O(t,{skipOptionalParameters:s,withOAuth2Call:l},a,r,m,o,c,i){return t.map(({lang:g,label:d,options:S})=>({lang:g,label:d,get:v=>x({...v,lang:g,options:{...S,skipOptionalParameters:s,withOAuth2Call:l,spec:a,generatedPayloadSamplesMaxDepth:r,store:m,activeMimeName:i},environment:o,translate:c})}))}function P(t,s,l){if(!s||!t.length)return t;const a=l?.server;let r={...s.values||{}};return a&&s.serverValues?.[a]&&(r={...r,...s.serverValues[a]}),Object.keys(r).length===0?t:t.map(m=>{const o={...m};return"source"in o&&typeof o.source=="string"&&(o.source=o.source.replace(/\{\{([^}]+)\}\}/g,(c,i)=>r[i]!==void 0?r[i]:c)),o})}export{G as useCodeSamples};
1
+ import{useAtomValue as a}from"jotai";import{applyEnvironments as x,getCodeSample as D}from"../../services/index.js";import{globalStoreAtom as K}from"../../jotai/store.js";import{operationStore as E}from"../../jotai/operation.js";import{environmentAtom as N,getLangKey as r,languageAtom as k,activeMimeNameAtom as P}from"../../jotai/app.js";import{useTranslate as T}from"../../hooks/index.js";function I({payload:o,isWebhook:p,definitionSamples:c,pointer:g,envVariables:f}){const{parser:u,options:{codeSamples:s,generatedSamplesMaxDepth:d}}=a(K),S=a(P),i=a(E(g)),{languages:m}=a(k),[l]=a(N),b=T(),n=new Map(m?.map(({key:e,order:t})=>[e,t])),A=c.filter(e=>n.has(r(e))),C=x(A,f,l),M=new Set(C.map(r));let L=[];if(!p){const e=s.languages?.filter(({lang:t,label:w})=>t!=="Payload"&&!M.has(r({lang:t,label:w})))||[];L=V(e,s,u.definition,d,i,l,b,S)}const h=[...C,...L],y=m?.find(({lang:e})=>e===o?.lang)?.title,v=o&&r({label:y,lang:o.lang});return o&&v&&n.has(v)&&h.push({...o,label:y,order:n.get(v)}),{samples:h.map(e=>{const t=e.label??e.lang;return{key:r(e),title:t,order:typeof n.get(t.toLowerCase())=="number"?n.get(t.toLowerCase()):9999,...e}}).sort((e,t)=>e.order-t.order)}}function V(o,{skipOptionalParameters:p,withOAuth2Call:c},g,f,u,s,d,S){return o.map(({lang:i,label:m,options:l})=>({lang:i,label:m,get:b=>D({...b,lang:i,options:{...l,skipOptionalParameters:p,withOAuth2Call:c,spec:g,generatedPayloadSamplesMaxDepth:f,store:u,activeMimeName:S},environment:s,translate:d})}))}export{I as useCodeSamples};
@@ -0,0 +1,2 @@
1
+ import type { OperationModel } from '../../models/types.js';
2
+ export declare function applyEnvironments<T extends object>(samples: T[], envVariables?: OperationModel['envVariables'], currentEnvironment?: Record<string, string>): T[];
@@ -0,0 +1 @@
1
+ function i(n,t,c){if(!t||!n.length)return n;const u=c?.server;let r={...t.values||{}};return u&&t.serverValues?.[u]&&(r={...r,...t.serverValues[u]}),Object.keys(r).length===0?n:n.map(e=>!("source"in e)||typeof e.source!="string"?e:{...e,source:e.source.replace(/\{\{([^}]+)\}\}/g,(f,o)=>r[o]!==void 0?r[o]:f)})}export{i as applyEnvironments};
@@ -0,0 +1,17 @@
1
+ import type { TFunction } from '@redocly/theme/core/openapi';
2
+ import type { OpenAPIDefinition, OperationModel, Options } from '../../index.js';
3
+ type CodeSample = {
4
+ lang: string;
5
+ label?: string;
6
+ source: string;
7
+ };
8
+ type BuildCodeSamplesAttributes = {
9
+ exampleKey?: string;
10
+ mimeType?: string;
11
+ parameters?: Record<string, object>;
12
+ requestBody?: unknown;
13
+ environments?: Record<string, Record<string, string>>;
14
+ environment?: string;
15
+ };
16
+ export declare function buildCodeSamples(operation: OperationModel, options: Options, definition: OpenAPIDefinition, attributes: BuildCodeSamplesAttributes, translate: TFunction): CodeSample[];
17
+ export {};
@@ -0,0 +1 @@
1
+ import{applyEnvironments as S}from"./apply-environments.js";import{getCodeSample as h}from"./generator.js";function x(a,t,d,n,g){const{codeSamples:r,generatedSamplesMaxDepth:f}=t,p=r.languages??[],m=new Map(p.map(({lang:e,label:o},i)=>[s({lang:e,label:o}),i])),l=n.environment&&n.environments?.[n.environment]||{},c=S((a.definitionSamples??[]).filter(e=>m.has(s(e))&&"source"in e&&typeof e.source=="string"),a.envVariables,l),u=new Set(c.map(s)),y=a.isWebhook?[]:p.filter(({lang:e,label:o})=>e!=="Payload"&&!u.has(s({lang:e,label:o}))).map(({lang:e,label:o,options:i})=>({lang:e,label:o,source:h({lang:e,operation:a,exampleName:n.exampleKey,options:{...i,skipOptionalParameters:r.skipOptionalParameters,withOAuth2Call:r.withOAuth2Call,spec:d,generatedPayloadSamplesMaxDepth:f,store:{requestValues:{body:n.requestBody,...n.parameters}},activeMimeName:n.mimeType},environment:l,translate:g})}));return[...c,...y].filter(e=>!!e.source).sort((e,o)=>(m.get(s(e))??9999)-(m.get(s(o))??9999))}function s({lang:a,label:t}){return(t||a).toLowerCase()}export{x as buildCodeSamples};
@@ -0,0 +1,4 @@
1
+ import type { OpenAPIEncoding } from '../../types/open-api.js';
2
+ export declare function getExampleValueByMimeType(value: unknown, mimeType: string, encoding?: {
3
+ [field: string]: OpenAPIEncoding;
4
+ }): string;
@@ -0,0 +1 @@
1
+ import{XMLBuilder as n}from"fast-xml-parser";import{isFormUrlEncoded as o,isJsonLike as e,isSequentialMediaType as f,isXmlLike as d,urlFormEncodePayload as s}from"../../utils/openapi.js";const c=new n({format:!0,cdataPropName:"#cdata"});function u(r,t,i){if(r===void 0)return"";if(e(t)&&!f(t))try{return JSON.stringify(typeof r=="string"?JSON.parse(r):r,null,2)??""}catch{return String(r)}return typeof r=="object"&&r!==null?o(t)?s(r,i):d(t)?c.build(Array.isArray(r)?r:{root:r}):JSON.stringify(r,null,2):String(r)}export{u as getExampleValueByMimeType};
@@ -1,3 +1,6 @@
1
1
  export * from './generator.js';
2
2
  export * from './types.js';
3
3
  export * from './convertSampleToString.js';
4
+ export * from './apply-environments.js';
5
+ export * from './build-code-samples.js';
6
+ export * from './get-example-value-by-mime-type.js';
@@ -1 +1 @@
1
- export*from"./generator.js";export*from"./types.js";export*from"./convertSampleToString.js";
1
+ export*from"./generator.js";export*from"./types.js";export*from"./convertSampleToString.js";export*from"./apply-environments.js";export*from"./build-code-samples.js";export*from"./get-example-value-by-mime-type.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-docs",
3
- "version": "3.23.0-next.5",
3
+ "version": "3.23.0-next.6",
4
4
  "description": "Redocly OpenAPI Docs",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "@babel/core": "7.29.7",
24
24
  "@markdoc/markdoc": "0.5.2",
25
- "@redocly/openapi-core": "2.34.0",
25
+ "@redocly/openapi-core": "2.35.0",
26
26
  "deepmerge": "^4.2.2",
27
27
  "dompurify": "3.4.11",
28
28
  "fast-deep-equal": "^3.1.3",
@@ -39,9 +39,9 @@
39
39
  "url-template": "^2.0.8",
40
40
  "util": "~0.12.5",
41
41
  "web-vitals": "3.3.1",
42
- "@redocly/config": "0.49.0",
43
- "@redocly/redoc-opentelemetry": "0.2.1",
44
- "@redocly/replay": "0.26.0-next.5"
42
+ "@redocly/config": "0.49.1",
43
+ "@redocly/redoc-opentelemetry": "0.2.2",
44
+ "@redocly/replay": "0.26.0-next.6"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@shikijs/transformers": "3.21.0",
@@ -71,7 +71,7 @@
71
71
  "url": "~0.11.0",
72
72
  "vite": "7.3.3",
73
73
  "vitest": "4.1.8",
74
- "@redocly/theme": "0.67.0-next.4"
74
+ "@redocly/theme": "0.67.0-next.5"
75
75
  },
76
76
  "scripts": {
77
77
  "start": "pnpm run copy-highlight-hook && vite",