@redocly/openapi-docs 3.6.2 → 3.7.0-next.0

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,2 +1,2 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t},__awaiter=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,i){function a(e){try{u(o.next(e))}catch(e){i(e)}}function s(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((o=o.apply(e,t||[])).next())}))},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Replay=void 0;const jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),theme_1=require("@redocly/theme"),jotai_1=require("jotai"),deepmerge_1=__importDefault(require("deepmerge")),ReplayOverlay=(0,react_1.lazy)((()=>__awaiter(void 0,void 0,void 0,(function*(){return Promise.resolve().then((()=>__importStar(require("@redocly/replay")))).then((e=>({default:e.ReplayOverlay})))})))),store_1=require("../../jotai/store"),replay_1=require("../../jotai/replay"),operation_1=require("../../jotai/operation"),constants_1=require("../../constants"),app_1=require("../../jotai/app"),utils_1=require("./utils"),hooks_1=require("../../hooks"),utils_2=require("../../utils");function ReplayComponent({operation:e,corsProxyUrl:t,fullOpenApi:r}){var o,n;const i=(0,hooks_1.useTranslate)(),a=(0,react_1.useRef)(null),{mockServer:s,oAuth2RedirectURI:u,routingBasePath:l}=(0,jotai_1.useAtomValue)(store_1.globalOptionsAtom),_=(0,jotai_1.useAtomValue)(replay_1.allOperationsAtom),{parser:c}=(0,jotai_1.useAtomValue)(store_1.globalStoreAtom),[p,d]=(0,react_1.useState)(!1),[m,f]=(0,jotai_1.useAtom)(replay_1.replayStateAtom),[h,j]=(0,jotai_1.useAtom)(operation_1.allOperations),[[,y],v]=(0,jotai_1.useAtom)(app_1.environmentAtom);(0,theme_1.useFocusTrap)(a),(0,theme_1.useModalScrollLock)(p);const O=(0,react_1.useCallback)((({operations:e,environment:t,environments:r})=>{const o=e.reduce(((e,t)=>{t.requestValues.body=t.requestValues.body instanceof URLSearchParams?Object.fromEntries(t.requestValues.body.entries()):t.requestValues.body;const{path:r,method:o}=t.sourcePath,n=utils_2.JsonPointer.compile(["paths",r,o]);return e[n]=(0,deepmerge_1.default)((0,operation_1.getDefaultOperationStore)(n),t),e}),{});j(Object.assign(Object.assign({},h),o)),v({environment:t,environments:r})}),[h,j,v]),A=()=>{m!==constants_1.LOADING_STATE.LOADING&&d(!p),m===constants_1.LOADING_STATE.NOT_LOADED&&f(constants_1.LOADING_STATE.LOADING)},x=(0,react_1.useCallback)((e=>{if(!e)return;const t=_.find((t=>t.operationId===e));return l+(null==t?void 0:t.href)}),[_,l]);return r?(0,jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment,{children:[(0,jsx_runtime_1.jsx)(theme_1.Button,{onClick:A,variant:"primary",iconPosition:"left",icon:m===constants_1.LOADING_STATE.LOADING?(0,jsx_runtime_1.jsx)(theme_1.CircleDashIcon,{}):(0,jsx_runtime_1.jsx)(theme_1.RocketIcon,{}),children:m===constants_1.LOADING_STATE.LOADING?i("openapi.loading","Loading..."):i("openapi.tryIt","Try it")}),p&&(0,jsx_runtime_1.jsx)(react_1.Suspense,{children:(0,jsx_runtime_1.jsx)(theme_1.Portal,{mountId:"api-content",children:(0,jsx_runtime_1.jsx)("div",{ref:a,children:(0,jsx_runtime_1.jsx)(ReplayOverlay,{activeOperationId:e.operationId,source:{data:r,type:"openapi"},onRequestChange:O,onClose:A,onLoad:()=>f(constants_1.LOADING_STATE.LOADED),settings:{corsProxyUrl:t,mockServer:s,environment:y,apiId:null===(n=null===(o=null==c?void 0:c.definition.info)||void 0===o?void 0:o["x-metadata"])||void 0===n?void 0:n.apiId,oAuth2RedirectURI:u,disableCollectionsTab:!0,storageKey:l,convertOperationToReplayValue:utils_1.convertOperationToReplayValue,getOperationUrl:x}})})})})]}):null}exports.Replay=(0,react_1.memo)(ReplayComponent);
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t},__awaiter=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,i){function a(e){try{u(o.next(e))}catch(e){i(e)}}function s(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((o=o.apply(e,t||[])).next())}))},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Replay=void 0;const jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),theme_1=require("@redocly/theme"),jotai_1=require("jotai"),deepmerge_1=__importDefault(require("deepmerge")),ReplayOverlay=(0,react_1.lazy)((()=>__awaiter(void 0,void 0,void 0,(function*(){return Promise.resolve().then((()=>__importStar(require("@redocly/replay")))).then((e=>({default:e.ReplayOverlay})))})))),store_1=require("../../jotai/store"),replay_1=require("../../jotai/replay"),operation_1=require("../../jotai/operation"),constants_1=require("../../constants"),app_1=require("../../jotai/app"),utils_1=require("./utils"),hooks_1=require("../../hooks"),utils_2=require("../../utils");function ReplayComponent({operation:e,corsProxyUrl:t,fullOpenApi:r}){var o,n;const i=(0,hooks_1.useTranslate)(),a=(0,react_1.useRef)(null),{mockServer:s,oAuth2RedirectURI:u,routingBasePath:l}=(0,jotai_1.useAtomValue)(store_1.globalOptionsAtom),_=(0,jotai_1.useAtomValue)(replay_1.allOperationsAtom),{parser:c}=(0,jotai_1.useAtomValue)(store_1.globalStoreAtom),[p,d]=(0,react_1.useState)(!1),[m,f]=(0,jotai_1.useAtom)(replay_1.replayStateAtom),[h,j]=(0,jotai_1.useAtom)(operation_1.allOperations),[[,y],v]=(0,jotai_1.useAtom)(app_1.environmentAtom);(0,theme_1.useFocusTrap)(a),(0,theme_1.useModalScrollLock)(p);const O=(0,react_1.useCallback)((({operations:e,environment:t,environments:r})=>{const o=e.reduce(((e,t)=>{t.requestValues.body=t.requestValues.body instanceof URLSearchParams?Object.fromEntries(t.requestValues.body.entries()):t.requestValues.body;const{path:r,method:o}=t.sourcePath,n=utils_2.JsonPointer.compile(["paths",r,o]);return e[n]=(0,deepmerge_1.default)((0,operation_1.getDefaultOperationStore)(n),t),e}),{});j(Object.assign(Object.assign({},h),o)),v({environment:t,environments:r})}),[h,j,v]),A=()=>{m!==constants_1.LOADING_STATE.LOADING&&d(!p),m===constants_1.LOADING_STATE.NOT_LOADED&&f(constants_1.LOADING_STATE.LOADING)},x=(0,react_1.useCallback)((e=>{if(!e)return;const t=_.find((t=>t.operationId===e));return l+(null==t?void 0:t.href)}),[_,l]);return r?(0,jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment,{children:[(0,jsx_runtime_1.jsx)(theme_1.Button,{onClick:A,variant:"primary",iconPosition:"left",icon:m===constants_1.LOADING_STATE.LOADING?(0,jsx_runtime_1.jsx)(theme_1.CircleDashIcon,{}):(0,jsx_runtime_1.jsx)(theme_1.RocketIcon,{}),children:m===constants_1.LOADING_STATE.LOADING?i("openapi.loading","Loading..."):i("openapi.tryIt","Try it")}),p&&(0,jsx_runtime_1.jsx)(react_1.Suspense,{children:(0,jsx_runtime_1.jsx)(theme_1.Portal,{mountId:"api-content",children:(0,jsx_runtime_1.jsx)("div",{ref:a,children:(0,jsx_runtime_1.jsx)(ReplayOverlay,{activeOperationId:e.operationId||e.pointer,source:{data:r,type:"openapi"},onRequestChange:O,onClose:A,onLoad:()=>f(constants_1.LOADING_STATE.LOADED),settings:{corsProxyUrl:t,mockServer:s,environment:y,apiId:null===(n=null===(o=null==c?void 0:c.definition.info)||void 0===o?void 0:o["x-metadata"])||void 0===n?void 0:n.apiId,oAuth2RedirectURI:u,disableCollectionsTab:!0,storageKey:l,convertOperationToReplayValue:utils_1.convertOperationToReplayValueForRedoc,getOperationUrl:x}})})})})]}):null}exports.Replay=(0,react_1.memo)(ReplayComponent);
2
2
  //# sourceMappingURL=Replay.js.map
@@ -19,4 +19,23 @@ export declare function convertOperationToReplayValue(path: string, method: stri
19
19
  };
20
20
  };
21
21
  } | undefined;
22
+ export declare function convertOperationToReplayValueForRedoc(path: string, method: string, openAPI: OpenAPIDefinition): {
23
+ operationId: string;
24
+ id: string;
25
+ name: string;
26
+ method: string;
27
+ parameters: any[];
28
+ body: any;
29
+ path: string;
30
+ href: string;
31
+ servers: import("../../types").OpenAPIServer[];
32
+ security: any[] | undefined;
33
+ responses: {
34
+ [k: string]: {
35
+ code: string;
36
+ description: string | GenericObject;
37
+ mediaTypes: {} | undefined;
38
+ };
39
+ };
40
+ } | undefined;
22
41
  export declare function convertRequestSecurity(security?: SecurityRequirement[]): any[] | undefined;
@@ -1,2 +1,2 @@
1
- "use strict";var __rest=this&&this.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(r=Object.getOwnPropertySymbols(e);a<r.length;a++)t.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(e,r[a])&&(n[r[a]]=e[r[a]])}return n};Object.defineProperty(exports,"__esModule",{value:!0}),exports.convertOperationToReplayValue=convertOperationToReplayValue,exports.convertRequestSecurity=convertRequestSecurity;const theme_1=require("@redocly/theme"),models_1=require("../../models"),services_1=require("../../services");function convertOperationToReplayValue(e,t,n){var r;if(!n)return;const a=new services_1.OpenAPIParser(n),i=null===(r=a.definition.paths)||void 0===r?void 0:r[e],o=null==i?void 0:i[t],s=(0,models_1.getOperation)(a,Object.assign(Object.assign({},o),{pathName:e,httpVerb:t,pathParameters:i.parameters||[],pathServers:i.servers||[]}),void 0,(0,services_1.normalizeOptions)({}),""),l={id:s.id,name:s.name,method:s.httpVerb,operationId:s.operationId,parameters:convertParameters(s.parameters),body:convertRequestBody(s.requestBody,n),path:s.path,href:s.href,servers:s.servers,security:convertRequestSecurity(s.security),responses:Object.fromEntries(s.responses.map((e=>{var t;return[e.code,{code:e.code,description:e.description,mediaTypes:null===(t=e.content)||void 0===t?void 0:t.mediaTypes.reduce(((e,t)=>{var r;return e[t.name]={name:t.name,schema:getBodySchema(null===(r=t.schema)||void 0===r?void 0:r.rawSchema,n)},e}),{})}]})))};return l}function convertParameters(e,t){const n=new Set,r=e.map((e=>{var r;return n.add(e.in+":"+e.name),{name:e.name,in:e.in,required:e.required,description:e.description,example:(null===(r=null==t?void 0:t[String(e.in)])||void 0===r?void 0:r[e.name])||e.example,schema:e.schema}}));for(const[e,a]of Object.entries(t||{}))for(const[t,i]of Object.entries(a||{}))n.has(e+":"+t)||r.push({name:t,in:e,required:!1,description:"",example:String(i),schema:void 0});return r}function getInputType({type:e,format:t,enum:n}){return"string"!==e||"binary"!==t&&"base64"!==t?"object"===e?"multiline":n.length>0?"select":"text":"file"}function getFieldExamples(e,t){var n,r,a,i,o;const s=(null===(n=e[0])||void 0===n?void 0:n.example)||(null===(r=e[0])||void 0===r?void 0:r.examples);if(s)return s;if(null===(a=e.schema)||void 0===a?void 0:a.example)return e.schema.example;const l=(null===(i=null==t?void 0:t.default)||void 0===i?void 0:i.value)||(null===(o=null==t?void 0:t.default)||void 0===o?void 0:o.rawValue);return(null==l?void 0:l[e.name])?(0,theme_1.isPrimitive)(null==l?void 0:l[e.name])?String(null==l?void 0:l[e.name]):JSON.stringify(null==l?void 0:l[e.name]):""}function convertRequestBody(e,t,n){var r;if(!e||!(null===(r=e.content)||void 0===r?void 0:r.mediaTypes)){if(!n)return;const{activeExampleName:e}=n,t=__rest(n,["activeExampleName"]);return{activeExampleName:e,mediaTypes:Object.fromEntries(Object.entries(t).map((([e,t])=>[e,{name:e,examples:{default:{value:t}},schema:{},parameters:[]}])))}}return{required:e.required,activeExampleName:null==n?void 0:n.activeExampleName,mediaTypes:e.content.mediaTypes.reduce(((e,r)=>{var a,i;const o=r.schema,s=(null==n?void 0:n[r.name])?{default:{value:null==n?void 0:n[r.name],rawValue:null==n?void 0:n[r.name],mime:r.name}}:r.examples||r.formExamples;return e[r.name]={name:r.name,examples:s,schema:getBodySchema(null===(a=r.schema)||void 0===a?void 0:a.rawSchema,t),parameters:null===(i=null==o?void 0:o.fields)||void 0===i?void 0:i.map((e=>({inputType:getInputType(e.schema),name:e.name,example:getFieldExamples(e,s)})))},e}),{})}}function getBodySchema(e,t){if(e&&t)return Object.assign(Object.assign({},e),{components:(null==t?void 0:t.components)||{}})}function convertRequestSecurity(e){if(e)return e.map((({schemes:e})=>e.map((e=>{const t={id:e.id,type:e.type,in:e.in,openIdConnectUrl:e.openIdConnectUrl,scopes:e.scopes,scheme:e.scheme,name:e.name,flows:e.flows,"x-defaultAccessToken":e["x-defaultAccessToken"],"x-defaultTokenType":e["x-defaultTokenType"],"x-defaultClientId":e["x-defaultClientId"],"x-defaultClientSecret":e["x-defaultClientSecret"],"x-defaultUsername":e["x-defaultUsername"],"x-defaultPassword":e["x-defaultPassword"]};return Object.keys(t).forEach((e=>void 0===t[e]&&delete t[e])),t}))))}
1
+ "use strict";var __rest=this&&this.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(r=Object.getOwnPropertySymbols(e);a<r.length;a++)t.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(e,r[a])&&(n[r[a]]=e[r[a]])}return n};Object.defineProperty(exports,"__esModule",{value:!0}),exports.convertOperationToReplayValue=convertOperationToReplayValue,exports.convertOperationToReplayValueForRedoc=convertOperationToReplayValueForRedoc,exports.convertRequestSecurity=convertRequestSecurity;const theme_1=require("@redocly/theme"),models_1=require("../../models"),services_1=require("../../services"),utils_1=require("../../utils");function convertOperationToReplayValue(e,t,n){var r;if(!n)return;const a=new services_1.OpenAPIParser(n),o=null===(r=a.definition.paths)||void 0===r?void 0:r[e],i=null==o?void 0:o[t],s=(0,models_1.getOperation)(a,Object.assign(Object.assign({},i),{pathName:e,httpVerb:t,pathParameters:o.parameters||[],pathServers:o.servers||[]}),void 0,(0,services_1.normalizeOptions)({}),"");if(!s)return;const l={id:s.id,name:s.name,method:s.httpVerb,operationId:s.operationId,parameters:convertParameters(s.parameters),body:convertRequestBody(s.requestBody,n),path:s.path,href:s.href,servers:s.servers,security:convertRequestSecurity(s.security),responses:Object.fromEntries(s.responses.map((e=>{var t;return[e.code,{code:e.code,description:e.description,mediaTypes:null===(t=e.content)||void 0===t?void 0:t.mediaTypes.reduce(((e,t)=>{var r;return e[t.name]={name:t.name,schema:getBodySchema(null===(r=t.schema)||void 0===r?void 0:r.rawSchema,n)},e}),{})}]})))};return l}function convertOperationToReplayValueForRedoc(e,t,n){const r=convertOperationToReplayValue(e,t,n);if(r)return Object.assign(Object.assign({},r),{operationId:r.operationId||utils_1.JsonPointer.compile(["paths",r.path,r.method])})}function convertParameters(e,t){const n=new Set,r=e.map((e=>{var r;return n.add(e.in+":"+e.name),{name:e.name,in:e.in,required:e.required,description:e.description,example:(null===(r=null==t?void 0:t[String(e.in)])||void 0===r?void 0:r[e.name])||e.example,schema:e.schema}}));for(const[e,a]of Object.entries(t||{}))for(const[t,o]of Object.entries(a||{}))n.has(e+":"+t)||r.push({name:t,in:e,required:!1,description:"",example:String(o),schema:void 0});return r}function getInputType({type:e,format:t,enum:n}){return"string"!==e||"binary"!==t&&"base64"!==t?"object"===e?"multiline":n.length>0?"select":"text":"file"}function getFieldExamples(e,t){var n,r,a,o,i;const s=(null===(n=e[0])||void 0===n?void 0:n.example)||(null===(r=e[0])||void 0===r?void 0:r.examples);if(s)return s;if(null===(a=e.schema)||void 0===a?void 0:a.example)return e.schema.example;const l=(null===(o=null==t?void 0:t.default)||void 0===o?void 0:o.value)||(null===(i=null==t?void 0:t.default)||void 0===i?void 0:i.rawValue);return(null==l?void 0:l[e.name])?(0,theme_1.isPrimitive)(null==l?void 0:l[e.name])?String(null==l?void 0:l[e.name]):JSON.stringify(null==l?void 0:l[e.name]):""}function convertRequestBody(e,t,n){var r;if(!e||!(null===(r=e.content)||void 0===r?void 0:r.mediaTypes)){if(!n)return;const{activeExampleName:e}=n,t=__rest(n,["activeExampleName"]);return{activeExampleName:e,mediaTypes:Object.fromEntries(Object.entries(t).map((([e,t])=>[e,{name:e,examples:{default:{value:t}},schema:{},parameters:[]}])))}}return{required:e.required,activeExampleName:null==n?void 0:n.activeExampleName,mediaTypes:e.content.mediaTypes.reduce(((e,r)=>{var a,o;const i=r.schema,s=(null==n?void 0:n[r.name])?{default:{value:null==n?void 0:n[r.name],rawValue:null==n?void 0:n[r.name],mime:r.name}}:r.examples||r.formExamples;return e[r.name]={name:r.name,examples:s,schema:getBodySchema(null===(a=r.schema)||void 0===a?void 0:a.rawSchema,t),parameters:null===(o=null==i?void 0:i.fields)||void 0===o?void 0:o.map((e=>({inputType:getInputType(e.schema),name:e.name,example:getFieldExamples(e,s)})))},e}),{})}}function getBodySchema(e,t){if(e&&t)return Object.assign(Object.assign({},e),{components:(null==t?void 0:t.components)||{}})}function convertRequestSecurity(e){if(e)return e.map((({schemes:e})=>e.map((e=>{const t={id:e.id,type:e.type,in:e.in,openIdConnectUrl:e.openIdConnectUrl,scopes:e.scopes,scheme:e.scheme,name:e.name,flows:e.flows,"x-defaultAccessToken":e["x-defaultAccessToken"],"x-defaultTokenType":e["x-defaultTokenType"],"x-defaultClientId":e["x-defaultClientId"],"x-defaultClientSecret":e["x-defaultClientSecret"],"x-defaultUsername":e["x-defaultUsername"],"x-defaultPassword":e["x-defaultPassword"]};return Object.keys(t).forEach((e=>void 0===t[e]&&delete t[e])),t}))))}
2
2
  //# sourceMappingURL=utils.js.map
@@ -1,2 +1,2 @@
1
- var __awaiter=this&&this.__awaiter||function(e,o,t,r){return new(t||(t=Promise))((function(n,a){function i(e){try{l(r.next(e))}catch(e){a(e)}}function s(e){try{l(r.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?n(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(i,s)}l((r=r.apply(e,o||[])).next())}))};import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import{lazy,memo,Suspense,useCallback,useRef,useState}from"react";import{Button,CircleDashIcon,Portal,RocketIcon,useFocusTrap,useModalScrollLock}from"@redocly/theme";import{useAtom,useAtomValue}from"jotai";import merge from"deepmerge";const ReplayOverlay=lazy((()=>__awaiter(void 0,void 0,void 0,(function*(){return import("@redocly/replay").then((e=>({default:e.ReplayOverlay})))}))));import{globalOptionsAtom,globalStoreAtom}from"../../jotai/store";import{allOperationsAtom,replayStateAtom}from"../../jotai/replay";import{allOperations,getDefaultOperationStore}from"../../jotai/operation";import{LOADING_STATE}from"../../constants";import{environmentAtom}from"../../jotai/app";import{convertOperationToReplayValue}from"./utils";import{useTranslate}from"../../hooks";import{JsonPointer}from"../../utils";function ReplayComponent({operation:e,corsProxyUrl:o,fullOpenApi:t}){var r,n;const a=useTranslate(),i=useRef(null),{mockServer:s,oAuth2RedirectURI:l,routingBasePath:u}=useAtomValue(globalOptionsAtom),m=useAtomValue(allOperationsAtom),{parser:p}=useAtomValue(globalStoreAtom),[c,d]=useState(!1),[A,f]=useAtom(replayStateAtom),[y,O]=useAtom(allOperations),[[,v],h]=useAtom(environmentAtom);useFocusTrap(i),useModalScrollLock(c);const _=useCallback((({operations:e,environment:o,environments:t})=>{const r=e.reduce(((e,o)=>{o.requestValues.body=o.requestValues.body instanceof URLSearchParams?Object.fromEntries(o.requestValues.body.entries()):o.requestValues.body;const{path:t,method:r}=o.sourcePath,n=JsonPointer.compile(["paths",t,r]);return e[n]=merge(getDefaultOperationStore(n),o),e}),{});O(Object.assign(Object.assign({},y),r)),h({environment:o,environments:t})}),[y,O,h]),I=()=>{A!==LOADING_STATE.LOADING&&d(!c),A===LOADING_STATE.NOT_LOADED&&f(LOADING_STATE.LOADING)},T=useCallback((e=>{if(!e)return;const o=m.find((o=>o.operationId===e));return u+(null==o?void 0:o.href)}),[m,u]);return t?_jsxs(_Fragment,{children:[_jsx(Button,{onClick:I,variant:"primary",iconPosition:"left",icon:A===LOADING_STATE.LOADING?_jsx(CircleDashIcon,{}):_jsx(RocketIcon,{}),children:A===LOADING_STATE.LOADING?a("openapi.loading","Loading..."):a("openapi.tryIt","Try it")}),c&&_jsx(Suspense,{children:_jsx(Portal,{mountId:"api-content",children:_jsx("div",{ref:i,children:_jsx(ReplayOverlay,{activeOperationId:e.operationId,source:{data:t,type:"openapi"},onRequestChange:_,onClose:I,onLoad:()=>f(LOADING_STATE.LOADED),settings:{corsProxyUrl:o,mockServer:s,environment:v,apiId:null===(n=null===(r=null==p?void 0:p.definition.info)||void 0===r?void 0:r["x-metadata"])||void 0===n?void 0:n.apiId,oAuth2RedirectURI:l,disableCollectionsTab:!0,storageKey:u,convertOperationToReplayValue:convertOperationToReplayValue,getOperationUrl:T}})})})})]}):null}export const Replay=memo(ReplayComponent);
1
+ var __awaiter=this&&this.__awaiter||function(e,o,t,r){return new(t||(t=Promise))((function(n,a){function i(e){try{l(r.next(e))}catch(e){a(e)}}function s(e){try{l(r.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?n(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(i,s)}l((r=r.apply(e,o||[])).next())}))};import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import{lazy,memo,Suspense,useCallback,useRef,useState}from"react";import{Button,CircleDashIcon,Portal,RocketIcon,useFocusTrap,useModalScrollLock}from"@redocly/theme";import{useAtom,useAtomValue}from"jotai";import merge from"deepmerge";const ReplayOverlay=lazy((()=>__awaiter(void 0,void 0,void 0,(function*(){return import("@redocly/replay").then((e=>({default:e.ReplayOverlay})))}))));import{globalOptionsAtom,globalStoreAtom}from"../../jotai/store";import{allOperationsAtom,replayStateAtom}from"../../jotai/replay";import{allOperations,getDefaultOperationStore}from"../../jotai/operation";import{LOADING_STATE}from"../../constants";import{environmentAtom}from"../../jotai/app";import{convertOperationToReplayValueForRedoc}from"./utils";import{useTranslate}from"../../hooks";import{JsonPointer}from"../../utils";function ReplayComponent({operation:e,corsProxyUrl:o,fullOpenApi:t}){var r,n;const a=useTranslate(),i=useRef(null),{mockServer:s,oAuth2RedirectURI:l,routingBasePath:u}=useAtomValue(globalOptionsAtom),m=useAtomValue(allOperationsAtom),{parser:p}=useAtomValue(globalStoreAtom),[c,d]=useState(!1),[A,f]=useAtom(replayStateAtom),[y,O]=useAtom(allOperations),[[,v],h]=useAtom(environmentAtom);useFocusTrap(i),useModalScrollLock(c);const _=useCallback((({operations:e,environment:o,environments:t})=>{const r=e.reduce(((e,o)=>{o.requestValues.body=o.requestValues.body instanceof URLSearchParams?Object.fromEntries(o.requestValues.body.entries()):o.requestValues.body;const{path:t,method:r}=o.sourcePath,n=JsonPointer.compile(["paths",t,r]);return e[n]=merge(getDefaultOperationStore(n),o),e}),{});O(Object.assign(Object.assign({},y),r)),h({environment:o,environments:t})}),[y,O,h]),I=()=>{A!==LOADING_STATE.LOADING&&d(!c),A===LOADING_STATE.NOT_LOADED&&f(LOADING_STATE.LOADING)},T=useCallback((e=>{if(!e)return;const o=m.find((o=>o.operationId===e));return u+(null==o?void 0:o.href)}),[m,u]);return t?_jsxs(_Fragment,{children:[_jsx(Button,{onClick:I,variant:"primary",iconPosition:"left",icon:A===LOADING_STATE.LOADING?_jsx(CircleDashIcon,{}):_jsx(RocketIcon,{}),children:A===LOADING_STATE.LOADING?a("openapi.loading","Loading..."):a("openapi.tryIt","Try it")}),c&&_jsx(Suspense,{children:_jsx(Portal,{mountId:"api-content",children:_jsx("div",{ref:i,children:_jsx(ReplayOverlay,{activeOperationId:e.operationId||e.pointer,source:{data:t,type:"openapi"},onRequestChange:_,onClose:I,onLoad:()=>f(LOADING_STATE.LOADED),settings:{corsProxyUrl:o,mockServer:s,environment:v,apiId:null===(n=null===(r=null==p?void 0:p.definition.info)||void 0===r?void 0:r["x-metadata"])||void 0===n?void 0:n.apiId,oAuth2RedirectURI:l,disableCollectionsTab:!0,storageKey:u,convertOperationToReplayValue:convertOperationToReplayValueForRedoc,getOperationUrl:T}})})})})]}):null}export const Replay=memo(ReplayComponent);
2
2
  //# sourceMappingURL=Replay.js.map
@@ -19,4 +19,23 @@ export declare function convertOperationToReplayValue(path: string, method: stri
19
19
  };
20
20
  };
21
21
  } | undefined;
22
+ export declare function convertOperationToReplayValueForRedoc(path: string, method: string, openAPI: OpenAPIDefinition): {
23
+ operationId: string;
24
+ id: string;
25
+ name: string;
26
+ method: string;
27
+ parameters: any[];
28
+ body: any;
29
+ path: string;
30
+ href: string;
31
+ servers: import("../../types").OpenAPIServer[];
32
+ security: any[] | undefined;
33
+ responses: {
34
+ [k: string]: {
35
+ code: string;
36
+ description: string | GenericObject;
37
+ mediaTypes: {} | undefined;
38
+ };
39
+ };
40
+ } | undefined;
22
41
  export declare function convertRequestSecurity(security?: SecurityRequirement[]): any[] | undefined;
@@ -1,2 +1,2 @@
1
- var __rest=this&&this.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(r=Object.getOwnPropertySymbols(e);a<r.length;a++)t.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(e,r[a])&&(n[r[a]]=e[r[a]])}return n};import{isPrimitive}from"@redocly/theme";import{getOperation}from"../../models";import{normalizeOptions,OpenAPIParser}from"../../services";export function convertOperationToReplayValue(e,t,n){var r;if(!n)return;const a=new OpenAPIParser(n),i=null===(r=a.definition.paths)||void 0===r?void 0:r[e],o=null==i?void 0:i[t],s=getOperation(a,Object.assign(Object.assign({},o),{pathName:e,httpVerb:t,pathParameters:i.parameters||[],pathServers:i.servers||[]}),void 0,normalizeOptions({}),""),l={id:s.id,name:s.name,method:s.httpVerb,operationId:s.operationId,parameters:convertParameters(s.parameters),body:convertRequestBody(s.requestBody,n),path:s.path,href:s.href,servers:s.servers,security:convertRequestSecurity(s.security),responses:Object.fromEntries(s.responses.map((e=>{var t;return[e.code,{code:e.code,description:e.description,mediaTypes:null===(t=e.content)||void 0===t?void 0:t.mediaTypes.reduce(((e,t)=>{var r;return e[t.name]={name:t.name,schema:getBodySchema(null===(r=t.schema)||void 0===r?void 0:r.rawSchema,n)},e}),{})}]})))};return l}function convertParameters(e,t){const n=new Set,r=e.map((e=>{var r;return n.add(e.in+":"+e.name),{name:e.name,in:e.in,required:e.required,description:e.description,example:(null===(r=null==t?void 0:t[String(e.in)])||void 0===r?void 0:r[e.name])||e.example,schema:e.schema}}));for(const[e,a]of Object.entries(t||{}))for(const[t,i]of Object.entries(a||{}))n.has(e+":"+t)||r.push({name:t,in:e,required:!1,description:"",example:String(i),schema:void 0});return r}function getInputType({type:e,format:t,enum:n}){return"string"!==e||"binary"!==t&&"base64"!==t?"object"===e?"multiline":n.length>0?"select":"text":"file"}function getFieldExamples(e,t){var n,r,a,i,o;const s=(null===(n=e[0])||void 0===n?void 0:n.example)||(null===(r=e[0])||void 0===r?void 0:r.examples);if(s)return s;if(null===(a=e.schema)||void 0===a?void 0:a.example)return e.schema.example;const l=(null===(i=null==t?void 0:t.default)||void 0===i?void 0:i.value)||(null===(o=null==t?void 0:t.default)||void 0===o?void 0:o.rawValue);return(null==l?void 0:l[e.name])?isPrimitive(null==l?void 0:l[e.name])?String(null==l?void 0:l[e.name]):JSON.stringify(null==l?void 0:l[e.name]):""}function convertRequestBody(e,t,n){var r;if(!e||!(null===(r=e.content)||void 0===r?void 0:r.mediaTypes)){if(!n)return;const{activeExampleName:e}=n,t=__rest(n,["activeExampleName"]);return{activeExampleName:e,mediaTypes:Object.fromEntries(Object.entries(t).map((([e,t])=>[e,{name:e,examples:{default:{value:t}},schema:{},parameters:[]}])))}}return{required:e.required,activeExampleName:null==n?void 0:n.activeExampleName,mediaTypes:e.content.mediaTypes.reduce(((e,r)=>{var a,i;const o=r.schema,s=(null==n?void 0:n[r.name])?{default:{value:null==n?void 0:n[r.name],rawValue:null==n?void 0:n[r.name],mime:r.name}}:r.examples||r.formExamples;return e[r.name]={name:r.name,examples:s,schema:getBodySchema(null===(a=r.schema)||void 0===a?void 0:a.rawSchema,t),parameters:null===(i=null==o?void 0:o.fields)||void 0===i?void 0:i.map((e=>({inputType:getInputType(e.schema),name:e.name,example:getFieldExamples(e,s)})))},e}),{})}}function getBodySchema(e,t){if(e&&t)return Object.assign(Object.assign({},e),{components:(null==t?void 0:t.components)||{}})}export function convertRequestSecurity(e){if(e)return e.map((({schemes:e})=>e.map((e=>{const t={id:e.id,type:e.type,in:e.in,openIdConnectUrl:e.openIdConnectUrl,scopes:e.scopes,scheme:e.scheme,name:e.name,flows:e.flows,"x-defaultAccessToken":e["x-defaultAccessToken"],"x-defaultTokenType":e["x-defaultTokenType"],"x-defaultClientId":e["x-defaultClientId"],"x-defaultClientSecret":e["x-defaultClientSecret"],"x-defaultUsername":e["x-defaultUsername"],"x-defaultPassword":e["x-defaultPassword"]};return Object.keys(t).forEach((e=>void 0===t[e]&&delete t[e])),t}))))}
1
+ var __rest=this&&this.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(r=Object.getOwnPropertySymbols(e);a<r.length;a++)t.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(e,r[a])&&(n[r[a]]=e[r[a]])}return n};import{isPrimitive}from"@redocly/theme";import{getOperation}from"../../models";import{normalizeOptions,OpenAPIParser}from"../../services";import{JsonPointer}from"../../utils";export function convertOperationToReplayValue(e,t,n){var r;if(!n)return;const a=new OpenAPIParser(n),o=null===(r=a.definition.paths)||void 0===r?void 0:r[e],i=null==o?void 0:o[t],s=getOperation(a,Object.assign(Object.assign({},i),{pathName:e,httpVerb:t,pathParameters:o.parameters||[],pathServers:o.servers||[]}),void 0,normalizeOptions({}),"");if(!s)return;const l={id:s.id,name:s.name,method:s.httpVerb,operationId:s.operationId,parameters:convertParameters(s.parameters),body:convertRequestBody(s.requestBody,n),path:s.path,href:s.href,servers:s.servers,security:convertRequestSecurity(s.security),responses:Object.fromEntries(s.responses.map((e=>{var t;return[e.code,{code:e.code,description:e.description,mediaTypes:null===(t=e.content)||void 0===t?void 0:t.mediaTypes.reduce(((e,t)=>{var r;return e[t.name]={name:t.name,schema:getBodySchema(null===(r=t.schema)||void 0===r?void 0:r.rawSchema,n)},e}),{})}]})))};return l}export function convertOperationToReplayValueForRedoc(e,t,n){const r=convertOperationToReplayValue(e,t,n);if(r)return Object.assign(Object.assign({},r),{operationId:r.operationId||JsonPointer.compile(["paths",r.path,r.method])})}function convertParameters(e,t){const n=new Set,r=e.map((e=>{var r;return n.add(e.in+":"+e.name),{name:e.name,in:e.in,required:e.required,description:e.description,example:(null===(r=null==t?void 0:t[String(e.in)])||void 0===r?void 0:r[e.name])||e.example,schema:e.schema}}));for(const[e,a]of Object.entries(t||{}))for(const[t,o]of Object.entries(a||{}))n.has(e+":"+t)||r.push({name:t,in:e,required:!1,description:"",example:String(o),schema:void 0});return r}function getInputType({type:e,format:t,enum:n}){return"string"!==e||"binary"!==t&&"base64"!==t?"object"===e?"multiline":n.length>0?"select":"text":"file"}function getFieldExamples(e,t){var n,r,a,o,i;const s=(null===(n=e[0])||void 0===n?void 0:n.example)||(null===(r=e[0])||void 0===r?void 0:r.examples);if(s)return s;if(null===(a=e.schema)||void 0===a?void 0:a.example)return e.schema.example;const l=(null===(o=null==t?void 0:t.default)||void 0===o?void 0:o.value)||(null===(i=null==t?void 0:t.default)||void 0===i?void 0:i.rawValue);return(null==l?void 0:l[e.name])?isPrimitive(null==l?void 0:l[e.name])?String(null==l?void 0:l[e.name]):JSON.stringify(null==l?void 0:l[e.name]):""}function convertRequestBody(e,t,n){var r;if(!e||!(null===(r=e.content)||void 0===r?void 0:r.mediaTypes)){if(!n)return;const{activeExampleName:e}=n,t=__rest(n,["activeExampleName"]);return{activeExampleName:e,mediaTypes:Object.fromEntries(Object.entries(t).map((([e,t])=>[e,{name:e,examples:{default:{value:t}},schema:{},parameters:[]}])))}}return{required:e.required,activeExampleName:null==n?void 0:n.activeExampleName,mediaTypes:e.content.mediaTypes.reduce(((e,r)=>{var a,o;const i=r.schema,s=(null==n?void 0:n[r.name])?{default:{value:null==n?void 0:n[r.name],rawValue:null==n?void 0:n[r.name],mime:r.name}}:r.examples||r.formExamples;return e[r.name]={name:r.name,examples:s,schema:getBodySchema(null===(a=r.schema)||void 0===a?void 0:a.rawSchema,t),parameters:null===(o=null==i?void 0:i.fields)||void 0===o?void 0:o.map((e=>({inputType:getInputType(e.schema),name:e.name,example:getFieldExamples(e,s)})))},e}),{})}}function getBodySchema(e,t){if(e&&t)return Object.assign(Object.assign({},e),{components:(null==t?void 0:t.components)||{}})}export function convertRequestSecurity(e){if(e)return e.map((({schemes:e})=>e.map((e=>{const t={id:e.id,type:e.type,in:e.in,openIdConnectUrl:e.openIdConnectUrl,scopes:e.scopes,scheme:e.scheme,name:e.name,flows:e.flows,"x-defaultAccessToken":e["x-defaultAccessToken"],"x-defaultTokenType":e["x-defaultTokenType"],"x-defaultClientId":e["x-defaultClientId"],"x-defaultClientSecret":e["x-defaultClientSecret"],"x-defaultUsername":e["x-defaultUsername"],"x-defaultPassword":e["x-defaultPassword"]};return Object.keys(t).forEach((e=>void 0===t[e]&&delete t[e])),t}))))}
2
2
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-docs",
3
- "version": "3.6.2",
3
+ "version": "3.7.0-next.0",
4
4
  "description": "Redocly OpenAPI Docs",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",
@@ -16,7 +16,7 @@
16
16
  "openapi-docs": "bin.js"
17
17
  },
18
18
  "peerDependencies": {
19
- "@redocly/theme": ">=0.9.4",
19
+ "@redocly/theme": ">=0.51.0-next.0",
20
20
  "core-js": "^3.1.4",
21
21
  "react": "^18.0.0",
22
22
  "react-dom": "^18.0.0",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@markdoc/markdoc": "0.4.0",
27
- "@redocly/openapi-core": "0.0.0-snapshot.1737556585",
27
+ "@redocly/openapi-core": "1.28.2",
28
28
  "deepmerge": "^4.2.2",
29
29
  "dompurify": "2.5.4",
30
30
  "fast-deep-equal": "^3.1.3",
@@ -44,7 +44,7 @@
44
44
  "url-template": "^2.0.8",
45
45
  "util": "~0.12.5",
46
46
  "@redocly/config": "0.20.3",
47
- "@redocly/replay": "0.9.5"
47
+ "@redocly/replay": "0.10.0-next.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@shikijs/transformers": "1.24.0",
@@ -95,7 +95,7 @@
95
95
  "webpack": "5.94.0",
96
96
  "webpack-cli": "5.1.4",
97
97
  "webpack-dev-server": "5.1.0",
98
- "@redocly/theme": "0.50.0"
98
+ "@redocly/theme": "0.51.0-next.0"
99
99
  },
100
100
  "scripts": {
101
101
  "start": "npm run copy-highlight-hook && webpack serve --mode=development --hot",