@redocly/openapi-docs 3.12.0 → 3.12.2
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 +753 -750
- 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 +16 -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.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 +40 -7
- 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.js +12 -6
- 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 +52 -29
- 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.js +252 -3
- 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.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.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 +4 -4
|
@@ -1 +1,540 @@
|
|
|
1
|
-
import*
|
|
1
|
+
import * as Sampler from 'openapi-sampler';
|
|
2
|
+
import merge from 'deepmerge';
|
|
3
|
+
import { isObject } from '@redocly/theme/core/openapi';
|
|
4
|
+
import { areArraysEqual, serializeParameterValue, getSecurityDetails, getParameterValue, queryString, isArrayOfObjects, deleteEmptyArrayItem, } from '../../utils/index.js';
|
|
5
|
+
import { normalizeMimeType, arrayMergeStrategy } from '../utils.js';
|
|
6
|
+
import { MediaTypes } from '../../constants.js';
|
|
7
|
+
import { HTTPSnippet } from './httpsnippet/index.js';
|
|
8
|
+
import { getActiveMediaType } from '../../models/mediaContent.js';
|
|
9
|
+
import StringUtility from './httpsnippet/helpers/string-utility.js';
|
|
10
|
+
export function safeSample(schema, options, document) {
|
|
11
|
+
try {
|
|
12
|
+
return Sampler.sample(schema, options, document);
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
console.error(`Error sampling schema: ${e.message}`);
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function getSelectedSecurityScheme(operationSecurity, activeSecuritySchemeIds) {
|
|
20
|
+
return operationSecurity.find((sec) => {
|
|
21
|
+
const secSchemesIds = sec.schemes.map((scheme) => scheme.id);
|
|
22
|
+
return areArraysEqual(secSchemesIds, activeSecuritySchemeIds || []);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function mapOperationToHAR(operation, { exampleName = '', skipOptionalParameters = false, withOAuth2Call = false, spec, generatedPayloadSamplesMaxDepth = 8, pathParams = {}, properties = {}, activeMimeName = '', }, { environment, requestValues, activeSecuritySchemeIds, }) {
|
|
26
|
+
const envServer = environment.server;
|
|
27
|
+
const activeServer = operation.servers.find((server) => server.url === envServer) || operation.servers[0];
|
|
28
|
+
const selectedSecurityScheme = getSelectedSecurityScheme(operation.security, activeSecuritySchemeIds);
|
|
29
|
+
const { securityHeaders, securityCookies, securityQueries, securityOAuth2ExtraCalls, basicAuth } = getSecurityData(selectedSecurityScheme || operation.security?.[0], withOAuth2Call, environment); // TODO: add dropdown for security type select
|
|
30
|
+
const activeMimeType = operation?.requestBody?.content &&
|
|
31
|
+
getActiveMediaType(operation.requestBody.content, activeMimeName);
|
|
32
|
+
const samplerOptions = {
|
|
33
|
+
skipNonRequired: skipOptionalParameters,
|
|
34
|
+
skipReadOnly: true,
|
|
35
|
+
maxSampleDepth: generatedPayloadSamplesMaxDepth,
|
|
36
|
+
quiet: true,
|
|
37
|
+
};
|
|
38
|
+
const tryItRequestValues = requestValues;
|
|
39
|
+
let hasContentTypeHeader = false;
|
|
40
|
+
const headers = operation.parameters
|
|
41
|
+
.filter((param) => param.in === 'header')
|
|
42
|
+
.filter((param) => !(skipOptionalParameters && !param.required))
|
|
43
|
+
.map((header) => ({
|
|
44
|
+
name: header.name,
|
|
45
|
+
value: tryItRequestValues['header']?.[header.name] ||
|
|
46
|
+
getParameterValue('header', header.name) ||
|
|
47
|
+
header.serverValues?.[envServer]?.example ||
|
|
48
|
+
header.example ||
|
|
49
|
+
serializeParameterValue(header, safeSample(header.schema.rawSchema, samplerOptions, spec)),
|
|
50
|
+
}))
|
|
51
|
+
.map((header) => {
|
|
52
|
+
if (
|
|
53
|
+
// Overwrite content-type header from selected value in dropdown
|
|
54
|
+
activeMimeType?.name &&
|
|
55
|
+
header.name.toLowerCase() === 'content-type') {
|
|
56
|
+
hasContentTypeHeader = true;
|
|
57
|
+
header.value = activeMimeType.name;
|
|
58
|
+
}
|
|
59
|
+
return header;
|
|
60
|
+
})
|
|
61
|
+
.concat(securityHeaders);
|
|
62
|
+
if (!hasContentTypeHeader && activeMimeType?.name) {
|
|
63
|
+
headers.unshift({
|
|
64
|
+
name: 'Content-Type',
|
|
65
|
+
value: activeMimeType?.name,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const cookies = operation.parameters
|
|
69
|
+
.filter((param) => param.in === 'cookie')
|
|
70
|
+
.filter((param) => !(skipOptionalParameters && !param.required))
|
|
71
|
+
.map((cookie) => queryString.parse(serializeParameterValue(cookie, cookie.serverValues?.[envServer]?.example ||
|
|
72
|
+
cookie.example ||
|
|
73
|
+
safeSample(cookie.schema.rawSchema, samplerOptions, spec))))
|
|
74
|
+
.reduce((acc, current) => {
|
|
75
|
+
for (const [key, value] of Object.entries(current)) {
|
|
76
|
+
acc.push({
|
|
77
|
+
name: key,
|
|
78
|
+
value: String(tryItRequestValues['cookie']?.[key] || value),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return acc;
|
|
82
|
+
}, [])
|
|
83
|
+
.concat(securityCookies);
|
|
84
|
+
const queryParams = operation.parameters
|
|
85
|
+
.filter((param) => param.in === 'query')
|
|
86
|
+
.filter((param) => !(skipOptionalParameters && !param.required))
|
|
87
|
+
.map((query) => {
|
|
88
|
+
return queryString.parse(serializeParameterValue(query, query.serverValues?.[envServer]?.example ||
|
|
89
|
+
query.example ||
|
|
90
|
+
safeSample(query.schema.rawSchema, samplerOptions, spec)));
|
|
91
|
+
})
|
|
92
|
+
.reduce((acc, current) => {
|
|
93
|
+
for (const [key, value] of Object.entries(current)) {
|
|
94
|
+
acc.push({
|
|
95
|
+
name: key,
|
|
96
|
+
value: (isArrayOfObjects(tryItRequestValues['query']?.[key]) &&
|
|
97
|
+
JSON.stringify(deleteEmptyArrayItem(tryItRequestValues['query']?.[key]))) ||
|
|
98
|
+
String(tryItRequestValues['query']?.[key] || value),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return acc;
|
|
102
|
+
}, [])
|
|
103
|
+
.concat(securityQueries);
|
|
104
|
+
const server = activeServer?.url.replace(/\/$/, ''); // remove trailing slash
|
|
105
|
+
const path = operation.path.replace(/^\//, '');
|
|
106
|
+
const url = `${server}/${path}`;
|
|
107
|
+
// should we use examples instead of name?
|
|
108
|
+
const pathParameters = operation.parameters
|
|
109
|
+
.filter((param) => param.in === 'path')
|
|
110
|
+
.reduce((acc, value) => {
|
|
111
|
+
const { in: _in, name } = value;
|
|
112
|
+
acc[name] =
|
|
113
|
+
tryItRequestValues['path']?.[name] ||
|
|
114
|
+
value.serverValues?.[envServer]?.example ||
|
|
115
|
+
value.example ||
|
|
116
|
+
pathParams[name] ||
|
|
117
|
+
getParameterValue(_in, name);
|
|
118
|
+
return acc;
|
|
119
|
+
}, {});
|
|
120
|
+
const contentType = activeMimeType?.name.toLowerCase();
|
|
121
|
+
const useFormValues = contentType === MediaTypes.MULTIPART || contentType === MediaTypes.URL_ENCODED;
|
|
122
|
+
const activeExample = useFormValues
|
|
123
|
+
? activeMimeType?.formExamples?.[exampleName]
|
|
124
|
+
: activeMimeType?.examples?.[exampleName];
|
|
125
|
+
// Getting example by name or just first example in name is not provided
|
|
126
|
+
const examples = useFormValues
|
|
127
|
+
? activeMimeType?.formExamples || {}
|
|
128
|
+
: activeMimeType?.examples || {};
|
|
129
|
+
const [firstExample] = Object.values(examples);
|
|
130
|
+
const serverSpecificValue = activeExample?.serverValues?.[envServer]?.value ||
|
|
131
|
+
firstExample?.serverValues?.[envServer]?.value;
|
|
132
|
+
const processXmlSchema = (values) => {
|
|
133
|
+
if (!values || typeof values !== 'object' || !activeMimeType?.schema?.rawSchema) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
return safeSample(populateXmlSchemaFields(activeMimeType.schema.rawSchema, values), { ...samplerOptions, format: 'xml' }, spec);
|
|
137
|
+
};
|
|
138
|
+
const getExampleValue = () => {
|
|
139
|
+
if (tryItRequestValues?.['body']) {
|
|
140
|
+
return tryItRequestValues['body'];
|
|
141
|
+
}
|
|
142
|
+
if (contentType === MediaTypes.XML) {
|
|
143
|
+
const xmlProcessed = processXmlSchema(serverSpecificValue) ||
|
|
144
|
+
processXmlSchema(activeExample?.value) ||
|
|
145
|
+
processXmlSchema(firstExample?.value);
|
|
146
|
+
if (xmlProcessed) {
|
|
147
|
+
return xmlProcessed;
|
|
148
|
+
}
|
|
149
|
+
if (activeMimeType?.schema) {
|
|
150
|
+
return safeSample(activeMimeType.schema.rawSchema, { ...samplerOptions, format: 'xml' }, spec);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
const sampledValue = activeMimeType?.schema &&
|
|
155
|
+
safeSample(activeMimeType.schema.rawSchema, { ...samplerOptions, format: 'json' }, spec);
|
|
156
|
+
return serverSpecificValue || activeExample?.value || firstExample?.value || sampledValue;
|
|
157
|
+
}
|
|
158
|
+
return '';
|
|
159
|
+
};
|
|
160
|
+
const exampleValue = getExampleValue();
|
|
161
|
+
let textPostData = '';
|
|
162
|
+
let postDataParams = [];
|
|
163
|
+
switch (normalizeMimeType(contentType)) {
|
|
164
|
+
case MediaTypes.JSON:
|
|
165
|
+
textPostData = JSON.stringify(getDataRequest(exampleValue, properties));
|
|
166
|
+
break;
|
|
167
|
+
case MediaTypes.XML:
|
|
168
|
+
textPostData = exampleValue;
|
|
169
|
+
break;
|
|
170
|
+
case MediaTypes.URL_ENCODED:
|
|
171
|
+
case MediaTypes.MULTIPART:
|
|
172
|
+
textPostData = queryString.stringify(getDataRequest(exampleValue, properties));
|
|
173
|
+
postDataParams = objectToHarParams(getDataRequest(exampleValue, properties));
|
|
174
|
+
break;
|
|
175
|
+
default:
|
|
176
|
+
textPostData = String(exampleValue || '');
|
|
177
|
+
}
|
|
178
|
+
const postData = textPostData
|
|
179
|
+
? {
|
|
180
|
+
mimeType: activeMimeType?.name || MediaTypes.OCTET_STREAM,
|
|
181
|
+
text: textPostData,
|
|
182
|
+
params: postDataParams,
|
|
183
|
+
}
|
|
184
|
+
: undefined;
|
|
185
|
+
const allResponseCodes = operation.responses.map((response) => response.code);
|
|
186
|
+
return {
|
|
187
|
+
method: operation.httpVerb,
|
|
188
|
+
url,
|
|
189
|
+
httpVersion: 'HTTP/1.1',
|
|
190
|
+
cookies: cookies,
|
|
191
|
+
headers: headers,
|
|
192
|
+
queryString: queryParams,
|
|
193
|
+
postData,
|
|
194
|
+
headersSize: -1,
|
|
195
|
+
bodySize: -1,
|
|
196
|
+
securityOAuth2ExtraCalls,
|
|
197
|
+
basicAuth,
|
|
198
|
+
pathParameters,
|
|
199
|
+
serverVariables: environment,
|
|
200
|
+
allResponseCodes,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const defaultOptions = { withImports: true, withComments: false };
|
|
204
|
+
// Map language to 'httpsnippet' library target code
|
|
205
|
+
const langToSnippetConfig = {
|
|
206
|
+
curl: {
|
|
207
|
+
code: 'shell',
|
|
208
|
+
defaultTarget: 'curl',
|
|
209
|
+
defaultOptions: { ...defaultOptions, short: true },
|
|
210
|
+
},
|
|
211
|
+
JavaScript: {
|
|
212
|
+
code: 'javascript',
|
|
213
|
+
defaultTarget: 'fetch',
|
|
214
|
+
defaultOptions: {
|
|
215
|
+
...defaultOptions,
|
|
216
|
+
withImports: false,
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
'Node.js': {
|
|
220
|
+
code: 'node',
|
|
221
|
+
defaultTarget: 'fetch',
|
|
222
|
+
defaultOptions: { ...defaultOptions },
|
|
223
|
+
},
|
|
224
|
+
Python: {
|
|
225
|
+
code: 'python',
|
|
226
|
+
defaultTarget: 'requests',
|
|
227
|
+
defaultOptions: { ...defaultOptions },
|
|
228
|
+
},
|
|
229
|
+
'Java8+Apache': {
|
|
230
|
+
code: 'java8',
|
|
231
|
+
defaultTarget: 'apachehttp',
|
|
232
|
+
defaultOptions: { ...defaultOptions },
|
|
233
|
+
},
|
|
234
|
+
Java: {
|
|
235
|
+
code: 'java',
|
|
236
|
+
defaultTarget: 'httpclient',
|
|
237
|
+
defaultOptions: { ...defaultOptions },
|
|
238
|
+
},
|
|
239
|
+
'C#': {
|
|
240
|
+
code: 'csharp',
|
|
241
|
+
defaultTarget: 'httpclient',
|
|
242
|
+
defaultOptions: { ...defaultOptions },
|
|
243
|
+
},
|
|
244
|
+
'C#+Newtonsoft': {
|
|
245
|
+
code: 'csharpNewtonsoft',
|
|
246
|
+
defaultTarget: 'httpclient',
|
|
247
|
+
defaultOptions: { ...defaultOptions },
|
|
248
|
+
},
|
|
249
|
+
Go: {
|
|
250
|
+
code: 'go',
|
|
251
|
+
defaultTarget: 'http.DefaultClient',
|
|
252
|
+
defaultOptions: { ...defaultOptions },
|
|
253
|
+
},
|
|
254
|
+
PHP: {
|
|
255
|
+
code: 'php',
|
|
256
|
+
defaultTarget: 'curl',
|
|
257
|
+
defaultOptions: { ...defaultOptions },
|
|
258
|
+
},
|
|
259
|
+
Ruby: {
|
|
260
|
+
code: 'ruby',
|
|
261
|
+
defaultTarget: 'net::http',
|
|
262
|
+
defaultOptions: { ...defaultOptions },
|
|
263
|
+
},
|
|
264
|
+
R: {
|
|
265
|
+
code: 'r',
|
|
266
|
+
defaultTarget: 'httr',
|
|
267
|
+
defaultOptions: { ...defaultOptions },
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
export function getCodeSample({ lang, operation, exampleName, pathParams, properties, options = {}, environment, translate, }) {
|
|
271
|
+
try {
|
|
272
|
+
const { skipOptionalParameters, withOAuth2Call, spec, generatedPayloadSamplesMaxDepth, store: operationStore, activeMimeName, } = options;
|
|
273
|
+
const har = mapOperationToHAR(operation, {
|
|
274
|
+
exampleName,
|
|
275
|
+
pathParams,
|
|
276
|
+
properties,
|
|
277
|
+
skipOptionalParameters,
|
|
278
|
+
withOAuth2Call,
|
|
279
|
+
spec,
|
|
280
|
+
generatedPayloadSamplesMaxDepth,
|
|
281
|
+
activeMimeName,
|
|
282
|
+
}, {
|
|
283
|
+
environment,
|
|
284
|
+
requestValues: operationStore.requestValues,
|
|
285
|
+
activeSecuritySchemeIds: operationStore.activeSecuritySchemeIds,
|
|
286
|
+
});
|
|
287
|
+
const snippet = new HTTPSnippet(har);
|
|
288
|
+
if (!langToSnippetConfig[lang]) {
|
|
289
|
+
return translate('openapi.unsupportedLanguage', 'Language is not supported.');
|
|
290
|
+
}
|
|
291
|
+
return snippet.convert(langToSnippetConfig[lang].code, langToSnippetConfig[lang].defaultTarget, {
|
|
292
|
+
...langToSnippetConfig[lang].defaultOptions,
|
|
293
|
+
...options,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
catch (e) {
|
|
297
|
+
console.error(e);
|
|
298
|
+
return translate('openapi.failedToGenerateCodeSample', 'Failed to generate code sample.');
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function getSecurityData(requirement, withOAuth2Call, environment) {
|
|
302
|
+
const securityData = {
|
|
303
|
+
securityHeaders: [],
|
|
304
|
+
securityCookies: [],
|
|
305
|
+
securityQueries: [],
|
|
306
|
+
securityOAuth2ExtraCalls: [],
|
|
307
|
+
basicAuth: undefined,
|
|
308
|
+
};
|
|
309
|
+
const serverUrl = environment?.server;
|
|
310
|
+
for (const scheme of requirement?.schemes || []) {
|
|
311
|
+
const authDetails = getSecurityDetails(scheme.id, environment);
|
|
312
|
+
const serverCredentials = serverUrl && scheme.serverValues && scheme.serverValues[serverUrl];
|
|
313
|
+
const operationSecurityValue = {
|
|
314
|
+
access_token: serverCredentials?.['x-defaultAccessToken'] || scheme['x-defaultAccessToken'],
|
|
315
|
+
token_type: serverCredentials?.['x-defaultTokenType'] || scheme['x-defaultTokenType'],
|
|
316
|
+
client_id: serverCredentials?.['x-defaultClientId'] || scheme['x-defaultClientId'],
|
|
317
|
+
client_secret: serverCredentials?.['x-defaultClientSecret'] || scheme['x-defaultClientSecret'],
|
|
318
|
+
};
|
|
319
|
+
const operationUsername = serverCredentials?.['x-defaultUsername'] || scheme['x-defaultUsername'];
|
|
320
|
+
const operationPassword = serverCredentials?.['x-defaultPassword'] || scheme['x-defaultPassword'];
|
|
321
|
+
const operationScopes = serverCredentials && 'scopes' in serverCredentials
|
|
322
|
+
? serverCredentials.scopes || []
|
|
323
|
+
: scheme.scopes || [];
|
|
324
|
+
switch (scheme.type) {
|
|
325
|
+
case 'openIdConnect':
|
|
326
|
+
securityData.securityHeaders?.push({
|
|
327
|
+
name: 'Authorization',
|
|
328
|
+
value: operationSecurityValue.access_token
|
|
329
|
+
? `${operationSecurityValue.token_type || 'Bearer'} ${operationSecurityValue.access_token}`
|
|
330
|
+
: authDetails.token
|
|
331
|
+
? `${operationSecurityValue.token_type || authDetails.token.token_type || 'Bearer'} ${authDetails.token.access_token}`
|
|
332
|
+
: 'Bearer <YOUR_TOKEN_HERE>',
|
|
333
|
+
});
|
|
334
|
+
break;
|
|
335
|
+
case 'oauth2': {
|
|
336
|
+
const authTokenValue = operationSecurityValue.access_token
|
|
337
|
+
? `${operationSecurityValue.token_type || 'Bearer'} ${operationSecurityValue.access_token}`
|
|
338
|
+
: authDetails.token
|
|
339
|
+
? `${authDetails.token.token_type || 'Bearer'} ${authDetails.token.access_token}`
|
|
340
|
+
: 'Bearer <YOUR_TOKEN_HERE>';
|
|
341
|
+
if (scheme.flows.clientCredentials && withOAuth2Call) {
|
|
342
|
+
securityData.securityOAuth2ExtraCalls.push(getOAuth2ClientCredsCallHar(scheme.flows.clientCredentials, operationScopes, {
|
|
343
|
+
...authDetails,
|
|
344
|
+
client_id: operationSecurityValue.client_id || authDetails.client_id,
|
|
345
|
+
client_secret: operationSecurityValue.client_secret || authDetails.client_secret,
|
|
346
|
+
}));
|
|
347
|
+
}
|
|
348
|
+
else if (scheme.flows.password && withOAuth2Call) {
|
|
349
|
+
securityData.securityOAuth2ExtraCalls.push(getOAuth2PasswordCallHar(scheme.flows.password, operationScopes, {
|
|
350
|
+
...authDetails,
|
|
351
|
+
client_id: operationSecurityValue.client_id || authDetails.client_id,
|
|
352
|
+
client_secret: operationSecurityValue.client_secret || authDetails.client_secret,
|
|
353
|
+
}));
|
|
354
|
+
}
|
|
355
|
+
securityData.securityHeaders?.push({ name: 'Authorization', value: authTokenValue });
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
case 'apiKey': {
|
|
359
|
+
const value = operationSecurityValue.access_token || authDetails.raw || 'YOUR_API_KEY_HERE';
|
|
360
|
+
if (scheme.in === 'header') {
|
|
361
|
+
securityData.securityHeaders?.push({
|
|
362
|
+
name: scheme.name,
|
|
363
|
+
value,
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
if (scheme.in === 'cookie') {
|
|
367
|
+
securityData.securityCookies.push({
|
|
368
|
+
name: scheme.name,
|
|
369
|
+
value,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
if (scheme.in === 'query') {
|
|
373
|
+
securityData.securityQueries.push({
|
|
374
|
+
name: scheme.name,
|
|
375
|
+
value,
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
case 'http':
|
|
381
|
+
if (scheme.scheme === 'basic') {
|
|
382
|
+
securityData.basicAuth = {
|
|
383
|
+
username: operationUsername ||
|
|
384
|
+
authDetails.username ||
|
|
385
|
+
`<${StringUtility.toSnakeCase('Username')}>`,
|
|
386
|
+
password: operationPassword ||
|
|
387
|
+
authDetails.password ||
|
|
388
|
+
`<${StringUtility.toSnakeCase('Password')}>`,
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
const token = operationSecurityValue?.access_token ||
|
|
393
|
+
authDetails.token?.access_token ||
|
|
394
|
+
`<YOUR_${scheme.bearerFormat || 'TOKEN'}_HERE>`;
|
|
395
|
+
securityData.securityHeaders?.push({
|
|
396
|
+
name: 'Authorization',
|
|
397
|
+
value: `${capitalizeFirst(scheme.scheme || 'bearer')} ${token}`,
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return securityData;
|
|
404
|
+
}
|
|
405
|
+
function getOAuth2PasswordCallHar(flow, scopes, authDetails) {
|
|
406
|
+
return {
|
|
407
|
+
method: 'POST',
|
|
408
|
+
url: flow.tokenUrl,
|
|
409
|
+
httpVersion: 'HTTP/1.1',
|
|
410
|
+
headers: [
|
|
411
|
+
{ name: 'Content-Type', value: MediaTypes.URL_ENCODED },
|
|
412
|
+
{ name: 'Accept', value: MediaTypes.JSON },
|
|
413
|
+
],
|
|
414
|
+
queryString: [],
|
|
415
|
+
postData: {
|
|
416
|
+
mimeType: MediaTypes.URL_ENCODED,
|
|
417
|
+
text: '',
|
|
418
|
+
params: [
|
|
419
|
+
{ name: 'grant_type', value: 'password' },
|
|
420
|
+
{ name: 'client_id', value: authDetails.client_id || 'YOUR_CLIENT_ID' },
|
|
421
|
+
{ name: 'client_secret', value: authDetails.client_secret || 'YOUR_CLIENT_SECRET' },
|
|
422
|
+
{ name: 'username', value: authDetails.username || '<username>' },
|
|
423
|
+
{ name: 'password', value: authDetails.password || '<password>' },
|
|
424
|
+
scopes.length ? { name: 'scope', value: scopes.join(' ') } : undefined,
|
|
425
|
+
].filter(isDefined),
|
|
426
|
+
},
|
|
427
|
+
cookies: [],
|
|
428
|
+
headersSize: -1,
|
|
429
|
+
bodySize: -1,
|
|
430
|
+
securityOAuth2ExtraCalls: [],
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function getOAuth2ClientCredsCallHar(flow, scopes, authDetails) {
|
|
434
|
+
return {
|
|
435
|
+
method: 'POST',
|
|
436
|
+
url: flow.tokenUrl,
|
|
437
|
+
httpVersion: 'HTTP/1.1',
|
|
438
|
+
headers: [
|
|
439
|
+
{ name: 'Content-Type', value: MediaTypes.URL_ENCODED },
|
|
440
|
+
{ name: 'Accept', value: MediaTypes.JSON },
|
|
441
|
+
],
|
|
442
|
+
queryString: [],
|
|
443
|
+
postData: {
|
|
444
|
+
mimeType: MediaTypes.URL_ENCODED,
|
|
445
|
+
text: '',
|
|
446
|
+
params: [
|
|
447
|
+
{ name: 'grant_type', value: 'client_credentials' },
|
|
448
|
+
{ name: 'client_id', value: authDetails.client_id || 'YOUR_CLIENT_ID' },
|
|
449
|
+
{ name: 'client_secret', value: authDetails.client_secret || 'YOUR_CLIENT_SECRET' },
|
|
450
|
+
scopes.length ? { name: 'scope', value: scopes.join(' ') } : undefined,
|
|
451
|
+
].filter(isDefined),
|
|
452
|
+
},
|
|
453
|
+
cookies: [],
|
|
454
|
+
headersSize: -1,
|
|
455
|
+
bodySize: -1,
|
|
456
|
+
securityOAuth2ExtraCalls: [],
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
export function getDataRequest(exampleValue, properties) {
|
|
460
|
+
if (exampleValue) {
|
|
461
|
+
if (isObject(exampleValue)) {
|
|
462
|
+
if (Object.keys(exampleValue).length > 0 && Object.keys(properties).length === 0) {
|
|
463
|
+
return exampleValue;
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
return merge(exampleValue, properties, { arrayMerge: arrayMergeStrategy });
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
try {
|
|
470
|
+
return merge(JSON.parse(exampleValue), properties, { arrayMerge: arrayMergeStrategy });
|
|
471
|
+
}
|
|
472
|
+
catch {
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
function objectToHarParams(obj, parentKey = '') {
|
|
479
|
+
const res = [];
|
|
480
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
481
|
+
const currentKey = parentKey ? `${parentKey}[${key}]` : key;
|
|
482
|
+
if (typeof value === 'object' && value !== null) {
|
|
483
|
+
res.push(...objectToHarParams(value, currentKey));
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
const name = Array.isArray(obj) && typeof value === 'string' && parentKey ? parentKey : currentKey;
|
|
487
|
+
res.push({ name, value: String(value) });
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return res;
|
|
491
|
+
}
|
|
492
|
+
export function isDefined(arg) {
|
|
493
|
+
return arg !== undefined;
|
|
494
|
+
}
|
|
495
|
+
export function capitalizeFirst(str) {
|
|
496
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
497
|
+
}
|
|
498
|
+
function populateXmlSchemaFields(schema, values) {
|
|
499
|
+
if (!schema || typeof schema !== 'object' || !values || typeof values !== 'object') {
|
|
500
|
+
return schema;
|
|
501
|
+
}
|
|
502
|
+
const updatedSchema = JSON.parse(JSON.stringify(schema));
|
|
503
|
+
function populateValues(schemaNode, valueNode) {
|
|
504
|
+
if (!schemaNode ||
|
|
505
|
+
!valueNode ||
|
|
506
|
+
typeof schemaNode !== 'object' ||
|
|
507
|
+
typeof valueNode !== 'object') {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
if (schemaNode.properties) {
|
|
511
|
+
for (const propName in schemaNode.properties) {
|
|
512
|
+
if (valueNode[propName] !== undefined) {
|
|
513
|
+
const propSchema = schemaNode.properties[propName];
|
|
514
|
+
const propValue = valueNode[propName];
|
|
515
|
+
if (propSchema.type === 'object' &&
|
|
516
|
+
typeof propValue === 'object' &&
|
|
517
|
+
!Array.isArray(propValue)) {
|
|
518
|
+
populateValues(propSchema, propValue);
|
|
519
|
+
}
|
|
520
|
+
else if (propSchema.type === 'array' &&
|
|
521
|
+
Array.isArray(propValue) &&
|
|
522
|
+
propValue.length > 0) {
|
|
523
|
+
// For arrays, use the first item from values array to update item examples
|
|
524
|
+
const firstItem = propValue[0];
|
|
525
|
+
if (propSchema.items && propSchema.items.properties) {
|
|
526
|
+
populateValues(propSchema.items, firstItem);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
propSchema.example = propValue;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
// If value doesn't exist for this property, just skip it (keep original example)
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
populateValues(updatedSchema, values);
|
|
538
|
+
return updatedSchema;
|
|
539
|
+
}
|
|
540
|
+
//# sourceMappingURL=generator.js.map
|