@redocly/openapi-docs 3.12.0-rc.7 → 3.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/redocly-openapi-docs.min.js +2153 -1963
- package/lib/components/ApiInfo/ApiInfo.js +29 -1
- package/lib/components/ApiInfo/Metadata.js +29 -1
- package/lib/components/ApiInfo/index.js +2 -1
- package/lib/components/ApiInfo/styled.js +17 -8
- package/lib/components/CallbackSamples/CallbackSamples.js +25 -4
- package/lib/components/CallbackSamples/index.js +2 -1
- package/lib/components/Callbacks/CallbackDetails.js +17 -3
- package/lib/components/Callbacks/CallbackOperation.js +24 -3
- package/lib/components/Callbacks/CallbackSummary.js +19 -3
- package/lib/components/Callbacks/CallbacksList.js +16 -1
- package/lib/components/Callbacks/index.js +4 -1
- package/lib/components/Callbacks/styled.js +6 -3
- package/lib/components/Content/Content.js +10 -1
- package/lib/components/Content/index.js +2 -1
- package/lib/components/Content/useAutoScroll.js +50 -1
- package/lib/components/ContentItem/ContentItem.js +31 -1
- package/lib/components/ContentItem/index.js +2 -1
- package/lib/components/ContentItem/useIsExpanded.js +33 -1
- package/lib/components/ContentItems/ContentItems.js +19 -1
- package/lib/components/ContentItems/Items.js +13 -1
- package/lib/components/ContentItems/VirtualList.js +35 -1
- package/lib/components/ContentItems/helpers.js +49 -1
- package/lib/components/ContentItems/index.js +2 -1
- package/lib/components/ContentItems/useScrollOnRender.js +26 -1
- package/lib/components/Discriminator/Discriminator.js +27 -2
- package/lib/components/Discriminator/index.js +2 -1
- package/lib/components/Download/DownloadSpecification.js +46 -4
- package/lib/components/Download/index.js +2 -1
- package/lib/components/Download/types.js +2 -0
- package/lib/components/Download/useDownloadInfo.js +42 -1
- package/lib/components/ErrorBoundary/ErrorBoundary.js +22 -2
- package/lib/components/ErrorBoundary/index.js +2 -1
- package/lib/components/ExpandAllButton/ExpandAllButton.js +31 -2
- package/lib/components/ExpandAllButton/index.js +2 -1
- package/lib/components/ExternalDocumentation/ExternalDocumentation.js +18 -4
- package/lib/components/ExternalDocumentation/index.js +2 -1
- package/lib/components/Language/LanguageDropdown.js +21 -1
- package/lib/components/Language/LanguageItem.js +33 -1
- package/lib/components/Language/LanguageList.js +93 -1
- package/lib/components/Language/_tests_/LanguageDropdown.test.js +23 -1
- package/lib/components/Language/constants.js +3 -1
- package/lib/components/Language/index.js +4 -1
- package/lib/components/Language/styled.js +29 -15
- package/lib/components/Markdown/Markdown.js +64 -1
- package/lib/components/Markdown/index.js +3 -1
- package/lib/components/Markdown/types.js +2 -0
- package/lib/components/MediaTypeSwitch/MediaTypesSwitch.js +51 -1
- package/lib/components/MediaTypeSwitch/index.js +2 -1
- package/lib/components/OperationItem/Description.d.ts +1 -4
- package/lib/components/OperationItem/Description.js +9 -1
- package/lib/components/OperationItem/OperationItem.js +70 -5
- package/lib/components/OperationItem/_tests_/OperationItem.test.js +70 -1
- package/lib/components/OperationItem/_tests_/__mocks__/mock-intersection-observer.js +40 -1
- package/lib/components/OperationItem/index.js +2 -1
- package/lib/components/OperationItem/types.js +2 -0
- package/lib/components/Overlay.js +48 -3
- package/lib/components/Overview/Overview.js +20 -1
- package/lib/components/Overview/index.js +2 -1
- package/lib/components/PageFooter/PageFooter.js +19 -1
- package/lib/components/PageFooter/index.js +2 -1
- package/lib/components/Panel/ResponsePanel.js +12 -6
- package/lib/components/Panel/Trigger.js +4 -2
- package/lib/components/Panel/index.js +3 -1
- package/lib/components/PanelItem/PanelItem.js +6 -1
- package/lib/components/PanelItem/index.js +3 -1
- package/lib/components/PanelItem/styled.js +20 -10
- package/lib/components/PayloadSamples/Example.js +6 -1
- package/lib/components/PayloadSamples/ExampleValue.js +30 -1
- package/lib/components/PayloadSamples/MediaTypeSamples.js +36 -2
- package/lib/components/PayloadSamples/PayloadSamples.js +26 -1
- package/lib/components/PayloadSamples/index.js +7 -1
- package/lib/components/PayloadSamples/styled.js +9 -4
- package/lib/components/PayloadSamples/types.js +2 -0
- package/lib/components/PropertyDetails/DescriptionEnums.js +19 -3
- package/lib/components/PropertyDetails/EnumValues.js +37 -1
- package/lib/components/PropertyDetails/Examples.js +26 -1
- package/lib/components/PropertyDetails/Extensions.js +17 -2
- package/lib/components/PropertyDetails/FieldDetail.js +15 -2
- package/lib/components/PropertyDetails/FieldDetails.js +51 -6
- package/lib/components/PropertyDetails/Pattern.js +21 -1
- package/lib/components/PropertyDetails/PlusCircleIcon.js +10 -4
- package/lib/components/PropertyDetails/PropertyDetails.js +22 -5
- package/lib/components/PropertyDetails/SchemaTypeInfo.js +10 -2
- package/lib/components/PropertyDetails/SimpleEnums.js +13 -2
- package/lib/components/PropertyDetails/cycleColorsByLevel.js +18 -1
- package/lib/components/PropertyDetails/index.js +4 -1
- package/lib/components/PropertyDetails/styled.js +15 -7
- package/lib/components/PropertyDetails/types.js +2 -0
- package/lib/components/RedoclyOpenAPIDocs/Providers.js +114 -1
- package/lib/components/RedoclyOpenAPIDocs/RedoclyOpenAPIDocs.js +57 -1
- package/lib/components/RedoclyOpenAPIDocs/RedoclyOpenAPIDocsStandalone.js +86 -1
- package/lib/components/RedoclyOpenAPIDocs/index.js +5 -1
- package/lib/components/RedoclyOpenAPIDocs/styled.js +4 -2
- package/lib/components/RedoclyOpenAPIDocs/types.js +2 -0
- package/lib/components/RedoclyOpenAPIDocs/utils.js +33 -1
- package/lib/components/RenderHook/RenderHook.js +17 -1
- package/lib/components/RenderHook/index.js +2 -1
- package/lib/components/Replay/EmbeddedReplay.js +41 -3
- package/lib/components/Replay/Replay.js +99 -1
- package/lib/components/Replay/index.js +3 -1
- package/lib/components/Replay/utils.js +208 -1
- package/lib/components/Request/RequestDetails.js +33 -2
- package/lib/components/Request/types.js +2 -0
- package/lib/components/RequestParameters/Body.js +8 -1
- package/lib/components/RequestParameters/ParametersGroup.js +19 -4
- package/lib/components/RequestParameters/RequestParameters.js +40 -1
- package/lib/components/RequestParameters/index.js +4 -1
- package/lib/components/RequestSamples/CodeSample.js +55 -2
- package/lib/components/RequestSamples/Example.js +37 -1
- package/lib/components/RequestSamples/RequestSamples.js +89 -5
- package/lib/components/RequestSamples/index.js +3 -1
- package/lib/components/RequestSamples/useCodeSamples.js +92 -1
- package/lib/components/ResponseSamples/ResponseSamples.js +47 -1
- package/lib/components/ResponseSamples/Summary.js +9 -1
- package/lib/components/ResponseSamples/index.js +2 -1
- package/lib/components/Responses/OperationResponseList.js +42 -2
- package/lib/components/Responses/ResponseDetails.js +18 -1
- package/lib/components/Responses/ResponseHeaders.js +15 -1
- package/lib/components/Responses/index.js +6 -1
- package/lib/components/Responses/styled.js +14 -6
- package/lib/components/Responses/types.js +2 -0
- package/lib/components/RightPanel/RightPanel.js +21 -1
- package/lib/components/RightPanel/index.js +2 -1
- package/lib/components/Samples/ExampleSwitch.js +33 -1
- package/lib/components/Samples/index.js +3 -1
- package/lib/components/Samples/use-example-key.js +12 -1
- package/lib/components/Schema/ArraySchema.js +45 -1
- package/lib/components/Schema/ObjectSchema.js +29 -1
- package/lib/components/Schema/OneOfSchema.js +47 -3
- package/lib/components/Schema/RecursiveSchema.js +10 -1
- package/lib/components/Schema/Schema.js +63 -2
- package/lib/components/Schema/SubSchema.js +20 -1
- package/lib/components/Schema/helpers.js +16 -1
- package/lib/components/Schema/index.js +5 -1
- package/lib/components/Schema/types.js +2 -0
- package/lib/components/Schema/useOneOfLocationIdx.js +11 -1
- package/lib/components/SchemaDefinition/SchemaDefinition.js +65 -2
- package/lib/components/SchemaDefinition/index.js +2 -1
- package/lib/components/SectionContent/SectionContent.js +49 -6
- package/lib/components/SectionContent/index.js +2 -1
- package/lib/components/SectionItem/SectionItem.js +14 -1
- package/lib/components/SectionItem/index.js +2 -1
- package/lib/components/Security/Divider.js +9 -2
- package/lib/components/Security/OAuthFlow.js +11 -1
- package/lib/components/Security/OAuthScopes.js +59 -9
- package/lib/components/Security/Security.js +15 -1
- package/lib/components/Security/SecurityButton.js +31 -7
- package/lib/components/Security/SecurityFlow.js +28 -4
- package/lib/components/Security/SecurityModal.js +34 -5
- package/lib/components/Security/SecuritySchemeItem.js +15 -4
- package/lib/components/Security/helper.js +16 -1
- package/lib/components/Security/index.js +11 -1
- package/lib/components/Security/styled.js +6 -3
- package/lib/components/SelectOrLabel/SelectOrLabel.js +12 -2
- package/lib/components/SelectOrLabel/index.js +2 -1
- package/lib/components/ServerList/ServerList.js +36 -10
- package/lib/components/ServerList/index.js +2 -1
- package/lib/components/ServerList/types.js +2 -0
- package/lib/components/ServerListDropdown/ServerListDropdown.js +54 -1
- package/lib/components/ServerListDropdown/index.js +2 -1
- package/lib/components/ServerListDropdown/styled.js +15 -6
- package/lib/components/SideMenu/SideMenu.js +13 -2
- package/lib/components/SideMenu/hooks/useMenuItems.js +110 -1
- package/lib/components/SideMenu/index.js +2 -1
- package/lib/components/SideMenu/types.js +2 -0
- package/lib/components/StickySidebar/SidebarActions.js +14 -2
- package/lib/components/StickySidebar/StickyResponsiveSidebar.js +37 -7
- package/lib/components/StickySidebar/index.js +2 -1
- package/lib/components/Tabs/Tabs.js +16 -5
- package/lib/components/Tabs/index.js +3 -1
- package/lib/components/Tabs/useTabsState.js +22 -1
- package/lib/components/TagItem/OperationNavigationItems.js +18 -4
- package/lib/components/TagItem/OperationsNavigation.js +46 -2
- package/lib/components/TagItem/TagItem.js +41 -8
- package/lib/components/TagItem/index.js +2 -1
- package/lib/components/TagItem/styled.js +5 -2
- package/lib/components/TagItem/types.js +2 -0
- package/lib/components/ViewNested/ViewNested.js +42 -9
- package/lib/components/ViewNested/index.js +2 -1
- package/lib/components/common/Badges.js +21 -5
- package/lib/components/common/BodyContent/BodyContent.js +31 -4
- package/lib/components/common/BodyContent/index.js +2 -1
- package/lib/components/common/ClearButton/ClearButton.js +5 -1
- package/lib/components/common/ClearButton/index.js +3 -1
- package/lib/components/common/ClearButton/styled.js +5 -2
- package/lib/components/common/ClearButton/types.js +2 -0
- package/lib/components/common/CodeBlockPanel.js +7 -3
- package/lib/components/common/ConstraintsView.js +14 -2
- package/lib/components/common/Dropdown/Dropdown.js +22 -4
- package/lib/components/common/Dropdown/index.js +2 -1
- package/lib/components/common/ExpandableExample/ExpandableExample.js +24 -3
- package/lib/components/common/ExpandableExample/index.js +2 -1
- package/lib/components/common/Extensions.js +17 -2
- package/lib/components/common/Fields/fields-layout.js +76 -51
- package/lib/components/common/Fields/fields.js +39 -17
- package/lib/components/common/Fields/index.js +3 -1
- package/lib/components/common/LinkToField.js +33 -6
- package/lib/components/common/OperationItemTitle.d.ts +1 -0
- package/lib/components/common/OperationItemTitle.js +16 -5
- package/lib/components/common/SchemaSelection/SchemaSelection.js +51 -1
- package/lib/components/common/SchemaSelection/index.js +2 -1
- package/lib/components/common/Select/Select.js +21 -1
- package/lib/components/common/Select/index.js +3 -1
- package/lib/components/common/Select/styled.js +17 -9
- package/lib/components/common/Select/types.js +2 -0
- package/lib/components/common/Skeleton/LanguageListSkeleton.js +16 -6
- package/lib/components/common/Skeleton/Skeleton.js +15 -5
- package/lib/components/common/Skeleton/index.js +3 -1
- package/lib/components/common/headers.js +4 -2
- package/lib/components/common/index.js +14 -1
- package/lib/components/common/linkify.js +28 -4
- package/lib/components/common/mixins.js +4 -2
- package/lib/components/common/panels.js +58 -33
- package/lib/components/common/schema.js +16 -8
- package/lib/components/common/styled.js +15 -7
- package/lib/components/index.js +25 -1
- package/lib/components/pluggable/RedocExample.js +20 -1
- package/lib/components/pluggable/RedocSchema.js +22 -1
- package/lib/components/pluggable/index.js +3 -1
- package/lib/components/pluggable/styled.components.js +9 -4
- package/lib/constants.js +30 -1
- package/lib/empty.js +7 -1
- package/lib/events/codeSampleCopy.js +19 -1
- package/lib/events/creator.js +5 -1
- package/lib/events/index.js +8 -1
- package/lib/events/languageSwitch.js +18 -1
- package/lib/events/panelToggle.js +16 -1
- package/lib/events/serverSwitch.js +13 -1
- package/lib/events/tryItOpen.js +12 -1
- package/lib/events/tryItSent.js +12 -1
- package/lib/events/types.js +11 -1
- package/lib/hoc/types.js +2 -0
- package/lib/hoc/utils.js +4 -1
- package/lib/hoc/withRouter.js +17 -1
- package/lib/hoc/withStore.js +28 -1
- package/lib/hooks/index.js +9 -1
- package/lib/hooks/useActivateExample.js +35 -1
- package/lib/hooks/useActiveWithFallback.js +12 -1
- package/lib/hooks/useContentItems.js +10 -1
- package/lib/hooks/useLicense.js +17 -1
- package/lib/hooks/usePerformanceMetrics.js +26 -1
- package/lib/hooks/useRouter.js +17 -1
- package/lib/hooks/useTelemetry.js +5 -1
- package/lib/hooks/useTranslate.js +6 -1
- package/lib/hooks/useUppercase2LowercaseRedirect.js +12 -1
- package/lib/icons/CSharpIcon/CSharpIcon.js +7 -1
- package/lib/icons/CSharpIcon/index.js +2 -1
- package/lib/icons/CurlIcon/CurlIcon.js +8 -2
- package/lib/icons/CurlIcon/index.js +2 -1
- package/lib/icons/GOIcon/GOIcon.js +7 -1
- package/lib/icons/GOIcon/index.js +2 -1
- package/lib/icons/JavaIcon/JavaIcon.js +7 -1
- package/lib/icons/JavaIcon/index.js +2 -1
- package/lib/icons/JavaScriptIcon/JavaScriptIcon.js +7 -1
- package/lib/icons/JavaScriptIcon/index.js +2 -1
- package/lib/icons/NodeJSIcon/NodeJSIcon.js +7 -1
- package/lib/icons/NodeJSIcon/index.js +2 -1
- package/lib/icons/PHPIcon/PHPIcon.js +7 -1
- package/lib/icons/PHPIcon/index.js +2 -1
- package/lib/icons/PayloadIcon/PayloadIcon.js +7 -1
- package/lib/icons/PayloadIcon/index.js +2 -1
- package/lib/icons/PythonIcon/PythonIcon.js +7 -1
- package/lib/icons/PythonIcon/index.js +2 -1
- package/lib/icons/RIcon/RIcon.js +7 -1
- package/lib/icons/RIcon/index.js +2 -1
- package/lib/icons/RubyIcon/RubyIcon.js +7 -1
- package/lib/icons/RubyIcon/index.js +2 -1
- package/lib/index.js +49 -1
- package/lib/jotai/app.js +113 -1
- package/lib/jotai/operation.js +28 -1
- package/lib/jotai/replay.js +5 -1
- package/lib/jotai/store.js +8 -1
- package/lib/jotai/use-write-atom.js +9 -1
- package/lib/models/callback.js +28 -1
- package/lib/models/code-sample-options.js +2 -0
- package/lib/models/example.js +17 -1
- package/lib/models/field.js +109 -1
- package/lib/models/group.js +38 -1
- package/lib/models/index.js +14 -1
- package/lib/models/mediaContent.js +26 -1
- package/lib/models/mediaType.js +153 -1
- package/lib/models/operation.js +166 -1
- package/lib/models/request.js +25 -1
- package/lib/models/response.js +46 -1
- package/lib/models/schema.js +474 -2
- package/lib/models/security.js +84 -1
- package/lib/models/tab.js +2 -0
- package/lib/models/types.js +2 -0
- package/lib/services/OpenAPIParser.js +321 -1
- package/lib/services/check.js +104 -1
- package/lib/services/code-samples/constants.js +16 -1
- package/lib/services/code-samples/generator.js +540 -1
- package/lib/services/code-samples/httpsnippet/helpers/code-builder.d.ts +5 -1
- package/lib/services/code-samples/httpsnippet/helpers/code-builder.js +252 -3
- package/lib/services/code-samples/httpsnippet/helpers/code-helpers.d.ts +2 -2
- package/lib/services/code-samples/httpsnippet/helpers/code-helpers.js +90 -2
- package/lib/services/code-samples/httpsnippet/helpers/constants.js +28 -1
- package/lib/services/code-samples/httpsnippet/helpers/lodash-int.js +173 -1
- package/lib/services/code-samples/httpsnippet/helpers/mocks/code-helpers-mock.js +76 -37
- package/lib/services/code-samples/httpsnippet/helpers/reducer.js +16 -1
- package/lib/services/code-samples/httpsnippet/helpers/shell.js +20 -1
- package/lib/services/code-samples/httpsnippet/helpers/string-utility.js +19 -1
- package/lib/services/code-samples/httpsnippet/index.js +166 -1
- package/lib/services/code-samples/httpsnippet/targets/__mocks__/mock.js +2340 -146
- package/lib/services/code-samples/httpsnippet/targets/csharp/httpclient.js +227 -2
- package/lib/services/code-samples/httpsnippet/targets/csharp/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/httpclient.js +185 -2
- package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/go/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/go/native.js +222 -3
- package/lib/services/code-samples/httpsnippet/targets/index.js +28 -1
- package/lib/services/code-samples/httpsnippet/targets/java/httpclient.js +184 -3
- package/lib/services/code-samples/httpsnippet/targets/java/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/java8/apachehttp.js +223 -2
- package/lib/services/code-samples/httpsnippet/targets/java8/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/javascript/fetch.js +147 -1
- package/lib/services/code-samples/httpsnippet/targets/javascript/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/node/fetch.js +199 -1
- package/lib/services/code-samples/httpsnippet/targets/node/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/php/curl.js +203 -5
- package/lib/services/code-samples/httpsnippet/targets/php/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/php/types.js +2 -0
- package/lib/services/code-samples/httpsnippet/targets/php/utils.js +106 -5
- package/lib/services/code-samples/httpsnippet/targets/python/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/python/requests.js +185 -6
- package/lib/services/code-samples/httpsnippet/targets/r/httr.js +111 -1
- package/lib/services/code-samples/httpsnippet/targets/r/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/r/utils.js +18 -6
- package/lib/services/code-samples/httpsnippet/targets/ruby/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/ruby/native.js +169 -1
- package/lib/services/code-samples/httpsnippet/targets/shell/curl.js +94 -6
- package/lib/services/code-samples/httpsnippet/targets/shell/index.js +11 -1
- package/lib/services/code-samples/index.js +3 -1
- package/lib/services/code-samples/types.js +2 -0
- package/lib/services/config-options/helpers.js +49 -1
- package/lib/services/config-options/index.js +3 -1
- package/lib/services/config-options/normalizeOptions.js +83 -1
- package/lib/services/config-options/types.js +2 -0
- package/lib/services/history/helpers.js +63 -1
- package/lib/services/history/index.js +2 -1
- package/lib/services/index.js +9 -1
- package/lib/services/menu/builder.js +47 -1
- package/lib/services/menu/index.js +2 -1
- package/lib/services/menu/markdown.js +93 -1
- package/lib/services/menu/operation.js +50 -1
- package/lib/services/menu/tags.js +166 -1
- package/lib/services/types.d.ts +0 -3
- package/lib/services/types.js +2 -0
- package/lib/services/utils.js +83 -1
- package/lib/standalone.js +68 -1
- package/lib/styled-components.js +6 -1
- package/lib/types/app.js +2 -0
- package/lib/types/index.js +4 -1
- package/lib/types/open-api.d.ts +1 -0
- package/lib/types/open-api.js +2 -0
- package/lib/types/security.js +2 -0
- package/lib/utils/JsonPointer.js +84 -1
- package/lib/utils/areArraysEqual.js +4 -1
- package/lib/utils/argValuesHelpers.js +35 -1
- package/lib/utils/compose.js +2 -1
- package/lib/utils/configure-helpers.js +223 -1
- package/lib/utils/convertSwagger2OpenAPI.js +14 -1
- package/lib/utils/cookies.js +73 -1
- package/lib/utils/debounce.js +22 -1
- package/lib/utils/debug.js +11 -1
- package/lib/utils/dom.js +65 -1
- package/lib/utils/environments.js +13 -1
- package/lib/utils/helpers.js +222 -12
- package/lib/utils/index.js +25 -1
- package/lib/utils/isMobile.js +13 -1
- package/lib/utils/loadAndBundleSpec.js +32 -1
- package/lib/utils/local-storage.js +12 -1
- package/lib/utils/object.js +31 -1
- package/lib/utils/openapi.js +592 -1
- package/lib/utils/parameters.js +13 -1
- package/lib/utils/path.js +22 -1
- package/lib/utils/queryString.js +60 -1
- package/lib/utils/replaceVariables.js +14 -1
- package/lib/utils/saveTextBeforeHeading.js +35 -1
- package/lib/utils/security-details.js +49 -1
- package/lib/utils/session-storage.js +12 -1
- package/lib/utils/simplifyAstStructure.js +22 -1
- package/lib/utils/sort.js +21 -1
- package/lib/utils/string.js +65 -1
- package/lib/utils/telemetry.js +7 -1
- package/lib/utils/test-utils.js +26 -1
- package/lib/utils/theme-helpers.js +24 -3
- package/lib/utils/url.js +38 -1
- package/package.json +5 -5
|
@@ -1 +1,208 @@
|
|
|
1
|
-
import{isPrimitive
|
|
1
|
+
import { isPrimitive } from '@redocly/theme/core/openapi';
|
|
2
|
+
import { getOperation, } from '../../models/index.js';
|
|
3
|
+
import { normalizeOptions, OpenAPIParser } from '../../services/index.js';
|
|
4
|
+
import { JsonPointer } from '../../utils/index.js';
|
|
5
|
+
export function convertOperationToReplayValue(path, method, openAPI, userClaims, operationState, appState) {
|
|
6
|
+
if (!openAPI) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const parser = new OpenAPIParser(openAPI);
|
|
10
|
+
const pathItem = parser.definition.paths?.[path];
|
|
11
|
+
const opItem = pathItem?.[method];
|
|
12
|
+
const operation = getOperation(parser, {
|
|
13
|
+
...opItem,
|
|
14
|
+
pathName: path,
|
|
15
|
+
httpVerb: method,
|
|
16
|
+
pathParameters: pathItem.parameters || [],
|
|
17
|
+
pathServers: pathItem.servers || [],
|
|
18
|
+
}, undefined, normalizeOptions({}), '', { isCallback: false }, userClaims);
|
|
19
|
+
if (!operation) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const activeMime = appState?.activeMimeName || 'application/json';
|
|
23
|
+
const value = {
|
|
24
|
+
id: operation.id,
|
|
25
|
+
name: operation.name,
|
|
26
|
+
method: operation.httpVerb,
|
|
27
|
+
operationId: operation.operationId,
|
|
28
|
+
parameters: convertParameters(operation.parameters, operationState?.requestValues),
|
|
29
|
+
body: convertRequestBody(operation.requestBody, openAPI, operationState?.requestValues?.body
|
|
30
|
+
? {
|
|
31
|
+
activeExampleName: operationState?.activeExampleName,
|
|
32
|
+
[activeMime]: operationState?.requestValues?.body,
|
|
33
|
+
}
|
|
34
|
+
: operationState?.activeExampleName
|
|
35
|
+
? { activeExampleName: operationState?.activeExampleName }
|
|
36
|
+
: undefined),
|
|
37
|
+
path: operation.path,
|
|
38
|
+
href: operation.href,
|
|
39
|
+
servers: operation.servers,
|
|
40
|
+
security: convertRequestSecurity(operation.security),
|
|
41
|
+
responses: Object.fromEntries(operation.responses.map((response) => [
|
|
42
|
+
response.code,
|
|
43
|
+
{
|
|
44
|
+
code: response.code,
|
|
45
|
+
description: response.description,
|
|
46
|
+
mediaTypes: response.content?.mediaTypes.reduce((acc, mediaType) => {
|
|
47
|
+
acc[mediaType.name] = {
|
|
48
|
+
name: mediaType.name,
|
|
49
|
+
schema: getBodySchema(mediaType.schema?.rawSchema, openAPI),
|
|
50
|
+
};
|
|
51
|
+
return acc;
|
|
52
|
+
}, {}),
|
|
53
|
+
},
|
|
54
|
+
])),
|
|
55
|
+
};
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
export function convertOperationToReplayValueForRedoc(userClaims) {
|
|
59
|
+
return function (path, method, openAPI) {
|
|
60
|
+
const replayValues = convertOperationToReplayValue(path, method, openAPI, userClaims);
|
|
61
|
+
if (!replayValues) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
...replayValues,
|
|
66
|
+
operationId: replayValues.operationId ||
|
|
67
|
+
JsonPointer.compile(['paths', replayValues.path, replayValues.method]),
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function convertParameters(params, state) {
|
|
72
|
+
const seenParams = new Set();
|
|
73
|
+
const allParams = params.map((param) => {
|
|
74
|
+
seenParams.add(param.in + ':' + param.name);
|
|
75
|
+
return {
|
|
76
|
+
name: param.name,
|
|
77
|
+
in: param.in,
|
|
78
|
+
required: param.required,
|
|
79
|
+
description: param.description,
|
|
80
|
+
example: state?.[String(param.in)]?.[param.name] || param.example,
|
|
81
|
+
schema: param.schema,
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
// allow to provide extra params (not defined in the operation spec)
|
|
85
|
+
for (const [inValue, param] of Object.entries(state || {})) {
|
|
86
|
+
for (const [name, example] of Object.entries(param || {})) {
|
|
87
|
+
if (!seenParams.has(inValue + ':' + name)) {
|
|
88
|
+
allParams.push({
|
|
89
|
+
name,
|
|
90
|
+
in: inValue,
|
|
91
|
+
required: false,
|
|
92
|
+
description: '',
|
|
93
|
+
example: String(example),
|
|
94
|
+
schema: undefined,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return allParams;
|
|
100
|
+
}
|
|
101
|
+
function getInputType({ type, format, enum: enumValue, }) {
|
|
102
|
+
if (type === 'string' && (format === 'binary' || format === 'base64')) {
|
|
103
|
+
return 'file';
|
|
104
|
+
}
|
|
105
|
+
if (type === 'object') {
|
|
106
|
+
return 'multiline';
|
|
107
|
+
}
|
|
108
|
+
if (enumValue.length > 0) {
|
|
109
|
+
return 'select';
|
|
110
|
+
}
|
|
111
|
+
return 'text';
|
|
112
|
+
}
|
|
113
|
+
function getFieldExamples(field, examples) {
|
|
114
|
+
const example = field[0]?.example || field[0]?.examples;
|
|
115
|
+
if (example) {
|
|
116
|
+
return example;
|
|
117
|
+
}
|
|
118
|
+
if (field.schema?.example) {
|
|
119
|
+
return field.schema.example;
|
|
120
|
+
}
|
|
121
|
+
const defaultExample = examples?.['default']?.value || examples?.['default']?.rawValue;
|
|
122
|
+
if (defaultExample?.[field.name]) {
|
|
123
|
+
return isPrimitive(defaultExample?.[field.name])
|
|
124
|
+
? String(defaultExample?.[field.name])
|
|
125
|
+
: JSON.stringify(defaultExample?.[field.name]);
|
|
126
|
+
}
|
|
127
|
+
return '';
|
|
128
|
+
}
|
|
129
|
+
function convertRequestBody(requestBody, fullOpenApi, state) {
|
|
130
|
+
if (!requestBody || !requestBody.content?.mediaTypes) {
|
|
131
|
+
if (!state)
|
|
132
|
+
return undefined;
|
|
133
|
+
const { activeExampleName, ...rest } = state;
|
|
134
|
+
return {
|
|
135
|
+
activeExampleName,
|
|
136
|
+
mediaTypes: Object.fromEntries(Object.entries(rest).map(([key, value]) => [
|
|
137
|
+
key,
|
|
138
|
+
{ name: key, examples: { default: { value } }, schema: {}, parameters: [] },
|
|
139
|
+
])),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
required: requestBody.required,
|
|
144
|
+
activeExampleName: state?.activeExampleName,
|
|
145
|
+
mediaTypes: requestBody.content.mediaTypes.reduce((acc, mediaType) => {
|
|
146
|
+
const schemaModel = mediaType.schema;
|
|
147
|
+
const examples = state?.[mediaType.name]
|
|
148
|
+
? {
|
|
149
|
+
default: {
|
|
150
|
+
value: state?.[mediaType.name],
|
|
151
|
+
rawValue: state?.[mediaType.name],
|
|
152
|
+
mime: mediaType.name,
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
: mediaType.examples || mediaType.formExamples;
|
|
156
|
+
acc[mediaType.name] = {
|
|
157
|
+
name: mediaType.name,
|
|
158
|
+
examples: examples,
|
|
159
|
+
schema: getBodySchema(mediaType.schema?.rawSchema, fullOpenApi),
|
|
160
|
+
parameters: schemaModel?.fields?.map((field) => {
|
|
161
|
+
// www-form-urlencoded and form-data
|
|
162
|
+
return {
|
|
163
|
+
inputType: getInputType(field.schema),
|
|
164
|
+
name: field.name,
|
|
165
|
+
example: getFieldExamples(field, examples),
|
|
166
|
+
};
|
|
167
|
+
}),
|
|
168
|
+
};
|
|
169
|
+
return acc;
|
|
170
|
+
}, {}),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function getBodySchema(schema, rootDefinition) {
|
|
174
|
+
if (!schema || !rootDefinition)
|
|
175
|
+
return undefined;
|
|
176
|
+
return {
|
|
177
|
+
...schema,
|
|
178
|
+
components: rootDefinition?.components || {}, // add components to schema in case there are $refs in the original schema
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
export function convertRequestSecurity(security) {
|
|
182
|
+
if (!security) {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
return security.map(({ schemes }) => {
|
|
186
|
+
return schemes.map((s) => {
|
|
187
|
+
const securityScheme = {
|
|
188
|
+
id: s.id,
|
|
189
|
+
type: s.type,
|
|
190
|
+
in: s.in,
|
|
191
|
+
openIdConnectUrl: s.openIdConnectUrl,
|
|
192
|
+
scopes: s.scopes,
|
|
193
|
+
scheme: s.scheme,
|
|
194
|
+
name: s.name,
|
|
195
|
+
flows: s.flows,
|
|
196
|
+
'x-defaultAccessToken': s['x-defaultAccessToken'],
|
|
197
|
+
'x-defaultTokenType': s['x-defaultTokenType'],
|
|
198
|
+
'x-defaultClientId': s['x-defaultClientId'],
|
|
199
|
+
'x-defaultClientSecret': s['x-defaultClientSecret'],
|
|
200
|
+
'x-defaultUsername': s['x-defaultUsername'],
|
|
201
|
+
'x-defaultPassword': s['x-defaultPassword'],
|
|
202
|
+
};
|
|
203
|
+
Object.keys(securityScheme).forEach((key) => securityScheme[key] === undefined && delete securityScheme[key]);
|
|
204
|
+
return securityScheme;
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useMemo } from 'react';
|
|
3
|
+
import { useAtomValue } from 'jotai';
|
|
4
|
+
import { Row } from '../common/index.js';
|
|
5
|
+
import { Title } from '../common/OperationItemTitle.js';
|
|
6
|
+
import { LinkToField } from '../common/LinkToField.js';
|
|
7
|
+
import { makeDeepLink } from '../../services/index.js';
|
|
8
|
+
import { Description } from '../OperationItem/Description.js';
|
|
9
|
+
import { Security } from '../Security/index.js';
|
|
10
|
+
import { ExpandAllButton } from '../ExpandAllButton/index.js';
|
|
11
|
+
import { RequestParameters } from '../RequestParameters/index.js';
|
|
12
|
+
import { activeMimeNameAtom } from '../../jotai/app.js';
|
|
13
|
+
import { getActiveMediaType } from '../../models/mediaContent.js';
|
|
14
|
+
import { styled } from '../../styled-components.js';
|
|
15
|
+
import { Extensions } from '../common/Extensions.js';
|
|
16
|
+
function RequestDetailsComponent({ operation: { id, description, externalDocs, parameters, requestBody, pointer, security, extensions, callbackId, }, title, translate, onPanelToggle, }) {
|
|
17
|
+
const activeMimeName = useAtomValue(activeMimeNameAtom);
|
|
18
|
+
const showExpandAllButton = useMemo(() => {
|
|
19
|
+
const hasNestedParameters = parameters.some(({ schema }) => !schema.isPrimitive && !schema.isCircular);
|
|
20
|
+
if (!requestBody?.content || hasNestedParameters) {
|
|
21
|
+
return hasNestedParameters;
|
|
22
|
+
}
|
|
23
|
+
const { schema } = getActiveMediaType(requestBody.content, activeMimeName) || {};
|
|
24
|
+
const hasNestedRequestBody = schema?.fields?.some(({ schema: fieldSchema }) => !fieldSchema.isPrimitive && !fieldSchema.isCircular);
|
|
25
|
+
return hasNestedRequestBody;
|
|
26
|
+
}, [activeMimeName, parameters, requestBody?.content]);
|
|
27
|
+
const hasCustomExtensions = Object.keys(extensions || {}).length > 0;
|
|
28
|
+
return (_jsxs(_Fragment, { children: [_jsx(Row, { children: _jsxs(HeadingWrapper, { children: [_jsxs(Title, { children: [id && _jsx(LinkToField, { to: makeDeepLink(id, 'request') }), title || translate?.('openapi.request', 'Request'), showExpandAllButton && (_jsx(ExpandAllButton, { operationPointer: pointer, type: "request", onPanelToggle: onPanelToggle }))] }), _jsx(Description, { description: description || externalDocs ? description : undefined, externalDocs: externalDocs }), hasCustomExtensions && _jsx(Extensions, { extensions: extensions }), _jsx(Security, { securities: security })] }) }), _jsx(RequestParameters, { parameters: parameters, body: requestBody, operationId: id, callbackId: callbackId })] }));
|
|
29
|
+
}
|
|
30
|
+
const HeadingWrapper = styled.div `
|
|
2
31
|
width: 100%;
|
|
3
|
-
|
|
32
|
+
`;
|
|
33
|
+
export const RequestDetails = memo(RequestDetailsComponent);
|
|
34
|
+
//# sourceMappingURL=RequestDetails.js.map
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { memo } from 'react';
|
|
3
|
+
import { BodyContent } from '../common/BodyContent/index.js';
|
|
4
|
+
function BodyComponent({ content, description, required, deepLink, }) {
|
|
5
|
+
return (_jsx(BodyContent, { content: content, required: required, description: description, skipReadOnly: content.isRequestType, skipWriteOnly: !content.isRequestType, deepLink: deepLink }));
|
|
6
|
+
}
|
|
7
|
+
export const Body = memo(BodyComponent);
|
|
8
|
+
//# sourceMappingURL=Body.js.map
|
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { memo } from 'react';
|
|
3
|
+
import { LinkIcon } from '@redocly/theme/icons/LinkIcon/LinkIcon';
|
|
4
|
+
import { PropertyDetails } from '../PropertyDetails/index.js';
|
|
5
|
+
import { LinkToField } from '../common/LinkToField.js';
|
|
6
|
+
import { styled } from '../../styled-components.js';
|
|
7
|
+
function ParametersGroupComponent({ title, parameters, deepLink, }) {
|
|
8
|
+
if (!parameters || !parameters.length) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return (_jsxs(Wrapper, { children: [_jsxs(Title, { children: [_jsx(LinkToField, { to: deepLink }), title] }), parameters.map((field, index) => (_jsx(PropertyDetails, { isFirst: index === 0, field: field }, field.name)))] }));
|
|
12
|
+
}
|
|
13
|
+
export const ParametersGroup = memo(ParametersGroupComponent);
|
|
14
|
+
const Title = styled.span `
|
|
2
15
|
position: relative;
|
|
3
16
|
display: flex;
|
|
4
17
|
align-items: center;
|
|
@@ -10,11 +23,13 @@ import{jsx as o,jsxs as t}from"react/jsx-runtime";import{memo as p}from"react";i
|
|
|
10
23
|
padding: var(--spacing-xxs) 0;
|
|
11
24
|
|
|
12
25
|
:hover {
|
|
13
|
-
${
|
|
26
|
+
${LinkIcon} {
|
|
14
27
|
opacity: 1;
|
|
15
28
|
visibility: visible;
|
|
16
29
|
}
|
|
17
30
|
}
|
|
18
|
-
|
|
31
|
+
`;
|
|
32
|
+
const Wrapper = styled.div `
|
|
19
33
|
margin-top: var(--spacing-md);
|
|
20
|
-
`;
|
|
34
|
+
`;
|
|
35
|
+
//# sourceMappingURL=ParametersGroup.js.map
|
|
@@ -1 +1,40 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ParametersGroup } from './ParametersGroup.js';
|
|
3
|
+
import { Body } from './Body.js';
|
|
4
|
+
import { makeDeepLink } from '../../services/index.js';
|
|
5
|
+
import { useTranslate } from '../../hooks/index.js';
|
|
6
|
+
const PARAM_PLACES = ['path', 'query', 'cookie', 'header'];
|
|
7
|
+
export function RequestParameters({ body, parameters = [], operationId, callbackId, }) {
|
|
8
|
+
const translate = useTranslate();
|
|
9
|
+
if (!body && !parameters.length) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const PARAM_NAMES_MAP = {
|
|
13
|
+
[PARAM_PLACES[0]]: translate('openapi.path', 'Path'),
|
|
14
|
+
[PARAM_PLACES[1]]: translate('openapi.query', 'Query'),
|
|
15
|
+
[PARAM_PLACES[2]]: translate('openapi.cookie', 'Cookies'),
|
|
16
|
+
[PARAM_PLACES[3]]: translate('openapi.header', 'Headers'),
|
|
17
|
+
};
|
|
18
|
+
const orderParams = (params) => {
|
|
19
|
+
const res = {};
|
|
20
|
+
params.forEach((param) => {
|
|
21
|
+
safePush(res, param.in, param);
|
|
22
|
+
});
|
|
23
|
+
return res;
|
|
24
|
+
};
|
|
25
|
+
const paramsMap = orderParams(parameters);
|
|
26
|
+
const paramsPlaces = parameters.length > 0 ? PARAM_PLACES : [];
|
|
27
|
+
const { content: bodyContent, description: bodyDescription, required } = body || {};
|
|
28
|
+
return (_jsxs(_Fragment, { children: [paramsPlaces.map((place) => (_jsx(ParametersGroup, { title: PARAM_NAMES_MAP[place], parameters: paramsMap[place], deepLink: generateDeepLink(operationId, callbackId, place) }, place))), bodyContent && (_jsx(Body, { content: bodyContent, description: bodyDescription, required: required, deepLink: generateDeepLink(operationId, callbackId) }))] }));
|
|
29
|
+
}
|
|
30
|
+
function safePush(obj, prop = '', item) {
|
|
31
|
+
if (!obj[prop]) {
|
|
32
|
+
obj[prop] = [];
|
|
33
|
+
}
|
|
34
|
+
obj[prop].push(item);
|
|
35
|
+
}
|
|
36
|
+
function generateDeepLink(operationId, callbackId, place = 'body') {
|
|
37
|
+
const suffix = `${callbackId ? `${callbackId}/request/${place}` : `request/${place}`}`;
|
|
38
|
+
return makeDeepLink(operationId, suffix);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=RequestParameters.js.map
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export { RequestParameters } from './RequestParameters.js';
|
|
2
|
+
export { ParametersGroup } from './ParametersGroup.js';
|
|
3
|
+
export { Body } from './Body.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,56 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useCallback } from 'react';
|
|
3
|
+
import { CodeBlock } from '@redocly/theme/components/CodeBlock/CodeBlock';
|
|
4
|
+
import { SelectOrLabel } from '../SelectOrLabel/index.js';
|
|
5
|
+
import { MediaTypesSwitch } from '../MediaTypeSwitch/index.js';
|
|
6
|
+
import { SelectWrapper } from '../PayloadSamples/index.js';
|
|
7
|
+
import { Example } from './Example.js';
|
|
8
|
+
import { MimeLabel, Select } from '../common/index.js';
|
|
9
|
+
import { styled } from '../../styled-components.js';
|
|
10
|
+
function CodeSampleComponent({ onCopyClick, ...props }) {
|
|
11
|
+
const mimeContent = props.operation.requestBody?.content;
|
|
12
|
+
const renderSelect = useCallback((props) => {
|
|
13
|
+
const hasSelect = (mimeContent?.mediaTypes?.length ?? 0) > 1;
|
|
14
|
+
return hasSelect ? (_jsx(SelectWrapper, { children: _jsx(SelectOrLabel, { Label: MimeLabel, Select: Select, variant: "dark", fullWidth: true, ...props }) })) : null;
|
|
15
|
+
}, [mimeContent]);
|
|
16
|
+
const renderSample = useCallback((exampleName) => {
|
|
17
|
+
return props.source ? (_jsx(StyledCodeBlock, { lang: props.lang, source: props.source, header: {
|
|
18
|
+
className: 'code-block-header',
|
|
19
|
+
controls: {
|
|
20
|
+
copy: {
|
|
21
|
+
onClick: onCopyClick,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
} })) : (_jsx(StyledCodeBlock, { lang: props.lang, externalSource: {
|
|
25
|
+
sample: props.externalSample,
|
|
26
|
+
exampleName,
|
|
27
|
+
operation: props.operation,
|
|
28
|
+
pathParams: props.pathParams,
|
|
29
|
+
properties: props.properties,
|
|
30
|
+
}, header: {
|
|
31
|
+
className: 'code-block-header',
|
|
32
|
+
controls: {
|
|
33
|
+
copy: {
|
|
34
|
+
onClick: onCopyClick,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
} }));
|
|
38
|
+
}, [
|
|
39
|
+
onCopyClick,
|
|
40
|
+
props.externalSample,
|
|
41
|
+
props.lang,
|
|
42
|
+
props.operation,
|
|
43
|
+
props.pathParams,
|
|
44
|
+
props.properties,
|
|
45
|
+
props.source,
|
|
46
|
+
]);
|
|
47
|
+
if (mimeContent === undefined || props.source != undefined) {
|
|
48
|
+
return renderSample();
|
|
49
|
+
}
|
|
50
|
+
return (_jsx(MediaTypesSwitch, { content: mimeContent, renderSelect: renderSelect, children: (mediaType) => (_jsx(Example, { mediaType: mediaType, mediaContent: mimeContent, renderSample: renderSample })) }));
|
|
51
|
+
}
|
|
52
|
+
export const CodeSample = memo(CodeSampleComponent);
|
|
53
|
+
const StyledCodeBlock = styled(CodeBlock) `
|
|
2
54
|
border: none;
|
|
3
55
|
margin: 0;
|
|
4
56
|
|
|
@@ -6,4 +58,5 @@ import{jsx as r}from"react/jsx-runtime";import{memo as d,useCallback as l}from"r
|
|
|
6
58
|
border-bottom: 0;
|
|
7
59
|
padding-right: var(--spacing-sm);
|
|
8
60
|
}
|
|
9
|
-
`;
|
|
61
|
+
`;
|
|
62
|
+
//# sourceMappingURL=CodeSample.js.map
|
|
@@ -1 +1,37 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { memo } from 'react';
|
|
3
|
+
import { useAtom } from 'jotai';
|
|
4
|
+
import { ExampleSwitch, useExampleKey } from '../Samples/index.js';
|
|
5
|
+
import { useActivateExample, useTelemetry } from '../../hooks/index.js';
|
|
6
|
+
import { operationStore } from '../../jotai/operation.js';
|
|
7
|
+
function ExampleComponent({ mediaType, mediaContent, renderSample }) {
|
|
8
|
+
const telemetry = useTelemetry();
|
|
9
|
+
const pointer = mediaType.operation.pointer;
|
|
10
|
+
const [operation, setOperation] = useAtom(operationStore(pointer));
|
|
11
|
+
const examples = mediaType.examples || {};
|
|
12
|
+
const examplesKeys = Object.keys(examples);
|
|
13
|
+
const setActivateExampleName = useActivateExample(mediaContent);
|
|
14
|
+
const { exampleKey } = useExampleKey(mediaType.operation, examples);
|
|
15
|
+
if (!examplesKeys.length || examplesKeys.length === 1) {
|
|
16
|
+
return renderSample();
|
|
17
|
+
}
|
|
18
|
+
const handleExampleChange = (key) => {
|
|
19
|
+
telemetry.send({
|
|
20
|
+
type: 'openapi_docs.examples_switcher.clicked',
|
|
21
|
+
payload: {
|
|
22
|
+
example: key,
|
|
23
|
+
numberOfExamples: examplesKeys.length,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
setOperation({
|
|
27
|
+
...operation,
|
|
28
|
+
activeExampleName: key,
|
|
29
|
+
activeOneOf: { [pointer]: examplesKeys.indexOf(key) },
|
|
30
|
+
requestValues: { body: null },
|
|
31
|
+
});
|
|
32
|
+
setActivateExampleName(key);
|
|
33
|
+
};
|
|
34
|
+
return (_jsxs(_Fragment, { children: [_jsx(ExampleSwitch, { examples: examples, exampleKey: exampleKey, onChange: handleExampleChange }), renderSample(exampleKey)] }));
|
|
35
|
+
}
|
|
36
|
+
export const Example = memo(ExampleComponent);
|
|
37
|
+
//# sourceMappingURL=Example.js.map
|
|
@@ -1,12 +1,96 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useCallback, useMemo } from 'react';
|
|
3
|
+
import { useAtomValue, useAtom } from 'jotai';
|
|
4
|
+
import { PanelHeader } from '@redocly/theme/components/Panel/PanelHeader';
|
|
5
|
+
import { PayloadSamples } from '../PayloadSamples/index.js';
|
|
6
|
+
import { CodeSample } from './CodeSample.js';
|
|
7
|
+
import { useCodeSamples } from './useCodeSamples.js';
|
|
8
|
+
import { isPayloadSample } from '../../models/index.js';
|
|
9
|
+
import { createCodeSampleCopyEvent, createLanguageSwitchEvent } from '../../events/index.js';
|
|
10
|
+
import { globalStoreAtom } from '../../jotai/store.js';
|
|
11
|
+
import { ServerListDropdown } from '../ServerListDropdown/index.js';
|
|
12
|
+
import { LanguageDropdown } from '../Language/index.js';
|
|
13
|
+
import { activeMimeNameAtom, languageAtom } from '../../jotai/app.js';
|
|
14
|
+
import { Replay } from '../Replay/index.js';
|
|
15
|
+
import { CodeBlockPanel } from '../common/index.js';
|
|
16
|
+
import { useActiveWithFallback, useTelemetry } from '../../hooks/index.js';
|
|
17
|
+
import { operationStore } from '../../jotai/operation.js';
|
|
18
|
+
import { styled } from '../../styled-components.js';
|
|
19
|
+
function RequestSamplesComponent({ operation, disableFooter, onPanelToggle, ...props }) {
|
|
20
|
+
const telemetry = useTelemetry();
|
|
21
|
+
const [{ activeLanguage, languages }, setLanguage] = useAtom(languageAtom);
|
|
22
|
+
const { samples } = useCodeSamples(operation);
|
|
23
|
+
const { parser, options: { events, corsProxyUrl, hideReplay }, } = useAtomValue(globalStoreAtom);
|
|
24
|
+
const isReplayAvailable = !disableFooter && !operation.isWebhook && !hideReplay && !operation.hideReplay;
|
|
25
|
+
const isLanguagesAvailable = !!languages?.length;
|
|
26
|
+
const localActiveLanguage = useActiveWithFallback(samples, activeLanguage);
|
|
27
|
+
const onSelectLanguage = (selectedItem) => {
|
|
28
|
+
setLanguage(selectedItem);
|
|
29
|
+
telemetry.send({
|
|
30
|
+
type: 'openapi_docs.select_language.clicked',
|
|
31
|
+
payload: { language: selectedItem },
|
|
32
|
+
});
|
|
33
|
+
const selectedSampleDetails = languages?.find((lang) => lang.key === selectedItem);
|
|
34
|
+
if (events?.codeSamplesLanguageSwitch && selectedSampleDetails) {
|
|
35
|
+
const eventPayload = createLanguageSwitchEvent({
|
|
36
|
+
operation: operation,
|
|
37
|
+
sample: {
|
|
38
|
+
lang: selectedSampleDetails.lang,
|
|
39
|
+
label: selectedSampleDetails.title,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
events.codeSamplesLanguageSwitch(eventPayload);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const activeMimeName = useAtomValue(activeMimeNameAtom);
|
|
46
|
+
const { activeExampleName } = useAtomValue(operationStore(operation.pointer));
|
|
47
|
+
const handleCodeSampleCopy = useCallback(({ lang, title }) => () => {
|
|
48
|
+
const event = createCodeSampleCopyEvent({
|
|
49
|
+
operation: operation,
|
|
50
|
+
label: title,
|
|
51
|
+
lang,
|
|
52
|
+
type: 'request',
|
|
53
|
+
activeMimeName,
|
|
54
|
+
activeExampleName,
|
|
55
|
+
});
|
|
56
|
+
telemetry.send({
|
|
57
|
+
type: 'openapi_docs.copy_code_snippet.clicked',
|
|
58
|
+
payload: { snippetType: 'request', language: lang },
|
|
59
|
+
});
|
|
60
|
+
events?.codeSamplesCopy?.(event);
|
|
61
|
+
}, [operation, telemetry, events, activeMimeName, activeExampleName]);
|
|
62
|
+
const handlePanelToggle = useCallback((isExpanded) => {
|
|
63
|
+
onPanelToggle?.(isExpanded, 'request-samples');
|
|
64
|
+
}, [onPanelToggle]);
|
|
65
|
+
const renderSummary = () => {
|
|
66
|
+
return (_jsxs(StyledPanelHeader, { isExpandable: false, withReplay: !isLanguagesAvailable && isReplayAvailable, children: [_jsx(StyledServerListDropdown, { operation: operation }), isLanguagesAvailable && (_jsx(LanguageDropdown, { activeTab: localActiveLanguage, samples: samples, onChange: onSelectLanguage })), !isLanguagesAvailable && isReplayAvailable && (_jsx(Replay, { operation: operation, corsProxyUrl: corsProxyUrl, fullOpenApi: parser.definition }))] }));
|
|
67
|
+
};
|
|
68
|
+
const renderFooter = useMemo(() => {
|
|
69
|
+
if (isReplayAvailable && isLanguagesAvailable) {
|
|
70
|
+
return (_jsx(ReplayWrapper, { children: _jsx(Replay, { operation: operation, corsProxyUrl: corsProxyUrl, fullOpenApi: parser.definition }) }));
|
|
71
|
+
}
|
|
72
|
+
}, [isReplayAvailable, isLanguagesAvailable, operation, corsProxyUrl, parser.definition]);
|
|
73
|
+
const renderSamples = useMemo(() => samples.map((sample) => {
|
|
74
|
+
return sample.key === localActiveLanguage ? (_jsx("div", { children: isPayloadSample(sample) ? (_jsx(PayloadSamples, { content: sample.requestBodyContent, onCopyClick: handleCodeSampleCopy(sample), onPanelToggle: handlePanelToggle, ...props })) : (_jsx(CodeSample, { lang: sample.lang, source: sample.source, externalSample: sample, operation: operation, onCopyClick: handleCodeSampleCopy(sample), ...props })) }, sample.key + operation.id)) : null;
|
|
75
|
+
}), [localActiveLanguage, handleCodeSampleCopy, handlePanelToggle, operation, props, samples]);
|
|
76
|
+
if (languages && !samples.length) {
|
|
77
|
+
return (_jsx(CodeBlockPanel, { className: "panel-request-samples", header: renderSummary, isExpandable: false, expanded: false }));
|
|
78
|
+
}
|
|
79
|
+
return samples.length ? (_jsx(CodeBlockPanel, { className: "panel-request-samples", header: renderSummary, footer: renderFooter, isExpandable: false, children: renderSamples })) : null;
|
|
80
|
+
}
|
|
81
|
+
export const RequestSamples = memo(RequestSamplesComponent);
|
|
82
|
+
const StyledPanelHeader = styled(PanelHeader) `
|
|
2
83
|
flex-wrap: nowrap;
|
|
3
|
-
${({withReplay
|
|
4
|
-
|
|
84
|
+
${({ withReplay }) => withReplay && 'padding: var(--spacing-xs) var(--spacing-sm);'}
|
|
85
|
+
`;
|
|
86
|
+
const StyledServerListDropdown = styled(ServerListDropdown) `
|
|
5
87
|
padding-right: var(--spacing-base);
|
|
6
88
|
min-width: 0;
|
|
7
|
-
|
|
89
|
+
`;
|
|
90
|
+
const ReplayWrapper = styled.div `
|
|
8
91
|
display: flex;
|
|
9
92
|
justify-content: flex-end;
|
|
10
93
|
border-top: var(--panel-border);
|
|
11
94
|
padding: var(--spacing-base) var(--spacing-md) var(--spacing-md);
|
|
12
|
-
`;
|
|
95
|
+
`;
|
|
96
|
+
//# sourceMappingURL=RequestSamples.js.map
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
export { CodeSample } from './CodeSample.js';
|
|
2
|
+
export { RequestSamples } from './RequestSamples.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|