@redocly/api-docs 0.2.0-next.5 → 0.2.0-next.7
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/RedocStandalone.d.ts +38 -0
- package/lib/RedocStandalone.js +1 -0
- package/lib/RedoclyApiDocs.js +1 -1
- package/lib/RedoclyApiDocsStandalone.d.ts +2 -0
- package/lib/RedoclyApiDocsStandalone.js +3 -3
- package/lib/adapters/asyncapi/items/overview/content.js +1 -1
- package/lib/adapters/graphql/group/utils.js +1 -1
- package/lib/adapters/graphql/utils/createApiItem.js +1 -1
- package/lib/adapters/openapi/build-code-sample-source.d.ts +1 -1
- package/lib/adapters/openapi/build-code-sample-source.js +1 -1
- package/lib/adapters/openapi/configure/merge-utils.d.ts +1 -1
- package/lib/adapters/openapi/configure/resolve-request-values.js +1 -1
- package/lib/adapters/openapi/index.js +1 -1
- package/lib/adapters/openapi/items/operation/content.js +1 -1
- package/lib/adapters/openapi/items/operation/item.js +1 -1
- package/lib/adapters/openapi/items/overview/content.js +1 -1
- package/lib/adapters/openapi/utils/merge-mock-server.d.ts +2 -2
- package/lib/adapters/utils/markdoc.d.ts +4 -1
- package/lib/adapters/utils/markdoc.js +1 -1
- package/lib/components/ErrorBoundary.d.ts +4 -2
- package/lib/components/ErrorBoundary.js +1 -1
- package/lib/components/Header/HeaderItem.js +5 -5
- package/lib/components/Header/HeaderPageActions.d.ts +4 -0
- package/lib/components/Header/HeaderPageActions.js +1 -0
- package/lib/components/Header/PageActions.d.ts +4 -0
- package/lib/components/Header/PageActions.js +11 -0
- package/lib/components/ItemContent/sections/MessagesSection.js +1 -1
- package/lib/components/Mcp/McpPrompt.js +1 -1
- package/lib/components/Mcp/McpTool.js +1 -1
- package/lib/components/Mcp/utils.d.ts +1 -1
- package/lib/components/Mcp/utils.js +1 -1
- package/lib/components/Schema/styled.js +4 -4
- package/lib/components/Schema/views/ArrayRenderer.js +1 -1
- package/lib/components/Schema/views/DiscriminatorPropertyRow.js +1 -1
- package/lib/components/Schema/views/Examples.js +1 -1
- package/lib/components/Search/index.d.ts +15 -0
- package/lib/components/Search/index.js +1 -0
- package/lib/components/Security/SecurityFlowDetail.js +1 -1
- package/lib/components/Security/styled.js +7 -7
- package/lib/components/StickySidebar/FloatingButton.d.ts +1 -0
- package/lib/components/StickySidebar/FloatingButton.js +32 -0
- package/lib/components/StickySidebar/RedoclyAttributionLogo.d.ts +5 -0
- package/lib/components/StickySidebar/RedoclyAttributionLogo.js +1 -0
- package/lib/components/StickySidebar/StickySidebar.js +33 -9
- package/lib/components/common/Breadcrumbs.js +2 -2
- package/lib/components/common/ResponseCodeTabs.js +1 -1
- package/lib/components/common/Tag.js +1 -1
- package/lib/components/common/ViewNested.js +2 -2
- package/lib/components/graphql/GraphQLFieldView.js +1 -1
- package/lib/components/graphql/RequiresScopesModal.js +3 -3
- package/lib/components/graphql/sections/GraphQLArgsSection.js +1 -1
- package/lib/components/markdoc/SchemaDefinition.js +1 -1
- package/lib/components/panels/ExampleItem/CodeSampleItem.js +1 -1
- package/lib/components/panels/ExampleItem/ResponseExampleItem.js +1 -1
- package/lib/components/panels/ExampleItem/SecuritySchemeSelector.d.ts +9 -0
- package/lib/components/panels/ExampleItem/SecuritySchemeSelector.js +1 -0
- package/lib/components/panels/ExampleItem/ServerDropdown.js +1 -1
- package/lib/components/panels/ExampleItem/generate-request-sample.d.ts +28 -0
- package/lib/components/panels/ExampleItem/generate-request-sample.js +1 -0
- package/lib/components/panels/ExampleItem/styled.d.ts +1 -49
- package/lib/components/panels/ExampleItem/useActiveServer.d.ts +17 -0
- package/lib/components/panels/ExampleItem/useActiveServer.js +1 -0
- package/lib/components/panels/ExampleItem/useCodeSampleLanguages.d.ts +23 -0
- package/lib/components/panels/ExampleItem/useCodeSampleLanguages.js +1 -0
- package/lib/components/panels/ExampleItem/useReplayRequestState.d.ts +18 -0
- package/lib/components/panels/ExampleItem/useReplayRequestState.js +1 -0
- package/lib/components/panels/ExampleItem/useTryItFooter.d.ts +3 -0
- package/lib/components/panels/ExampleItem/useTryItFooter.js +7 -0
- package/lib/components/panels/GroupPanelItem.js +1 -1
- package/lib/components/panels/LanguageItem/LanguagePanelItem.js +5 -1
- package/lib/components/panels/LanguageItem/styled.js +17 -14
- package/lib/components/panels/McpExamplePanelItem.js +2 -2
- package/lib/components/panels/McpPanelItem.js +2 -2
- package/lib/components/panels/ServerItem/ServerItem.js +1 -1
- package/lib/components/panels/asyncapi/BrokerItem/BrokerModal.js +1 -1
- package/lib/components/panels/asyncapi/BrokerItem/BrokerPanelItem.js +1 -1
- package/lib/components/panels/shared-panel-styles.js +1 -1
- package/lib/components/panels/styled.js +1 -1
- package/lib/components/pluggable/RedocResponseSamples.js +1 -1
- package/lib/hoc/withLicenseGate.d.ts +5 -0
- package/lib/hoc/withLicenseGate.js +1 -0
- package/lib/hoc/withStoreProvider.d.ts +2 -0
- package/lib/hoc/withStoreProvider.js +1 -1
- package/lib/hooks/useCopySpecSlice.d.ts +9 -0
- package/lib/hooks/useCopySpecSlice.js +1 -0
- package/lib/hooks/useInitialTelemetry.d.ts +2 -0
- package/lib/hooks/useInitialTelemetry.js +1 -0
- package/lib/hooks/useLicense.js +1 -1
- package/lib/hooks/useLicenseGate.d.ts +6 -0
- package/lib/hooks/useLicenseGate.js +1 -0
- package/lib/hooks/useScrollSpyUrlSync.js +1 -1
- package/lib/index.d.ts +6 -1
- package/lib/index.js +1 -1
- package/lib/jotai/app.d.ts +6 -0
- package/lib/jotai/app.js +1 -1
- package/lib/jotai/examples.js +1 -1
- package/lib/jotai/store.d.ts +4 -0
- package/lib/jotai/store.js +1 -1
- package/lib/options/editionOverrides.d.ts +3 -0
- package/lib/options/editionOverrides.js +1 -0
- package/lib/options/helpers.d.ts +1 -2
- package/lib/options/helpers.js +1 -1
- package/lib/options/normalizeOptions.d.ts +1 -1
- package/lib/options/normalizeOptions.js +1 -1
- package/lib/options/standaloneLayoutVars.d.ts +3 -0
- package/lib/options/standaloneLayoutVars.js +1 -0
- package/lib/pages/ItemPage.js +4 -2
- package/lib/services/code-samples/apply-env-variables.d.ts +8 -0
- package/lib/services/code-samples/apply-env-variables.js +1 -0
- package/lib/services/code-samples/builder.js +1 -1
- package/lib/services/code-samples/language-availability.d.ts +4 -0
- package/lib/services/code-samples/language-availability.js +1 -0
- package/lib/services/code-samples/{replay/normalize-servers.d.ts → normalize-servers.d.ts} +1 -1
- package/lib/services/code-samples/normalize-servers.js +1 -0
- package/lib/services/code-samples/replay/from-openapi-document.d.ts +8 -1
- package/lib/services/code-samples/replay/from-openapi-document.js +1 -1
- package/lib/services/code-samples/replay/index.d.ts +1 -1
- package/lib/services/code-samples/replay/index.js +1 -1
- package/lib/services/code-samples/replay/replay-predefined-env.d.ts +1 -2
- package/lib/services/code-samples/replay/replay-predefined-env.js +1 -1
- package/lib/services/code-samples/server-env.d.ts +3 -0
- package/lib/services/code-samples/server-env.js +1 -0
- package/lib/services/code-samples/source.d.ts +3 -3
- package/lib/services/license/check.d.ts +1 -0
- package/lib/services/license/check.js +1 -1
- package/lib/services/operation-samples/index.js +1 -1
- package/lib/services/search/indexer.d.ts +9 -0
- package/lib/services/search/indexer.js +1 -0
- package/lib/services/search/types.d.ts +27 -0
- package/lib/services/search/types.js +0 -0
- package/lib/services/spec-slice/assistant-links.d.ts +9 -0
- package/lib/services/spec-slice/assistant-links.js +5 -0
- package/lib/services/spec-slice/asyncapi-slice.d.ts +5 -0
- package/lib/services/spec-slice/asyncapi-slice.js +1 -0
- package/lib/services/spec-slice/clone-strip.d.ts +1 -0
- package/lib/services/spec-slice/clone-strip.js +1 -0
- package/lib/services/spec-slice/component-closure.d.ts +6 -0
- package/lib/services/spec-slice/component-closure.js +1 -0
- package/lib/services/spec-slice/graphql-slice.d.ts +2 -0
- package/lib/services/spec-slice/graphql-slice.js +1 -0
- package/lib/services/spec-slice/index.d.ts +6 -0
- package/lib/services/spec-slice/index.js +1 -0
- package/lib/services/spec-slice/openapi-slice.d.ts +6 -0
- package/lib/services/spec-slice/openapi-slice.js +1 -0
- package/lib/services/spec-slice/resolve-scope.d.ts +4 -0
- package/lib/services/spec-slice/resolve-scope.js +1 -0
- package/lib/services/spec-slice/types.d.ts +37 -0
- package/lib/services/spec-slice/types.js +0 -0
- package/lib/standalone.d.ts +19 -0
- package/lib/standalone.js +2 -0
- package/lib/standaloneThemeConfig.d.ts +3 -0
- package/lib/standaloneThemeConfig.js +1 -0
- package/lib/telemetry/RedocTelemetry.d.ts +3 -0
- package/lib/telemetry/RedocTelemetry.js +1 -1
- package/lib/telemetry/defaults.d.ts +2 -0
- package/lib/telemetry/defaults.js +1 -0
- package/lib/types/code-samples-config.d.ts +68 -0
- package/lib/types/code-samples-config.js +0 -0
- package/lib/types/common.d.ts +1 -1
- package/lib/types/content.d.ts +4 -3
- package/lib/types/edition-config.d.ts +4 -0
- package/lib/types/edition-config.js +0 -0
- package/lib/types/events.d.ts +2 -2
- package/lib/types/openapi.d.ts +2 -1
- package/lib/types/options.d.ts +24 -88
- package/lib/utils/compose.d.ts +1 -0
- package/lib/utils/deep-link.d.ts +1 -0
- package/lib/utils/deep-link.js +1 -1
- package/lib/utils/extract-extensions.js +1 -1
- package/lib/utils/x-logo.d.ts +13 -0
- package/lib/utils/x-logo.js +1 -0
- package/package.json +19 -8
- package/lib/services/code-samples/replay/normalize-servers.js +0 -1
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./types/common.js";import{buildItems as t,buildNavItems as p}from"./adapters/build.js";import{buildGraphqlStoreFromSdl as m}from"./adapters/graphql/buildStoreFromSdl.js";import{simplifyAstStructure as
|
|
1
|
+
export*from"./types/common.js";import{buildItems as t,buildNavItems as p}from"./adapters/build.js";import{buildGraphqlStoreFromSdl as m}from"./adapters/graphql/buildStoreFromSdl.js";import{simplifyAstStructure as f}from"./adapters/utils/simplifyAstStructure.js";import{extractFullText as s}from"./adapters/utils/markdoc.js";import{normalizeOptions as n}from"./options/normalizeOptions.js";import{excludeMockServers as c}from"./adapters/openapi/utils/merge-mock-server.js";import{appendUndeclaredConfigureParameters as S}from"./services/code-samples/replay/merge-configure-into-source.js";import{findFirstBinding as y}from"./adapters/asyncapi/build/utils.js";import{resolveRequestValues as D,applyRequestValuesToOperationInfo as P}from"./adapters/openapi/configure/index.js";import{updateObjectProperties as M,isDirectRequestValues as v,getEffectiveRequestValues as k,createSecurityUpdates as A,mergeSecurityIntoScheme as E,applyServerVariableDefaults as b}from"./adapters/openapi/configure/merge-utils.js";import{MarkdownAdapterProvider as O,useMarkdownAdapter as I}from"./contexts/markdownAdapter.js";import{markdocParser as V}from"./components/markdoc/markdocParser.js";import{createMarkdocAdapter as w}from"./components/markdoc/markdocAdapter.js";import{adapterToMarkdownParser as N}from"./components/Replay/adapterToMarkdownParser.js";import{parseMarkdown as B}from"./adapters/utils/parseMarkdown.js";import{isPlainText as H}from"./adapters/utils/isPlainText.js";import{buildMarkdocOptions as J}from"./components/markdoc/buildMarkdocOptions.js";import{apiDocsMarkdocTags as Y,apiDocsMarkdocNodes as j}from"./components/markdoc/defaultMarkdocConfig.js";import{apiDocsMarkdocComponents as K}from"./components/markdoc/apiDocsMarkdocComponents.js";import{RedoclyApiDocs as W}from"./RedoclyApiDocs.js";import{RedoclyApiDocsStandalone as Z}from"./RedoclyApiDocsStandalone.js";import{ApiDocsSearchIndexer as ee}from"./services/search/indexer.js";import{RedocTelemetry as oe}from"./telemetry/RedocTelemetry.js";import{Replay as pe,EmbeddedReplay as ae}from"./components/Replay/index.js";import{REPLAY_TRY_IT_LOADING_STATE as de}from"./services/code-samples/index.js";import{findExampleIdByKey as ie}from"./services/code-samples/example-key.js";import{RedocSchema as xe,RedocExample as ne,RedocResponseSamples as le,RedocCodeSample as ce}from"./components/pluggable/index.js";import{StoreProvider as Se}from"./hoc/withStoreProvider.js";import{GraphQLTypeViewByName as ye}from"./components/graphql/GraphQLTypeView.js";import{mcpTagSchemas as De}from"./components/markdoc/tags/mcp-tag-schemas.js";import{schemaDefinitionTag as ge}from"./components/markdoc/tags/schema-definition-tag.js";import{withReplayPrefetch as ve,useOpenApiDefinition as ke}from"./hoc/withReplayPrefetch.js";import{mergeEnvData as Ee}from"./utils/environments.js";import{buildReplayPredefinedEnvValues as he}from"./services/code-samples/replay/replay-predefined-env.js";import{createDocumentReplayConverter as Ie}from"./services/code-samples/replay/from-openapi-document.js";import{ReplayCodeSampleHTTPSnippet as Ve}from"./services/code-samples/replay/har-to-code-sample-har.js";import{encodeJsonPointerSegment as we}from"./utils/refPointer.js";import{JsonPointer as Ne}from"./adapters/openapi/utils/JsonPointer.js";import{langFromMime as Be,encodeExampleForMediaType as Ge}from"./utils/media-type.js";import{isOperationName as Le,HTTP_METHODS as Je}from"./utils/http-methods.js";import{convertSampleToString as Ye}from"./services/code-samples/convertSampleToString.js";import{resolveOperationSampleContext as ze,buildCodeSamples as Ke,getRequestBodySamples as Qe,getResponseSamples as We}from"./services/operation-samples/index.js";export{ee as ApiDocsSearchIndexer,ae as EmbeddedReplay,ye as GraphQLTypeViewByName,Je as HTTP_METHODS,Ne as JsonPointer,O as MarkdownAdapterProvider,de as REPLAY_TRY_IT_LOADING_STATE,ce as RedocCodeSample,ne as RedocExample,le as RedocResponseSamples,xe as RedocSchema,oe as RedocTelemetry,W as RedoclyApiDocs,Z as RedoclyApiDocsStandalone,pe as Replay,Ve as ReplayCodeSampleHTTPSnippet,Se as StoreProvider,N as adapterToMarkdownParser,K as apiDocsMarkdocComponents,j as apiDocsMarkdocNodes,Y as apiDocsMarkdocTags,S as appendUndeclaredConfigureParameters,P as applyRequestValuesToOperationInfo,b as applyServerVariableDefaults,Ke as buildCodeSamples,m as buildGraphqlStoreFromSdl,t as buildItems,J as buildMarkdocOptions,p as buildNavItems,he as buildReplayPredefinedEnvValues,Ye as convertSampleToString,Ie as createDocumentReplayConverter,w as createMarkdocAdapter,A as createSecurityUpdates,Ge as encodeExampleForMediaType,we as encodeJsonPointerSegment,c as excludeMockServers,s as extractFullText,ie as findExampleIdByKey,y as findFirstBinding,k as getEffectiveRequestValues,Qe as getRequestBodySamples,We as getResponseSamples,v as isDirectRequestValues,Le as isOperationName,H as isPlainText,Be as langFromMime,V as markdocParser,De as mcpTagSchemas,Ee as mergeEnvData,E as mergeSecurityIntoScheme,n as normalizeOptions,B as parseMarkdown,ze as resolveOperationSampleContext,D as resolveRequestValues,ge as schemaDefinitionTag,f as simplifyAstStructure,M as updateObjectProperties,I as useMarkdownAdapter,ke as useOpenApiDefinition,ve as withReplayPrefetch};
|
package/lib/jotai/app.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type AppSessionStore = {
|
|
|
15
15
|
export type AppStore = {
|
|
16
16
|
activeMimeName: string;
|
|
17
17
|
layout: LayoutVariant;
|
|
18
|
+
colorMode: string;
|
|
18
19
|
language: string;
|
|
19
20
|
environment: string;
|
|
20
21
|
environments: Record<string, Record<string, string>>;
|
|
@@ -47,6 +48,11 @@ export declare const allowedEnvironmentsAtom: import("jotai").WritableAtom<strin
|
|
|
47
48
|
* appSessionStore saved to session storage
|
|
48
49
|
*/
|
|
49
50
|
export declare const appSessionStore: import("jotai").WritableAtom<AppSessionStore, [typeof import("jotai/utils").RESET | AppSessionStore | ((prev: AppSessionStore) => typeof import("jotai/utils").RESET | AppSessionStore)], void>;
|
|
51
|
+
/** Mobile sidebar drawer — open state is per-view, never persisted. */
|
|
52
|
+
export declare const isSidebarOpenedAtom: import("jotai").PrimitiveAtom<boolean> & {
|
|
53
|
+
init: boolean;
|
|
54
|
+
};
|
|
55
|
+
export declare const colorModeAtom: import("jotai").WritableAtom<string, string[], void>;
|
|
50
56
|
export declare const collapsedSidebarAtom: import("jotai").WritableAtom<boolean, boolean[], void>;
|
|
51
57
|
export declare const languageAtom: import("jotai").WritableAtom<LanguageAtom, [string], void>;
|
|
52
58
|
export declare const selectedSecuritySchemeIdxAtom: import("jotai").PrimitiveAtom<number> & {
|
package/lib/jotai/app.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{atom as r}from"jotai";import{atomWithStorage as
|
|
1
|
+
import{atom as r}from"jotai";import{atomWithStorage as g,createJSONStorage as y}from"jotai/utils";import{LayoutVariant as O}from"@redocly/config";import{DEFAULT_COLOR_MODES as c}from"@redocly/theme/core/constants";import{getCookie as E,removeCookie as L,setCookie as k}from"../utils/cookies.js";import{mergeEnvData as p,IS_BROWSER as d}from"../utils/environments.js";import{keepReadingSectionAnchored as C}from"../utils/scroll-anchoring.js";import{safeJsonParse as S}from"../utils/string.js";import{fromSessionStorage as M,toSessionStorage as h}from"../utils/session-storage.js";import{DEFAULT_LAYOUT as N}from"../options/constants.js";import{globalOptionsAtom as T}from"./store.js";const f={activeMimeName:"",layout:N,colorMode:"",language:"",environment:"",environments:{},userClaims:{},allowedEnvironments:null},b={getItem:e=>{const o=S(E(e,globalThis.redoclyCookieStorage?.getStore?.())),t=S(M(e));return{...f,...t,...o}},setItem:(e,o)=>{const{environments:t,...n}=o,a={environments:t};k(e,JSON.stringify(n)),h(e,JSON.stringify(a))},removeItem:e=>{L(e),sessionStorage.removeItem(e)}},s=g("redoc.appStore",f,b),H=r(e=>{const o=e(s);return p(o.environments,{})}),W=r(e=>{const o=e(s),t=p(o.environments,{}),n=o.environment,a=Object.keys(t).find(l=>t[l]?.server===n),i=t[n]?n:a??Object.keys(t)[0];let m=t[i]||{};return!m.server&&a&&(m={...t[a],...m}),[m,i||""]},(e,o,{environment:t,environments:n})=>{const a=e(s);o(s,{...a,environment:t||a.environment,environments:p(a.environments||{},n)})}),B=r(e=>e(s).environment),u=r(e=>e(s).activeMimeName,(e,o,t)=>{const n=e(s);o(s,{...n,activeMimeName:t})}),A=r(void 0),P=r(e=>e(A)??(e(u)||void 0),(e,o,t)=>{o(A,void 0),(t??"")!==e(u)&&C(),o(u,t??"")}),Y=r(e=>e(s).layout,(e,o,t=O.STACKED)=>{const n=e(s);o(s,{...n,layout:t})}),z=r(e=>e(s).userClaims,(e,o,t)=>{const n=e(s);o(s,{...n,userClaims:t})}),Q=r(e=>e(s).allowedEnvironments,(e,o,t)=>{const n=e(s);o(s,{...n,allowedEnvironments:t})}),v=g("redoc.appSessionStore",{collapsedSidebar:!1,unsupportedFeatureScreen:!1},d?y(()=>sessionStorage):void 0),X=r(!1),D=[c.LIGHT,c.DARK];function I(e){const o=document.documentElement;D.forEach(t=>o.classList.remove(t)),o.classList.add(e,"notransition"),window.requestAnimationFrame(()=>{o.classList.remove("notransition")})}const Z=r(e=>{const o=e(s).colorMode||(d&&window.matchMedia?.("(prefers-color-scheme: dark)").matches?c.DARK:c.LIGHT);return d&&I(o),o},(e,o,t)=>{const n=e(s);o(s,{...n,colorMode:t})}),$=r(e=>e(v).collapsedSidebar,(e,o,t)=>{const n=e(v);o(v,{...n,collapsedSidebar:t})}),ee=r(e=>{const o=e(T),{codeSamples:t}=o;if(!t?.languages)return{languages:[],activeLanguage:e(s).language||""};const n=t.languages.map(({key:i,label:m,lang:l},x)=>({key:i,lang:l,title:m,order:x})),a=e(s).language||n[0]?.key;return{languages:n,activeLanguage:n.find(({key:i})=>i===a)?.key||n[0]?.key}},(e,o,t)=>{const n=e(s);o(s,{...n,language:t})}),oe=r(0),te=r({}),ne=r(null),se=r([]);export{P as activeMediaTypeAtom,u as activeMimeNameAtom,ne as activeScrollSectionAtom,Q as allowedEnvironmentsAtom,v as appSessionStore,s as appStore,$ as collapsedSidebarAtom,Z as colorModeAtom,W as environmentAtom,H as environmentsAtom,X as isSidebarOpenedAtom,ee as languageAtom,Y as layoutAtom,A as mediaTypeOverrideAtom,te as requestValuesAtom,B as savedEnvironmentNameAtom,oe as selectedSecuritySchemeIdxAtom,z as userClaimsAtom,se as visitedChannelsAtom};
|
package/lib/jotai/examples.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{atom as m}from"jotai";import{atomFamily as f}from"jotai-family";import*as
|
|
1
|
+
import{atom as m}from"jotai";import{atomFamily as f}from"jotai-family";import*as E from"openapi-sampler";import{schemaKind as g}from"../types/common.js";import{convertSampleToString as y}from"../services/code-samples/index.js";import{applyActiveVariantsToStore as h}from"../services/code-samples/discriminator.js";import{isSequentialMediaType as M}from"../utils/media-type.js";import{storeAtom as j,globalOptionsAtom as x}from"./store.js";import{schemaStoreAtom as l}from"./schema.js";import{activeDiscriminatorSelectAtom as F,activeOneOfSelectAtom as N}from"./itemStore.js";const G=m(t=>t(j).exampleStore??{});function A(t){const e={};for(const[n,r]of Object.entries(t)){const o=n.startsWith("components/schemas/")?n.replace("components/schemas/",""):n;e[o]=r}return{openapi:"3.0.0",info:{title:"",version:""},paths:{},components:{schemas:e}}}function R(t,e){return!!t&&Object.keys(t).length>0||!!e&&Object.keys(e).length>0}const u=m(t=>h(t(l))),O=f(t=>m(e=>{if(!t)return e(u);const n=e(F(t)),r=e(N(t));return R(n,r)?h(e(l),n,r):e(u)})),V=m(t=>A(t(u))),C=f(t=>m(e=>{const n=e(O(t));return n===e(u)?e(V):A(n)})),D="";function Q(t,e,n,r){return t?JSON.stringify({itemId:r??"",schemaId:t,context:e??"",mediaType:n??""}):D}function J(t){if(t)try{const e=JSON.parse(t);if(!e||typeof e.schemaId!="string"||!e.schemaId)return;const n=typeof e.itemId=="string"?e.itemId:"",r=typeof e.context=="string"?e.context:"",o=typeof e.mediaType=="string"?e.mediaType:"";return{itemId:n,schemaId:e.schemaId,context:r==="request"||r==="response"?r:void 0,mediaType:o||void 0}}catch{return}}const U=f(t=>{const e=J(t);return m(n=>{if(!e)return;const{itemId:r,schemaId:o,context:i,mediaType:p}=e,s=n(l)[o];if(!s||s.kind!==g.JSON_SCHEMA)return;const d=n(C(r)),v=n(O(r))[o]??s.data,{onlyRequiredInSamples:I,generatedSamplesMaxDepth:T}=n(x),{unstable_skipSamples:k}=n(x);if(k)return;const a=p?.toLowerCase(),q=a?a.includes("xml"):!1;try{const S={context:i,skipNonRequired:i==="request"&&I,maxSampleDepth:T,isXml:q},c=b(v,d,S);return c==null?c:a&&M(a)?K(s.data,c,d,S,a):c}catch{return}})});function K(t,e,n,r,o){const i=_(t);if(i.length>0){const p=i.map(s=>b(s,n,r)).filter(s=>s!=null);if(p.length>0)return y(p,o,t,!1)}return y(e,o,t,!0)}function _(t){const e=t.oneOf;return Array.isArray(e)?e.filter(n=>typeof n=="object"&&n!==null):[]}function b(t,e,{context:n,skipNonRequired:r,maxSampleDepth:o,isXml:i}){return E.sample(t,{skipReadOnly:n==="request",skipWriteOnly:n==="response",quiet:!0,skipNonRequired:r,maxSampleDepth:o,...i&&{format:"xml"}},e)}export{Q as buildExampleAtomKey,G as exampleStoreAtom,U as generatedExampleAtom,C as itemSpecForSamplerAtom};
|
package/lib/jotai/store.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export type GlobalStoreAtom = {
|
|
|
6
6
|
items: ApiItem[];
|
|
7
7
|
store: ApiStore;
|
|
8
8
|
options: ApiDocsOptions;
|
|
9
|
+
definition?: Record<string, unknown> | string;
|
|
10
|
+
definitionUrl?: string;
|
|
9
11
|
replayDefinition: OpenAPIDefinition | null;
|
|
10
12
|
};
|
|
11
13
|
export declare const globalStoreAtom: import("jotai").PrimitiveAtom<GlobalStoreAtom> & {
|
|
@@ -19,6 +21,8 @@ export declare const specTypeAtom: import("jotai").Atom<ApiSpecType>;
|
|
|
19
21
|
export declare const routingBasePathAtom: import("jotai").Atom<string>;
|
|
20
22
|
export declare const licenseKeyAtom: import("jotai").Atom<string | undefined>;
|
|
21
23
|
export declare const storeAtom: import("jotai").Atom<ApiStore>;
|
|
24
|
+
export declare const definitionAtom: import("jotai").Atom<string | Record<string, unknown> | undefined>;
|
|
25
|
+
export declare const definitionUrlAtom: import("jotai").Atom<string | undefined>;
|
|
22
26
|
export declare const replayDefinitionAtom: import("jotai").Atom<OpenAPIDefinition | null>;
|
|
23
27
|
export declare const setReplayDefinitionAtom: import("jotai").WritableAtom<null, [value: OpenAPIDefinition | null], void> & {
|
|
24
28
|
init: null;
|
package/lib/jotai/store.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{atom as o}from"jotai";const m={schemaStore:{},exampleStore:{},securitySchemeStore:{}},e=o({items:[],store:m,options:{},replayDefinition:null}),
|
|
1
|
+
import{atom as o}from"jotai";const m={schemaStore:{},exampleStore:{},securitySchemeStore:{}},e=o({items:[],store:m,options:{},replayDefinition:null}),a=o(t=>t(e).items),l=o(t=>{const i={};function s(p){for(const n of p){const r=n.content?.meta?.name;n.httpVerb==="schema"&&r&&n.routeSlug&&(i[r]=n.routeSlug),"items"in n&&Array.isArray(n.items)&&s(n.items)}}return s(t(e).items),i}),f=o(t=>t(e).options),A=o(t=>t(e).options.specType),x=o(t=>t(e).options.basePath),y=o(t=>t(e).options.licenseKey),u=o(t=>t(e).store??m),S=o(t=>t(e).definition),g=o(t=>t(e).definitionUrl),h=o(t=>t(e).replayDefinition),D=o(null,(t,i,s)=>{i(e,{...t(e),replayDefinition:s})});export{S as definitionAtom,g as definitionUrlAtom,a as globalItemsAtom,f as globalOptionsAtom,e as globalStoreAtom,y as licenseKeyAtom,h as replayDefinitionAtom,x as routingBasePathAtom,l as schemaDefinitionSlugMapAtom,D as setReplayDefinitionAtom,A as specTypeAtom,u as storeAtom};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { RawApiDocsOptions } from '../types/options.js';
|
|
2
|
+
/** Option overrides applied on top of host options in `normalizeOptions`. The community edition forces enterprise options off here. */
|
|
3
|
+
export declare const EDITION_OPTION_OVERRIDES: Partial<RawApiDocsOptions>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const I={};export{I as EDITION_OPTION_OVERRIDES};
|
package/lib/options/helpers.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LayoutVariant, type RedocConfig } from '@redocly/config';
|
|
2
2
|
import type { ApiSpecType } from '../types/common.js';
|
|
3
3
|
import type { RawApiDocsOptions } from '../types/options.js';
|
|
4
|
-
import type { CodeSamplesConfig } from '../types/
|
|
4
|
+
import type { CodeSamplesConfig } from '../types/code-samples-config.js';
|
|
5
5
|
export declare function argValueToBoolean(val?: string | boolean, defaultValue?: boolean): boolean;
|
|
6
6
|
export declare function argValueToNumber(value: number | string | undefined, defaultValue?: number): number;
|
|
7
7
|
export declare function argValueToInt(value: number | string | undefined, defaultValue?: number): number;
|
|
@@ -23,4 +23,3 @@ export declare function normalizeDownloadUrls(downloadUrls: {
|
|
|
23
23
|
url: string;
|
|
24
24
|
}[];
|
|
25
25
|
export declare function normalizeLayout(layout: RawApiDocsOptions['layout']): LayoutVariant;
|
|
26
|
-
export declare function isGraphqlDocsSidebarHidden(options: Pick<RawApiDocsOptions, 'specType' | 'sidebar'>): boolean;
|
package/lib/options/helpers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LayoutVariant as
|
|
1
|
+
import{LayoutVariant as i}from"@redocly/config";import{apiSpecType as o}from"../types/common.js";import{DEFAULT_LAYOUT as f}from"./constants.js";import{DEFAULT_LANGUAGES as p,getLangKey as s}from"../utils/languages.js";function d(r,t){return r===void 0?t??!1:typeof r=="string"?r!=="false":r}function A(r,t=0){return typeof r=="string"?parseInt(r,10):typeof r=="number"?r:t}function u(r,t=0){return typeof r=="string"?parseInt(r,10):typeof r=="number"?Math.ceil(r):t}function x(r,t){return r===void 0?t:r==="all"?1/0:u(r,t)}function h(r){let t=r;return t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),t.startsWith("/")||(t="/"+t),t}function E(r){if(typeof r>"u")return!1;if(r==="")return!0;if(typeof r!="string")return r;switch(r){case"true":return!0;case"false":return!1;default:return r.split(",").map(t=>t.trim()).filter(Boolean)}}function a(r){return/^-?\d+(\.\d+)?$/.test(r)}function T(r){return typeof r=="number"?()=>r:typeof r=="string"&&a(r)?()=>parseFloat(r):typeof r=="function"?()=>{const t=r();return typeof t=="number"?t:0}:()=>0}function L(r){const t=typeof r=="object"&&r!==null?r:{},n=t.languages??p.map(({label:e})=>({lang:e}));return{...t,languages:n.map(e=>({...e,key:s(e),label:e.label??e.lang}))}}function S(r){return Array.isArray(r)?r:typeof r=="string"?r.split(",").map(t=>t.trim()):[]}function b(r,t){return r.map(n=>({...n,title:n.title??m(n.url,t)}))}function m(r,t){const n=r.split("?")[0].split(/[\\/]/).pop();if(n&&["yaml","json","gql","graphql"].some(e=>n.includes(e)))return n;switch(t){case o.OPENAPI:return"openapi.yaml";case o.ASYNCAPI:return"asyncapi.yaml";case o.GRAPHQL:return"graphql.gql";default:return"description.json"}}function N(r){return r===void 0?f:r===i.STACKED?i.STACKED:i.THREE_PANEL}export{d as argValueToBoolean,x as argValueToExpandLevel,u as argValueToInt,A as argValueToNumber,L as normalizeCodeSamples,b as normalizeDownloadUrls,S as normalizeIgnoreNamedSchemas,N as normalizeLayout,h as normalizePath,T as normalizeScrollYOffset,E as normalizeShowExtensions};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ApiDocsOptions, RawApiDocsOptions } from '../types/options.js';
|
|
2
|
-
export declare function normalizeOptions(
|
|
2
|
+
export declare function normalizeOptions(rawOptions: RawApiDocsOptions): ApiDocsOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{addTrailingSlash as
|
|
1
|
+
import{addTrailingSlash as r}from"@redocly/theme/core/openapi";import{WindowReferenceOptions as t}from"../constants/openapi.js";import{argValueToBoolean as a,argValueToExpandLevel as n,argValueToInt as s,argValueToNumber as m,normalizeCodeSamples as d,normalizeDownloadUrls as p,normalizeIgnoreNamedSchemas as S,normalizeLayout as E,normalizePath as c,normalizeScrollYOffset as u,normalizeShowExtensions as h}from"./helpers.js";import{ASYNCAPI_DEFAULT_JSON_SAMPLES_DEPTH as _,DEFAULT_FEEDBACK as L,DEFAULT_MAX_DISPLAYED_ENUM_VALUES as f,GENERATED_SAMPLES_MAX_DEPTH_DEFAULT as P,GRAPHQL_DEFAULT_FIELD_EXPAND_LEVEL as A,GRAPHQL_DEFAULT_JSON_SAMPLES_DEPTH as D,GRAPHQL_DEFAULT_SAMPLES_MAX_INLINE_ARGS as T,JSON_SAMPLES_EXPAND_LEVEL_DEFAULT as i,MOCK_SERVER_DEFAULT_DESCRIPTION as I,MOCK_SERVER_DEFAULT_POSITION as R,DEFAULT_ROUTING_BASE_PATH as x}from"./constants.js";import{apiSpecType as N}from"../types/common.js";import{EDITION_OPTION_OVERRIDES as k}from"./editionOverrides.js";function v(l){const e={...l,...k},o=e.basePath||e.routingBasePath;return{specType:e.specType,licenseKey:e.licenseKey,metadata:e.metadata??{},downloadUrls:p(e.downloadUrls??[],e.specType),userClaims:e.userClaims,dynamicRequestValues:e.dynamicRequestValues,schemaDefinitionsTagName:e.schemaDefinitionsTagName,corsProxyUrl:e.corsProxyUrl?r(e.corsProxyUrl):void 0,jsonSamplesExpandLevel:n(e.jsonSamplesExpandLevel,i)??i,generatedSamplesMaxDepth:s(e.generatedSamplesMaxDepth,P),hideDownloadButtons:a(e.hideDownloadButtons,!1),hideInfoMetadata:a(e.hideInfoMetadata,!1),hideLoading:a(e.hideLoading,!1),hideSchemaTitles:a(e.hideSchemaTitles,!1),hideSchemaPattern:a(e.hideSchemaPattern,!1),maxDisplayedEnumValues:m(e.maxDisplayedEnumValues,f),mockServer:e.mockServer?.url?{url:e.mockServer.url,position:e.mockServer.position||R,description:e.mockServer.description||I}:void 0,hideReplay:a(e.hideReplay,!1),oAuth2RedirectURI:e.oAuth2RedirectURI,onlyRequiredInSamples:a(e.onlyRequiredInSamples,!1),[t.ON_DEEP_LINK_CLICK]:e.onDeepLinkClick??null,basePath:o?c(o):x,schemasExpansionLevel:n(e.schemasExpansionLevel),feedback:e.feedback??L,sortRequiredPropsFirst:a(e.sortRequiredPropsFirst??e.requiredPropsFirst,!1),scrollYOffset:u(e.scrollYOffset),showExtensions:h(e.showExtensions),sanitize:a(e.sanitize,!1),skipBundle:a(e.skipBundle,!1),ignoreNamedSchemas:new Set(S(e.ignoreNamedSchemas)),markdocOptions:e.markdocOptions,markdownParser:e.markdownParser,codeSamples:d(e.codeSamples),layout:E(e.layout),events:e.events??{},unstable_hooks:e.unstable_hooks??{},unstable_skipSamples:a(e.unstable_skipSamples,!1),unstable_externalCodeSamples:e.unstable_externalCodeSamples??[],hidePropertiesPrefix:a(e?.hidePropertiesPrefix,!1),showSchemaCatalogLinks:a(e?.showSchemaCatalogLinks,!1),jsonSamplesDepth:s(e.jsonSamplesDepth,e.specType===N.ASYNCAPI?_:D),samplesMaxInlineArgs:s(e.samplesMaxInlineArgs,T),fieldExpandLevel:s(e.fieldExpandLevel,A),menu:e.menu,showBuiltInScalars:e.showBuiltInScalars,showBuiltInDirectives:e.showBuiltInDirectives,info:e.info,markdown:e.markdown,apiLogo:e.apiLogo,protocol:e.protocol}}export{v as normalizeOptions};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function n({scrollYOffset:e}){const t=e?.()??0;if(!(t<=0))return{"--navbar-height":`${t}px`,"--navbar-stack-height":`${t}px`}}export{n as getStandaloneLayoutStyle};
|
package/lib/pages/ItemPage.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{jsx as r,jsxs as
|
|
1
|
+
import{jsx as r,jsxs as d}from"react/jsx-runtime";import{Fragment as v,memo as u}from"react";import{styled as p}from"styled-components";import{useAtomValue as s}from"jotai";import{ComponentMapper as k}from"../components/Mapper.js";import{SchemaCatalogLink as y}from"../components/SchemaCatalogLink.js";import{RenderHook as c}from"../components/RenderHook.js";import{ContentWrapper as l}from"../components/common/ContentWrapper.js";import{globalOptionsAtom as I}from"../jotai/store.js";import{routingBasePathAtom as x}from"../jotai/store.js";import{compose as A}from"../utils/compose.js";import{toElementId as O}from"../utils/url.js";import{withItemId as C}from"../hoc/withItemId.js";import{SECTION_ATTR as T}from"../constants/openapi.js";function j({content:o,itemPath:e,sectionId:i}){const{children:f}=o||{},a=o?.meta?.pointer,{unstable_hooks:n}=s(I),g=s(x),b=i?{[T]:i}:{},h=e?O(e,g):void 0;return d(P,{id:h,...b,"data-item-kind":o.itemVariant,"data-has-divider":o.showDivider||void 0,children:[r(c,{Hook:n?.BeforeOperation,props:{operation:o}}),f?.map((t,m)=>d(v,{children:[r(k,{type:t.nodeType,node:t,itemPath:e}),m===0&&a&&r(l,{children:r(y,{schemaRef:"#"+a})})]},`${e}-${t.nodeType}-${m}`)),r(c,{Hook:n?.AfterOperation,props:{operation:o}}),o.showDivider&&r(l,{children:r(w,{})})]})}const q=A(C,u)(j),w=p.div`
|
|
2
2
|
border-bottom: 1px solid var(--border-color-secondary);
|
|
3
3
|
`,P=p.div`
|
|
4
4
|
padding-top: calc(var(--spacing-unit) * 16);
|
|
@@ -10,9 +10,11 @@ import{jsx as r,jsxs as m}from"react/jsx-runtime";import{Fragment as v,memo as u
|
|
|
10
10
|
padding-top: calc(var(--spacing-unit) * 16);
|
|
11
11
|
padding-bottom: 0;
|
|
12
12
|
|
|
13
|
+
// @community-ignore
|
|
13
14
|
[data-component-name='FeedbackItem'] {
|
|
14
15
|
margin: 0;
|
|
15
16
|
}
|
|
17
|
+
// @community-ignore-end
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
&[data-item-kind='channel'],
|
|
@@ -23,4 +25,4 @@ import{jsx as r,jsxs as m}from"react/jsx-runtime";import{Fragment as v,memo as u
|
|
|
23
25
|
&[data-item-kind='channelOperation']:not([data-has-divider]) {
|
|
24
26
|
border-bottom: 1px solid var(--border-color-secondary);
|
|
25
27
|
}
|
|
26
|
-
`;export{
|
|
28
|
+
`;export{q as ItemPage};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CodeSampleRequestValues } from './source.js';
|
|
2
|
+
/**
|
|
3
|
+
* Substitutes `{{name}}` environment-variable placeholders in a sample using
|
|
4
|
+
* the base env variables plus the active server's scoped overrides.
|
|
5
|
+
* `requestValues.serverEnvVariables` is keyed by the raw (templated) spec
|
|
6
|
+
* server URL.
|
|
7
|
+
*/
|
|
8
|
+
export declare function applyEnvVariables(sample: string, requestValues: CodeSampleRequestValues | undefined, activeServerSpecUrl: string | undefined): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function o(a,n,r){const l={...n?.envVariables,...r&&n?.serverEnvVariables?.[r]};let e=a;for(const[s,t]of Object.entries(l))e=e.replaceAll(`{{${s}}}`,t);return e}export{o as applyEnvVariables};
|
|
@@ -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 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};
|
|
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"./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};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Which configured languages are offered in the code-sample panel. The community edition keeps only payload and x-codeSamples languages. */
|
|
2
|
+
export declare function filterAvailableLanguages<L extends {
|
|
3
|
+
key: string;
|
|
4
|
+
}>(languages: L[], _definitionSampleKeys: Set<string>): L[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function n(e,i){return e}export{n as filterAvailableLanguages};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { OpenAPIServer } from '
|
|
1
|
+
import type { OpenAPIServer } from '../../types/openapi.js';
|
|
2
2
|
export declare function resolveServerUrl(url: string, specUrl?: string): string;
|
|
3
3
|
export declare function normalizeServers(specUrl: string | undefined, servers: OpenAPIServer[]): OpenAPIServer[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isAbsoluteUrl as l,removeQueryStringAndHash as o,resolveUrl as s}from"../../adapters/openapi/utils/helpers.js";import{getUrlDirname as i}from"../../adapters/openapi/utils/url.js";import{IS_BROWSER as u}from"../../utils/environments.js";function f(e){const t=o(e);if(!t||t.endsWith("/"))return t;const r=t.lastIndexOf("/");return r===-1?"":t.slice(0,r)}function a(e){return e===void 0?o((()=>{if(!u)return globalThis.SSR_HOSTNAME||"";const r=window.location.href;return r.endsWith(".html")&&i(r)||r})()):l(e)?i(e):f(e)}function m(e,t){const r=a(t);return r?s(r,e):e}function S(e,t){let r=t;return r.length===0&&(r=[{url:"/"}]),r.map(n=>({...n,url:m(n.url,e),description:n.description||""}))}export{S as normalizeServers,m as resolveServerUrl};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { OperationInfo } from '../../../types/openapi.js';
|
|
2
|
-
import type { ApiDocsOptions } from '../../../types/options.js';
|
|
2
|
+
import type { ApiDocsOptions, RawApiDocsOptions } from '../../../types/options.js';
|
|
3
3
|
import type { StoreContext } from '../../../types/store.js';
|
|
4
4
|
import type { CodeSampleSource } from '../source.js';
|
|
5
|
+
import type { ReplayNormalizedOpenAPIOperation } from './replay-types.js';
|
|
5
6
|
import type { OpenAPIDefinition } from '../../../types/openapi.js';
|
|
6
7
|
/** Hook to apply adapter-time `configure()` results to a fallback-built `OperationInfo`. */
|
|
7
8
|
export type ApplyConfigureToOperationInfo = (operationInfo: OperationInfo, storeCtx: StoreContext, doc: OpenAPIDefinition) => void;
|
|
@@ -10,3 +11,9 @@ export type ApplyConfigureToOperationInfo = (operationInfo: OperationInfo, store
|
|
|
10
11
|
* Fallback path used by the Replay overlay when the prebuilt source map misses.
|
|
11
12
|
*/
|
|
12
13
|
export declare function buildCodeSampleSourceFromDocument(pathName: string, method: string, doc: OpenAPIDefinition, options: ApiDocsOptions, applyConfigure?: ApplyConfigureToOperationInfo): CodeSampleSource | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Build a Replay `convertOperationToReplayValue` for hosts that have no api-docs store —
|
|
16
|
+
* the standalone Replay desktop app. Resolvers are read back from the store context that
|
|
17
|
+
* {@link buildCodeSampleSourceFromDocument} just populated, so schema and example ids match.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createDocumentReplayConverter(rawOptions: RawApiDocsOptions): (path: string, method: string, document: unknown) => ReplayNormalizedOpenAPIOperation | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createStoreContext as
|
|
1
|
+
import{createStoreContext as O,toRecord as b}from"../../../adapters/helpers.js";import{populateOpenApiStore as R}from"../../../adapters/openapi/store.js";import{buildCodeSampleSource as v}from"../../../adapters/openapi/build-code-sample-source.js";import{normalizeOptions as $}from"../../../options/normalizeOptions.js";import{createCodeSampleResolvers as q}from"../resolvers.js";import{toReplayOperation as j}from"./replay-adapter.js";function w(t,e){if(!t.length&&!e?.length||!t.length)return e;if(!e?.length)return t;const n=new Set(e.map(i=>{const o=i;return`${o.in}:${o.name}`})),s=[...e];for(const i of t){const o=i,r=`${o.in}:${o.name}`;n.has(r)||s.push(i)}return s}let y=null;function C(t,e){if(y?.doc===t)return y.ctx;const n=O(b(t));return R(t,n,e),y={doc:t,ctx:n},n}function I(t,e,n,s,i){const o=n.paths;if(!o||typeof o!="object")return;const r=o[t];if(!r||typeof r!="object")return;const u=e.toLowerCase(),f=r;let p=u,c=f[u],d=!1;if(!c&&u==="query"&&f["x-query"]&&(c=f["x-query"],p="x-query"),!c&&u!=="query"&&r.additionalOperations){const l=r.additionalOperations,m=e in l?e:Object.keys(l).find(g=>g.toLowerCase()===u);m&&(c=l[m],p=m,d=!0)}if(!c||typeof c!="object")return;const a=c,S=r.parameters??[],h={pointer:d?`/paths/${t}/additionalOperations/${p}`:`/paths/${t}/${p}`,pathName:t,httpVerb:e.toUpperCase(),operationId:a.operationId,summary:typeof a.summary=="string"?a.summary:void 0,isWebhook:!1,isAdditionalOperation:d,tags:[],parameters:w(S,a.parameters),requestBody:a.requestBody,servers:a.servers??r.servers,security:a.security},x=C(n,s);return i?.(h,x,n),v(h,x,s.ignoreNamedSchemas,void 0,void 0,s)}function F(t){const e=$(t);return(n,s,i)=>{if(!i||typeof i!="object")return;const o=i;try{const r=I(n,s,o,e);if(!r)return;const u=C(o,e);return j(r,q(u.schemaStore,u.exampleStore,e))}catch(r){console.error("[Replay] createDocumentReplayConverter error:",r);return}}}export{I as buildCodeSampleSourceFromDocument,F as createDocumentReplayConverter};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { buildCodeSampleSourceFromDocument } from './from-openapi-document.js';
|
|
1
|
+
export { buildCodeSampleSourceFromDocument, createDocumentReplayConverter, } from './from-openapi-document.js';
|
|
2
2
|
export { REPLAY_TRY_IT_LOADING_STATE, type ReplayTryItLoadingState, } from '../constants/try-it-loading-state.js';
|
|
3
3
|
export { createReplayOverlayConverter } from './overlay-converter.js';
|
|
4
4
|
export { createReplayConverter, toReplayOperation } from './replay-adapter.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{buildCodeSampleSourceFromDocument as o}from"./from-openapi-document.js";import{REPLAY_TRY_IT_LOADING_STATE as
|
|
1
|
+
import{buildCodeSampleSourceFromDocument as o,createDocumentReplayConverter as a}from"./from-openapi-document.js";import{REPLAY_TRY_IT_LOADING_STATE as t}from"../constants/try-it-loading-state.js";import{createReplayOverlayConverter as l}from"./overlay-converter.js";import{createReplayConverter as R,toReplayOperation as f}from"./replay-adapter.js";import{handleReplayParamChange as y}from"./replay-handler.js";import{pickRuntimeConfigureRequestValues as c}from"./merge-configure-into-source.js";import{ReplayCodeSampleHTTPSnippet as T,replayHarToCodeSampleHar as i}from"./har-to-code-sample-har.js";export{t as REPLAY_TRY_IT_LOADING_STATE,T as ReplayCodeSampleHTTPSnippet,o as buildCodeSampleSourceFromDocument,a as createDocumentReplayConverter,R as createReplayConverter,l as createReplayOverlayConverter,y as handleReplayParamChange,c as pickRuntimeConfigureRequestValues,i as replayHarToCodeSampleHar,f as toReplayOperation};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { OpenAPIDefinition
|
|
1
|
+
import type { OpenAPIDefinition } from '../../../types/openapi.js';
|
|
2
2
|
import type { MockServerOptions } from '../../../adapters/openapi/utils/merge-mock-server.js';
|
|
3
|
-
export declare function buildServerEnvValues(servers: OpenAPIServer[]): Record<string, Record<string, string>>;
|
|
4
3
|
export declare function buildReplayPredefinedEnvValues(definition: OpenAPIDefinition, mockServer: MockServerOptions): Record<string, Record<string, string>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{mergeInMockServer as
|
|
1
|
+
import{mergeInMockServer as t}from"../../../adapters/openapi/utils/merge-mock-server.js";import{buildServerEnvValues as i}from"../server-env.js";function f(e,r){const n=t((e.servers??[]).filter(o=>typeof o?.url=="string"),r);return i(n)}export{f as buildReplayPredefinedEnvValues};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { OpenAPIServer } from '../../types/openapi.js';
|
|
2
|
+
/** Seeds one environment per global server so a saved environment name can resolve to a server in a fresh session. */
|
|
3
|
+
export declare function buildServerEnvValues(servers: OpenAPIServer[]): Record<string, Record<string, string>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{normalizeServers as o}from"./normalize-servers.js";import{getServerEnvName as m}from"../../utils/environments.js";function f(r){const t=o(void 0,r);return Object.fromEntries(t.map(e=>[String(m(e)),{server:e.url,...Object.fromEntries(Object.entries(e.variables??{}).map(([n,i])=>[n,i.default||""]))}]))}export{f as buildServerEnvValues};
|
|
@@ -96,11 +96,11 @@ export type CodeSampleSource = {
|
|
|
96
96
|
/** Raw pointer into the spec (for deep linking) */
|
|
97
97
|
pointer?: string;
|
|
98
98
|
/** Docs route slug of the operation page, relative to the routing base path
|
|
99
|
-
* (e.g. `operations/getmuseumhours`) —
|
|
99
|
+
* (e.g. `operations/getmuseumhours`) — lets hosts link back to the description */
|
|
100
100
|
href?: string;
|
|
101
|
-
/** OpenAPI `operationId` — should match the loaded spec so
|
|
101
|
+
/** OpenAPI `operationId` — should match the loaded spec so hosts can resolve the operation */
|
|
102
102
|
openApiOperationId?: string;
|
|
103
|
-
/** OpenAPI operation `summary` —
|
|
103
|
+
/** OpenAPI operation `summary` — the human-readable operation name */
|
|
104
104
|
summary?: string;
|
|
105
105
|
/** OpenAPI `security` array (AND-groups) for multi-scheme UI selection */
|
|
106
106
|
securityGroups?: Array<Record<string, string[]>>;
|
|
@@ -10,5 +10,6 @@ export type LicenseInfo = {
|
|
|
10
10
|
cryptoMissing?: boolean;
|
|
11
11
|
};
|
|
12
12
|
export declare function isHostAllowed(hostname: string, hosts: string[] | boolean | undefined): boolean;
|
|
13
|
+
export declare function isLicenseBypassed(): boolean;
|
|
13
14
|
export declare function parseLicense(key?: string): Promise<LicenseInfo>;
|
|
14
15
|
export default parseLicense;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const a="MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMHjNir5fXx/ZXoaEeXQ5XyxbNJ4YJYczoCRdSkL6NLzw1FHnng5Vfcgk5+bvox9QRYRbuk84mA4f2NhywDbXKECAwEAAQ==",o=typeof window<"u"&&(window.crypto||window.msCrypto)||void 0;function u(e){return"then"in e?e:new Promise(t=>{e.oncomplete=n=>{t(n.target.result)}})}function f(e){const t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let i=0,r=e.length;i<r;i++)n[i]=e.charCodeAt(i);return t}function
|
|
1
|
+
const a="MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMHjNir5fXx/ZXoaEeXQ5XyxbNJ4YJYczoCRdSkL6NLzw1FHnng5Vfcgk5+bvox9QRYRbuk84mA4f2NhywDbXKECAwEAAQ==",o=typeof window<"u"&&(window.crypto||window.msCrypto)||void 0;function u(e){return"then"in e?e:new Promise(t=>{e.oncomplete=n=>{t(n.target.result)}})}function f(e){const t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let i=0,r=e.length;i<r;i++)n[i]=e.charCodeAt(i);return t}function c(e){if(typeof TextEncoder<"u")return new TextEncoder().encode(e);const t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);return n}function l(){const e=f(atob(typeof REDOCLY_PUBLIC_KEY<"u"?REDOCLY_PUBLIC_KEY:a));return u(o.subtle.importKey("spki",e,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!0,["verify"]))}async function s(e,t){return u(o.subtle.verify({name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},await l(),f(atob(t)),c(e)))}function d(e,t){return t===!0?!0:Array.isArray(t)&&typeof window<"u"?e==="localhost"||e==="127.0.0.1"||e.endsWith(".localhost")||t.find(n=>n===e||e.endsWith("."+n))?!0:!!t.find(n=>{if(n.indexOf("*")!==n.lastIndexOf("*"))return!1;const[i,r]=n.split("*");return!!r&&e.startsWith(i)&&e.endsWith(r)&&r.split(".").length>2}):!1}function p(){return process.env.REDOCLY_FIRST_PARTY==="true"||process.env.NODE_ENV==="development"}async function w(e){if(p())return{valid:!0,allowed:!0};const t=window.location.hostname;if(!e)return t==="localhost"||t==="127.0.0.1"||t.endsWith(".localhost")?{local:!0}:{};const[n,i]=e.split(".");let r;try{if(!await s(atob(n),i))return{valid:!1};r=JSON.parse(atob(n))}catch{return{valid:!1,cryptoMissing:!0}}return r.valid=!0,(!r.e||Date.now()/1e3>r.e)&&(r.expired=!0),r.allowed=d(t,r.h),r}var y=w;export{y as default,d as isHostAllowed,p as isLicenseBypassed,w as parseLicense};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import*as B from"openapi-sampler";import{createStoreContext as I,resolveContent as C,resolveRef as h,toRecord as u}from"../../adapters/helpers.js";import{populateOpenApiStore as M}from"../../adapters/openapi/store.js";import{buildCodeSampleSource as N}from"../../adapters/openapi/build-code-sample-source.js";import{resolveOpenApiExampleValue as w}from"../../adapters/openapi/resolve-openapi-example-value.js";import{JsonPointer as b}from"../../adapters/openapi/utils/JsonPointer.js";import{createCodeSampleResolvers as A}from"../code-samples/resolvers.js";import{buildCodeSampleHAR as P}from"../code-samples/builder.js";import{tryGenerateCodeSample as T}from"../code-samples/generators/index.js";import{convertSampleToString as E}from"../code-samples/convertSampleToString.js";import{encodeExampleForMediaType as K,isSampleableMediaType as D,isSequentialMediaType as V,langFromMime as W}from"../../utils/media-type.js";import{getGeneratorKey as $,getLangKey as g}from"../../utils/languages.js";import{getServerEnvName as q}from"../../utils/environments.js";import{isOperationName as R}from"../../utils/http-methods.js";import{isStatusCode as F}from"../../utils/status-code.js";let v=null;function G(t,e){const n=e.ignoreNamedSchemas,o=n?[...n].sort().join(`
|
|
2
|
-
`):"";if(v?.doc===t&&v.optionsKey===o)return v.ctx;const r=I(u(t));return M(t,r,e),v={doc:t,optionsKey:o,ctx:r},r}function L(t,e){const n=t.paths;if(!(!n||typeof n!="object")){for(const[o,r]of Object.entries(n))if(!(!r||typeof r!="object"))for(const[s,i]of Object.entries(r)){if(!R(s)||!i||typeof i!="object")continue;const a=i;if(a.operationId===e)return{pathName:o,method:s,operation:a,pointer:b.compile(["paths",o,s])}}}}function U(t,e){const n=b.parse(e),o=n.indexOf("paths"),r=o>=0?n[o+1]:void 0,s=o>=0?n[o+2]:void 0;if(!r||!s||!R(s))return;const a=t.paths?.[r]?.[s];if(!(!a||typeof a!="object"))return{pathName:r,method:s,operation:a,pointer:b.compile(["paths",r,s])}}function H(t,{operationId:e,pointer:n}){if(e)return L(t,e);if(n)return U(t,n)}function ue(t,e,n){const o=H(t,n);if(!o)return;const{pathName:r,method:s,operation:i,pointer:a}=o,p=t.paths?.[r]??{},l={pointer:a,pathName:r,httpVerb:s.toUpperCase(),operationId:i.operationId,summary:typeof i.summary=="string"?i.summary:void 0,isWebhook:!1,isAdditionalOperation:!1,tags:i.tags??[],parameters:J(t,p.parameters,i.parameters),requestBody:i.requestBody,responses:i.responses,servers:i.servers??p.servers??t.servers,security:i.security},m=G(t,e),d=N(l,m,e,e
|
|
2
|
+
`):"";if(v?.doc===t&&v.optionsKey===o)return v.ctx;const r=I(u(t));return M(t,r,e),v={doc:t,optionsKey:o,ctx:r},r}function L(t,e){const n=t.paths;if(!(!n||typeof n!="object")){for(const[o,r]of Object.entries(n))if(!(!r||typeof r!="object"))for(const[s,i]of Object.entries(r)){if(!R(s)||!i||typeof i!="object")continue;const a=i;if(a.operationId===e)return{pathName:o,method:s,operation:a,pointer:b.compile(["paths",o,s])}}}}function U(t,e){const n=b.parse(e),o=n.indexOf("paths"),r=o>=0?n[o+1]:void 0,s=o>=0?n[o+2]:void 0;if(!r||!s||!R(s))return;const a=t.paths?.[r]?.[s];if(!(!a||typeof a!="object"))return{pathName:r,method:s,operation:a,pointer:b.compile(["paths",r,s])}}function H(t,{operationId:e,pointer:n}){if(e)return L(t,e);if(n)return U(t,n)}function ue(t,e,n){const o=H(t,n);if(!o)return;const{pathName:r,method:s,operation:i,pointer:a}=o,p=t.paths?.[r]??{},l={pointer:a,pathName:r,httpVerb:s.toUpperCase(),operationId:i.operationId,summary:typeof i.summary=="string"?i.summary:void 0,isWebhook:!1,isAdditionalOperation:!1,tags:i.tags??[],parameters:J(t,p.parameters,i.parameters),requestBody:i.requestBody,responses:i.responses,servers:i.servers??p.servers??t.servers,security:i.security},m=G(t,e),d=N(l,m,e.ignoreNamedSchemas,void 0,void 0,e),O=i["x-codeSamples"];O?.length&&(d.definitionSamples=O.map(({lang:S,label:c,source:f})=>({lang:S,label:c,source:f})));const y=A(m.schemaStore,m.exampleStore,e);return{doc:t,options:e,operation:i,pathName:r,method:s,source:d,storeCtx:m,resolvers:y}}function J(t,e,n){if(!e?.length)return n;if(!n?.length)return e;const o=u(t),r=a=>{const p=h(o,a)??a;return`${p.in}:${p.name}`},s=new Set(n.map(r));return[...e.filter(a=>!s.has(r(a))),...n]}function z(t,{environment:e,environments:n}){let o=t;if(e){const r=o.filter(s=>String(q(s))===e||s.url===e);o=r.length?r:o}return n&&(o=o.map(r=>{const s=n[String(q(r))]?.server;return s?{...r,url:s}:r})),o}function le(t,e={}){const{source:n,options:o}=t,r=o.codeSamples?.languages??[],s=new Map(r.map((c,f)=>[c.key,f])),i=z(n.servers,e),a=e.environment&&e.environments?.[e.environment]||{},p=(n.definitionSamples??[]).filter(c=>s.has(g(c))&&typeof c.source=="string"),l=new Set(p.map(g)),m={serverUrl:i[0]?.url??a.server,mediaType:e.mimeType,exampleName:e.exampleKey,environment:a,requestValues:e.parameters,replayBody:e.requestBody},d={skipOptionalParameters:o.codeSamples?.skipOptionalParameters,withOAuth2Call:o.codeSamples?.withOAuth2Call,generatedPayloadSamplesMaxDepth:o.generatedSamplesMaxDepth},y=n.operationType==="webhook"?void 0:P({...n,servers:i},m,d,t.resolvers),S=[];if(y)for(const c of r){const f=$(c);if(f==="payload"||l.has(c.key))continue;const x=T(f,y,c.options),k=x.kind==="ok"?x.source:x.kind==="unsupported-language"?"Language is not supported.":"Failed to generate code sample.";k&&S.push({lang:c.lang,label:c.label,source:k})}return[...p,...S].filter(c=>!!c.source).sort((c,f)=>(s.get(g(c))??9999)-(s.get(g(f))??9999))}function Q(t,e,n){if(e.examples&&typeof e.examples=="object"){const o=Object.keys(e.examples);if(o.length){const r=o.length===1?o[0]:n&&o.includes(n)?n:o[0],s=h(u(t),e.examples[r])??e.examples[r],i=w(s);if(i!==void 0)return i}}if(e.example!==void 0)return e.example}function X(t,e,n,o){const r=e.schema??e.itemSchema;if(!r)return;const s=h(u(t),r)??r;try{return B.sample(s,{skipReadOnly:o==="request",skipWriteOnly:o==="response",quiet:!0,skipNonRequired:n.onlyRequiredInSamples,maxSampleDepth:n.generatedSamplesMaxDepth},u(t))}catch{return}}function j(t,e,n,o,r,s){const i=[];if(!e)return i;for(const[a,p]of Object.entries(e)){if(!p||typeof p!="object"||s&&a!==s)continue;let l=Q(t.doc,p,n);const m=l===void 0&&D(a);if(m&&(l=X(t.doc,p,t.options,r)),l===void 0)continue;const d=E(l,a,p.schema??p.itemSchema,m&&V(a));d!==void 0&&i.push({lang:W(a),title:`${o} ${a}`,source:K(d,a,p.encoding)})}return i}function fe(t,{exampleKey:e,mimeType:n,titlePrefix:o="Payload"}={}){const r=h(u(t.doc),t.operation.requestBody)??t.operation.requestBody,s=C(u(t.doc),r);return j(t,s,e,o,"request",n)}function de(t,{exampleKey:e}={}){const n=t.operation.responses;if(!n||typeof n!="object")return[];const o=[];for(const[r,s]of Object.entries(n)){if(!F(r))continue;const i=h(u(t.doc),s)??s,a=C(u(t.doc),i);o.push(...j(t,a,e,r,"response"))}return o}export{le as buildCodeSamples,fe as getRequestBodySamples,de as getResponseSamples,ue as resolveOperationSampleContext};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ApiItem, SchemaEntry } from '../../types/store.js';
|
|
2
|
+
import type { SearchDocument } from './types.js';
|
|
3
|
+
/** Builds flat `SearchDocument`s from `ApiItem`s (OpenAPI, AsyncAPI, GraphQL). */
|
|
4
|
+
export declare class ApiDocsSearchIndexer {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(basePath: string, schemaStore?: Record<string, SchemaEntry>, document?: Record<string, unknown>);
|
|
7
|
+
addItem(item: ApiItem): void;
|
|
8
|
+
getResult(): SearchDocument[];
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{REDOCLY_TEAMS_RBAC as f}from"@redocly/config";import{nodeTypes as P,contentType as S,schemaKind as E}from"../../types/common.js";import{extractFullText as y}from"../../adapters/utils/markdoc.js";import{appendArraySuffix as D,appendVariantSuffix as g,buildGraphqlSuffix as O,buildOpenApiSectionSuffix as j,makeDeepLink as I}from"../../utils/deep-link.js";const V=10,R="message payload",w="message headers",x=200;function _(k){return k.length>x?`${k.slice(0,x)}\u2026`:k}class G{#a=[];#r;#i;#s;#o;constructor(e,n,t){this.#r=e,this.#i=n,this.#s=t}addItem(e){if(!(!e.link||!e.content))try{switch(e.content.contentType){case S.OVERVIEW:this.#d(e,this.#r);break;case S.GROUP:case S.ITEM:this.#d(e,e.link);break}}catch(n){console.error(`Cannot add item to api-docs search indexer [${e.label}, ${e.link}]:`,n.message)}}#d(e,n){if(!e.content)return;const t=n.startsWith(this.#r+"/")?n.slice(this.#r.length+1):n.split("/").slice(-2).join("/"),r=e.content.children,i=this.#l(r),o=this.#y(r,t),s=e,a={id:n,url:n,title:e.label??"",text:i,path:[],deprecated:e.content.meta?.deprecated,..."httpVerb"in e&&e.httpVerb?{httpMethod:e.httpVerb}:{},..."httpPath"in e&&e.httpPath?{httpPath:e.httpPath}:{},..."badges"in e&&Array.isArray(e.badges)&&e.badges.length?{badges:e.badges}:{},..."isAdditionalOperation"in e&&e.isAdditionalOperation?{isAdditionalOperation:!0}:{},[f]:s[f],...o.length&&{parameters:o}};this.#a.push(a)}#l(e){const n=[],t=r=>{for(const i of r)if(i.nodeType===P.MARKDOC){const o=i;if(this.#h(o.content))continue;const s=y(o.content);s&&n.push(s)}else(i.nodeType===P.CONTAINER||i.nodeType===P.OVERVIEW_SECTION_WRAPPER)&&t(i.children)};return t(e),n.join(" ").trim()}#h(e){let n=!1,t=!1;const r=o=>{o.type==="code"&&o.attributes?.content?n=!0:o.type==="text"&&o.attributes?.content&&(t=!0);for(const s of o.children??[])r(s)},i=Array.isArray(e)?e:[e];for(const o of i)r(o);return n&&!t}#y(e,n){const t={},r=new Set,i=o=>{for(const s of o)if(s.nodeType===P.ITEM){const a=s;if(a[f])continue;this.#m(a,t,n),this.#S(a,t,r,n)}else if(s.nodeType===P.CONTAINER){const a=s;if(a[f])continue;i(a.children)}else s.nodeType===P.OVERVIEW_SECTION_WRAPPER&&i(s.children)};return i(e),Object.values(t)}#m(e,n,t){if(e.parameters?.length)for(const r of e.parameters){if(r[f])continue;const i=this.#g(e.variant),o=this.#k(e.variant),s=r.description?y(r.description):"",a=this.#$(r.schemaId),d={name:r.name,description:s,place:i,mediaType:void 0,type:a,required:r.required??!1,deepLink:this.#c(t,"request",o,void 0,void 0,[r.name]),example:void 0,enum:void 0};n[this.#t(d)]=d}}#t(e){return[...Array.isArray(e.path)?e.path:[],e.name.toString()].join(".")+e.description+e.place}#c(e,n,t,r,i,o){if(!e)return"";const s=o.join("/"),a=[`t=${n}`];return t&&a.push(`in=${t}`),i&&a.push(`c=${i}`),r&&a.push(`ct=${r}`),s&&a.push(`path=${s}`),`/${e}#${e}/${a.join("&")}`.toLowerCase()}#P(e,n,t,r){if(!e)return"";let i="messages";n&&(i+=`&m=${n}`),i+=`&t=${t}`;const o=r.join("/");return o&&(i+=`&path=${o}`),`/${e}#${e}/${i}`.toLowerCase()}#k(e){switch(e){case"query":return"query";case"path":return"path";case"headers":return"header";case"cookies":return"cookie";default:return}}#g(e){switch(e){case"query":return"query parameters";case"path":return"path parameters";case"headers":return"header parameters";case"cookies":return"cookie parameters";case"parameters":return"channel parameters";default:return e?`${e} parameters`:"parameters"}}#$(e){const n=this.#i?.[e];if(!n||n.kind!==E.JSON_SCHEMA)return"unknown";const t=n.data,r=this.#p(t);return this.#f(r)}#f(e){return Array.isArray(e.type)?e.type.join(" | "):e.type?e.type:e.properties||e.additionalProperties?"object":e.items?"array":e.enum?"string":"any"}#S(e,n,t,r){const i=this.#A(e);if(e.graphqlSchema&&Array.isArray(e.graphqlSchema)){this.#I(e.graphqlSchema,i,n,e,r);return}const o=!!this.#i&&!!this.#s;o&&this.#O(e,i,n,t,r);for(const s of e.responses??[])s[f]||(this.#T(s,n,r),o&&this.#b(s,n,r));if(o)for(const s of e.messages??[])s[f]||this.#q(s,n,r)}#O(e,n,t,r,i){const o=n.startsWith("response");if(e.mediaTypeSchemas){const s=Object.entries(e.mediaTypeSchemas),a=s.find(([,d])=>!d[f]);if(a){const[d,c]=a;c.schemaId&&this.#n(c.schemaId,n,d,s.length>1,o,t,[],r,i)}}else e.schemaId&&this.#n(e.schemaId,n,void 0,!1,o,t,[],r,i)}#T(e,n,t){const r=e.description?y(e.description):"",o=[e.summary?y(e.summary):"",r].filter(Boolean).join(" ").trim();if(!o)return;const s={name:e.code,description:o,place:`response ${e.code}`,mediaType:void 0,type:"unknown",required:!1,deepLink:t?I(t,j("response",void 0,e.code)):void 0,example:void 0,enum:void 0};n[this.#t(s)]=s}#b(e,n,t){const r=`response ${e.code} fields`,i=new Set;if(e.mediaTypeContent){const o=Object.entries(e.mediaTypeContent),s=o.find(([,a])=>!a[f]);if(s){const[a,d]=s;d.schemaId&&this.#n(d.schemaId,r,a,o.length>1,!0,n,[],i,t)}}else e.schemaId&&this.#n(e.schemaId,r,e.mediaType,!1,!0,n,[],i,t)}#q(e,n,t){const r=e.description?y(e.description):"",i=e.summary??"",o={name:e.name,description:(r+i).trim(),place:"message",mediaType:void 0,type:"unknown",required:!1,example:void 0,enum:void 0};n[this.#t(o)]=o,this.#o=e.name;const s=new Set;e.schemaId&&this.#n(e.schemaId,R,e.contentType,!1,!1,n,[],s,t),e.headerSchemaId&&this.#n(e.headerSchemaId,w,void 0,!1,!1,n,[],s,t),this.#o=void 0}#A(e){switch(e.variant){case"body":return"request fields";case"responses":return"response fields";case"graphql-fields":return"fields";case"graphql-args":return"arguments";case"return-type":return"return type fields";default:return e.variant??"fields"}}#E(e){return e.variant!=="graphql-args"?e.graphqlTypeName:e.graphqlFieldName?e.graphqlFieldName:e.graphqlTypeName?`@${e.graphqlTypeName}`:void 0}#I(e,n,t,r,i){const o=r.variant==="graphql-args",s=this.#E(r),a=d=>i&&s?I(i,d):void 0;for(const d of e){const c=d.description?y(d.description):"",u=`${s}.${d.name}`,l={name:d.name,description:c,place:n,mediaType:void 0,path:[],type:d.type??"unknown",required:!1,deepLink:a(o?O({t:"argument",path:u,arg:d.name}):O({t:"field",path:u})),example:void 0,enum:void 0};if(t[this.#t(l)]=l,d.args?.length)for(const p of d.args){const m=p.description?y(p.description):"",h={name:p.name,description:m,place:"arguments",mediaType:void 0,path:[d.name],type:p.type??"unknown",required:!1,deepLink:a(O({t:"argument",path:`${u}.${p.name}`,arg:p.name})),example:void 0,enum:void 0};t[this.#t(h)]=h}}}#n(e,n,t,r,i,o,s,a,d=""){const c=this.#i?.[e];if(!c||c.kind!==E.JSON_SCHEMA||c[f])return;const u=c.data,l=r?t:void 0;this.#u(u,n,t,l,i,o,{path:s,linkPath:[...s],depth:0},a,d)}#R(e){const n=e.match(/^response (\d+)/);return n?n[1]:void 0}#p(e){if(e.allOf){const n={};for(const t of e.allOf){const r=t.$ref?this.#e(t.$ref):t;if(r){const i=n.properties,o=n.required;Object.assign(n,r),(i||r.properties)&&(n.properties={...i||{},...r.properties||{}}),(o||r.required)&&(n.required=[...o||[],...r.required||[]])}}return delete n.allOf,e.description&&(n.description=e.description),n}if(e.$ref){const n=this.#e(e.$ref);if(n){const t={...n};return e.description&&(t.description=e.description),t}}return e}#e(e){if(!e.startsWith("#/"))return;const n=e.slice(2).split("/");let t=this.#s;for(const r of n){if(t==null||typeof t!="object")return;t=t[r]}return t!=null&&typeof t=="object"?t:void 0}#u(e,n,t,r,i,o,s,a,d=""){if(s.depth>V||e[f])return;const c=(p,m)=>this.#u(p,n,t,r,i,o,m,a,d);if(e.$ref){this.#w(e.$ref,c,s,a);return}if(e.allOf){c(this.#x(e,a),s);return}const u=e.discriminator??e["x-discriminator"];if(u?.propertyName&&!s.inDiscriminatorVariant){this.#W(e,u,c,s);return}const l=e.oneOf??e.anyOf;if(l){this.#C(e,l,c,s,a);return}if(e.if&&(e.then||e.else)){this.#L(e,c,s);return}e.properties&&this.#D(e,c,{place:n,mediaType:t,deepLinkContentType:r,isResponse:i,paramsMap:o,frame:s,visited:a,slug:d}),this.#v(e,c,s,a)}#w(e,n,t,r){if(r.has(e))return;r.add(e);const i=this.#e(e);i&&n(i,t)}#x(e,n){const t={};for(const r of e.allOf??[]){let i=r;if(r.$ref){if(n.has(r.$ref))continue;n.add(r.$ref),i=this.#e(r.$ref)}if(i){const o=t.properties,s=t.required;Object.assign(t,i),(o||i.properties)&&(t.properties={...o||{},...i.properties||{}}),(s||i.required)&&(t.required=[...s||[],...i.required||[]])}}return delete t.allOf,t}#C(e,n,t,r,i){e.properties&&t({...e,oneOf:void 0,anyOf:void 0},{...r,linkPath:g(r.linkPath,"&oneof=0")}),n.forEach((o,s)=>{if(o.$ref){if(i.has(o.$ref))return;i.add(o.$ref)}const a=o.$ref?this.#e(o.$ref):o;a&&t(a,{...r,linkPath:g(r.linkPath,`&oneof=${s}`),depth:r.depth+1})})}#L(e,n,t){const{if:r,then:i,else:o,...s}=e;[{allOf:[s,i??{},r??{}]},{allOf:[s,o??{}]}].forEach((d,c)=>{n(d,{...t,linkPath:g(t.linkPath,`&oneof=${c}`),depth:t.depth+1})})}#D(e,n,t){const{isResponse:r,paramsMap:i,frame:o,visited:s}=t,a=e.required||[],d=this.#R(t.place),c=r?"response":"request",u=t.place===R?"payload":t.place===w?"headers":void 0,l={requiredList:a,responseCode:d,type:c,asyncSubsection:u,...t};for(const[p,m]of Object.entries(e.properties??{})){if(m[f])continue;const h=this.#j(m,s);if(!h)continue;const C=this.#V(h,s),$=this.#p(h);if(!this.#_(h,$,r))continue;const T=p===o.discriminatorPropertyName,L=[...o.path,p],b=this.#F(p,T,o),q=this.#M(p,h,$,b,l),A=this.#t(q);i[A]==null&&(i[A]=q,!C&&!T&&n($,{path:L,linkPath:b,depth:o.depth+1}))}}#j(e,n){if(!e.$ref)return e;if(!n.has(e.$ref))return n.add(e.$ref),this.#e(e.$ref)}#V(e,n){if(!e.allOf)return!1;let t=!1;for(const r of e.allOf)r.$ref?n.has(r.$ref)||(n.add(r.$ref),t=!0):t=!0;return!t}#_(e,n,t){return!(e[f]||n[f]||n.readOnly&&!t||n.writeOnly&&t||e.additionalProperties!==void 0&&!e.properties)}#F(e,n,t){return[...n&&t.discriminatorLinkPath?t.discriminatorLinkPath:t.linkPath,e]}#M(e,n,t,r,i){const o=n.description??t.description,s=o?y(o):"",a=n.example??t.example,d=a!==void 0?_(typeof a=="string"?a:JSON.stringify(a)):void 0,c=Array.isArray(t.enum)&&t.enum.length?t.enum:void 0;return{name:e,description:s,place:i.place,mediaType:i.mediaType,path:i.frame.path,type:this.#f(t),required:i.requiredList.includes(e),deepLink:i.asyncSubsection?this.#P(i.slug,this.#o,i.asyncSubsection,r):this.#c(i.slug,i.type,void 0,i.deepLinkContentType,i.responseCode,r),example:d,enum:c}}#v(e,n,t,r){if(!e.items||typeof e.items!="object"||Array.isArray(e.items))return;if(e.items.$ref){if(r.has(e.items.$ref))return;r.add(e.items.$ref)}const i=e.items.$ref?this.#e(e.items.$ref):e.items;i&&n(i,{...t,linkPath:D(t.linkPath),depth:t.depth+1})}#W(e,n,t,r){const i=this.#G(e,n),o=s=>({...r,linkPath:g(r.linkPath,`&d=${s}`),inDiscriminatorVariant:!0,discriminatorPropertyName:n.propertyName,discriminatorLinkPath:r.linkPath});e.properties&&t({...e,discriminator:void 0,"x-discriminator":void 0,oneOf:void 0,anyOf:void 0},i.length?o(0):r),i.forEach((s,a)=>{t(s,{...o(a),depth:r.depth+1})})}#G(e,n){const t=e.oneOf??e.anyOf??[],r=Object.values(n.mapping??{});if(r.length===0)return t;const i=s=>t.find(a=>a.$ref===s||a["x-original-ref"]===s)??this.#e(s)??{},o=r.filter(s=>s!==n.defaultMapping).map(i);return n.defaultMapping&&o.push(i(n.defaultMapping)),o}getResult(){return this.#a}}export{G as ApiDocsSearchIndexer};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { OperationParameter, ParameterHighlight } from '@redocly/theme/core/openapi';
|
|
2
|
+
import type { ItemBadge } from '@redocly/config';
|
|
3
|
+
import type { REDOCLY_TEAMS_RBAC } from '@redocly/config';
|
|
4
|
+
export type SearchDocument = {
|
|
5
|
+
[REDOCLY_TEAMS_RBAC]?: Record<string, string>;
|
|
6
|
+
id: string;
|
|
7
|
+
url: string;
|
|
8
|
+
title: string | string[];
|
|
9
|
+
text: string | string[];
|
|
10
|
+
path?: string[];
|
|
11
|
+
httpMethod?: string;
|
|
12
|
+
httpPath?: string | string[];
|
|
13
|
+
isAdditionalOperation?: boolean;
|
|
14
|
+
deprecated?: boolean;
|
|
15
|
+
security?: string[];
|
|
16
|
+
parameters?: OperationParameter[];
|
|
17
|
+
badges?: ItemBadge[];
|
|
18
|
+
};
|
|
19
|
+
export type SearchItemData = {
|
|
20
|
+
document: SearchDocument;
|
|
21
|
+
highlight: Record<string, string> & {
|
|
22
|
+
parameters?: ParameterHighlight[];
|
|
23
|
+
path?: string[];
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type { OperationParameter, ParameterHighlight } from '@redocly/theme/core/openapi';
|
|
27
|
+
export type { ItemBadge } from '@redocly/config';
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SliceContentKind, SpecSliceScope } from './types.js';
|
|
2
|
+
export declare const ASSISTANT_LINK_BASES: {
|
|
3
|
+
readonly chatgpt: 'https://chatgpt.com';
|
|
4
|
+
readonly claude: 'https://claude.ai/new';
|
|
5
|
+
};
|
|
6
|
+
export declare const MAX_ASSISTANT_URL_LENGTH = 8000;
|
|
7
|
+
export declare function buildInlinePromptLink(baseUrl: string, content: string, contentKind?: SliceContentKind): string | undefined;
|
|
8
|
+
export declare function describeSliceScope(scope: SpecSliceScope): string | undefined;
|
|
9
|
+
export declare function buildFetchSpecPromptLink(baseUrl: string, specUrl: string, scope: SpecSliceScope): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const c={chatgpt:"https://chatgpt.com",claude:"https://claude.ai/new"},i=8e3,s={yaml:`Read the yaml and answer questions based on the content.
|
|
2
|
+
|
|
3
|
+
`,graphql:`Read the GraphQL SDL and answer questions based on the content.
|
|
4
|
+
|
|
5
|
+
`};function u(e,a,r="yaml"){const t=new URL(e);t.searchParams.set("q",`${s[r]}${a}`);const n=t.toString();return n.length<=i?n:void 0}function h(e){switch(e.kind){case"operation":return`the ${e.httpVerb.toUpperCase()} ${e.pathName} operation`;case"tag":return`the "${e.tagName}" operations`;case"schema":return`the ${e.name} schema`;case"channel":return`the "${e.channelId}" channel`;case"async-operation":return`the "${e.operationId}" operation`;case"graphql-operation":return`the ${e.name} ${e.operationType}`;case"graphql-type":return`the ${e.name} type`;case"graphql-directive":return`the @${e.name} directive`;case"graphql-group":return e.label?`the "${e.label}" section`:void 0;default:return}}function d(e,a,r){const t=h(r),n=t?`answer questions about ${t}`:"answer questions based on the content",o=new URL(e);return o.searchParams.set("q",`Read ${a} and ${n}.`),o.toString()}export{c as ASSISTANT_LINK_BASES,i as MAX_ASSISTANT_URL_LENGTH,d as buildFetchSpecPromptLink,u as buildInlinePromptLink,h as describeSliceScope};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SpecSliceScope } from './types.js';
|
|
2
|
+
export declare function scopeFromAsyncApiPointer(pointer: string): SpecSliceScope | undefined;
|
|
3
|
+
export declare function extractAsyncApiSlice(document: Record<string, unknown>, scope: SpecSliceScope): {
|
|
4
|
+
document: Record<string, unknown>;
|
|
5
|
+
} | undefined;
|