@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,2 +1,223 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { CodeBuilder } from '../../helpers/code-builder.js';
|
|
2
|
+
import { HTTPSnippet } from '../../index.js';
|
|
3
|
+
import { isEmptyObject, normalizeMimeType } from '../../../../utils.js';
|
|
4
|
+
import { capitalizeFirst } from '../../../generator.js';
|
|
5
|
+
import { Lang } from '../../helpers/constants.js';
|
|
6
|
+
import { buildUrlExpression, printUrlVariablesDeclarations } from '../../helpers/code-helpers.js';
|
|
7
|
+
import { MediaTypes } from '../../../../../constants.js';
|
|
8
|
+
const handler = function (source, originalOptions, { target, client }) {
|
|
9
|
+
const options = Object.assign({ indent: ' ', withWrapper: true }, originalOptions);
|
|
10
|
+
const code = new CodeBuilder({
|
|
11
|
+
indentation: options.indent,
|
|
12
|
+
variablesPrefix: options.variablesPrefix,
|
|
13
|
+
capitalize: true,
|
|
14
|
+
lang: Lang.JAVA8,
|
|
15
|
+
});
|
|
16
|
+
const methodFormatted = formatHttpMethod(source.method);
|
|
17
|
+
if (options.withComments) {
|
|
18
|
+
addComments(code);
|
|
19
|
+
}
|
|
20
|
+
if (options.withImports) {
|
|
21
|
+
addImports(code, source);
|
|
22
|
+
}
|
|
23
|
+
if (options.withWrapper) {
|
|
24
|
+
code.push('public class App {');
|
|
25
|
+
code.push(1, 'public static void main(String[] args ) throws java.io.IOException {');
|
|
26
|
+
code.push(2, 'HttpClient httpClient = HttpClientBuilder.create().build();');
|
|
27
|
+
code.blank();
|
|
28
|
+
}
|
|
29
|
+
if (source.securityOAuth2ExtraCalls?.length) {
|
|
30
|
+
const oAuth2PrefixCode = new HTTPSnippet(source.securityOAuth2ExtraCalls?.[0]).convert(target, client, {
|
|
31
|
+
...options,
|
|
32
|
+
withImports: false,
|
|
33
|
+
withWrapper: false,
|
|
34
|
+
withComments: false,
|
|
35
|
+
variablesPrefix: 'oauth2',
|
|
36
|
+
});
|
|
37
|
+
code.push(oAuth2PrefixCode);
|
|
38
|
+
code.push(2, 'JSONObject %s = new JSONObject(EntityUtils.toString(httpClient.execute(%s).getEntity()));', 'oauth2Response', 'oauth2Request');
|
|
39
|
+
code.push(2, 'String accessToken = %s.getString("access_token");', 'oauth2Response');
|
|
40
|
+
code.blank();
|
|
41
|
+
}
|
|
42
|
+
printUrlVariablesDeclarations(source, code, 2);
|
|
43
|
+
const URL = buildUrlExpression(source, code);
|
|
44
|
+
code.push(2, `%s ${code.var('request')} = new %s(%s);`, methodFormatted, methodFormatted, URL);
|
|
45
|
+
const headers = Object.keys(source.allHeaders);
|
|
46
|
+
if (headers.length && !(source.postData && source.postData.mimeType == MediaTypes.MULTIPART)) {
|
|
47
|
+
headers.forEach((key) => {
|
|
48
|
+
code.push(2, '%s.setHeader("%s", %s);', code.var('request'), key, source.securityOAuth2ExtraCalls?.length
|
|
49
|
+
? '"Bearer " + accessToken'
|
|
50
|
+
: `"${source.allHeaders[key]}"`);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (source.basicAuth) {
|
|
54
|
+
const { username, password } = source.basicAuth;
|
|
55
|
+
code.push(2, `String encodedString = Base64.getEncoder().encodeToString("${username}:${password}".getBytes());`);
|
|
56
|
+
code.push(2, '%s.setHeader("%s", "%s"+encodedString);', code.var('request'), 'Authorization', 'Basic ');
|
|
57
|
+
}
|
|
58
|
+
if (source.postData) {
|
|
59
|
+
switch (normalizeMimeType(source.postData.mimeType)) {
|
|
60
|
+
case MediaTypes.URL_ENCODED:
|
|
61
|
+
if (source.postData.params) {
|
|
62
|
+
code.blank();
|
|
63
|
+
code.push(2, 'List<NameValuePair> params = new ArrayList<NameValuePair>();');
|
|
64
|
+
source.postData.params.forEach((param) => {
|
|
65
|
+
code.push(2, 'params.add(new BasicNameValuePair("%s", "%s"));', param.name, param.value);
|
|
66
|
+
});
|
|
67
|
+
code.push(2, '%s.setEntity(new UrlEncodedFormEntity(params));', code.var('request'));
|
|
68
|
+
code.blank();
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
case MediaTypes.MULTIPART:
|
|
72
|
+
if (source.postData.params) {
|
|
73
|
+
code.push(2, 'MultipartEntity reqEntity = new MultipartEntity();');
|
|
74
|
+
source.postData.params.forEach((param) => {
|
|
75
|
+
code.push(2, 'reqEntity.addPart("%s", %s);', param.name, isString(param.value) ? `new StringBody("${param.value}")` : param.value);
|
|
76
|
+
});
|
|
77
|
+
code.push(2, '%s.setEntity(reqEntity);', code.var('request'));
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
case MediaTypes.JSON:
|
|
81
|
+
if (source.postData.jsonObj) {
|
|
82
|
+
code.push(2, 'JSONObject payload = new JSONObject();');
|
|
83
|
+
for (const [key, value] of Object.entries(source.postData.jsonObj)) {
|
|
84
|
+
if (Array.isArray(value)) {
|
|
85
|
+
code.push(2, 'payload.put("%s", new JSONArray()', key);
|
|
86
|
+
value.forEach((item) => {
|
|
87
|
+
if (isObject(item)) {
|
|
88
|
+
code.push(3, '.put(new JSONObject()');
|
|
89
|
+
iterateObject(item, 4);
|
|
90
|
+
code.push(3, ')');
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
code.push(3, '.put(%s)', formatValue(item));
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
code.push(2, ');');
|
|
97
|
+
}
|
|
98
|
+
else if (isObject(value)) {
|
|
99
|
+
code.push(2, 'payload.put("%s", new JSONObject()%s', key, isEmptyObject(value) ? ');' : '');
|
|
100
|
+
iterateObject(value, 3);
|
|
101
|
+
if (!isEmptyObject(value)) {
|
|
102
|
+
code.push(2, ');');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
code.push(2, 'payload.put("%s", %s);', key, formatValue(value));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
code.push(2, '%s.setEntity(new StringEntity(payload.toString()));', code.var('request'));
|
|
110
|
+
}
|
|
111
|
+
break;
|
|
112
|
+
case MediaTypes.XML:
|
|
113
|
+
if (source.postData.text) {
|
|
114
|
+
code.push(2, 'String payload = String.join("\\n"');
|
|
115
|
+
source.postData.text
|
|
116
|
+
.trim()
|
|
117
|
+
.split('\n')
|
|
118
|
+
.forEach((item) => {
|
|
119
|
+
const line = item.replace(/"/g, '\\"');
|
|
120
|
+
code.push(3, `"${line}", `);
|
|
121
|
+
});
|
|
122
|
+
code.push(2, ');');
|
|
123
|
+
code.push(2, '%s.setEntity(new StringEntity(payload));', code.var('request'));
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// TODO: Add default case to handle unsupported mimeType or data type
|
|
129
|
+
if (options.withWrapper) {
|
|
130
|
+
code.push(2, `String ${code.var('response')} = EntityUtils.toString(httpClient.execute(request).getEntity());`);
|
|
131
|
+
code.blank();
|
|
132
|
+
code.push(2, 'System.out.println(response);');
|
|
133
|
+
code.push(1, '}');
|
|
134
|
+
code.push('}');
|
|
135
|
+
}
|
|
136
|
+
return code.join();
|
|
137
|
+
function iterateObject(obj, indent) {
|
|
138
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
139
|
+
if (isObject(value)) {
|
|
140
|
+
code.push(indent, '.put("%s", new JSONObject()', key);
|
|
141
|
+
iterateObject(value, indent + 1);
|
|
142
|
+
code.push(indent, ')');
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
code.push(indent, '.put("%s", %s)', key, formatValue(value));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
export const info = {
|
|
151
|
+
key: 'apachehttp',
|
|
152
|
+
title: 'Apache http',
|
|
153
|
+
link: 'https://hc.apache.org/httpcomponents-client-4.5.x/',
|
|
154
|
+
description: 'Apache HttpClient',
|
|
155
|
+
};
|
|
156
|
+
export default handler;
|
|
157
|
+
function addComments(code) {
|
|
158
|
+
code.push('/**');
|
|
159
|
+
code.push(' * Requires JDK >= 8');
|
|
160
|
+
code.push(' *');
|
|
161
|
+
code.push(' * Requires Apache HttpComponents Client >= 4.3.5');
|
|
162
|
+
code.push(' * See here for installation details:');
|
|
163
|
+
code.push(' * https://search.maven.org/artifact/org.apache.httpcomponents/httpcomponents-client');
|
|
164
|
+
code.push(' *');
|
|
165
|
+
code.push(' * Requires package "junit4"');
|
|
166
|
+
code.push(' * See here for installation details:');
|
|
167
|
+
code.push(' * https://junit.org/junit4');
|
|
168
|
+
code.push(' *');
|
|
169
|
+
code.push(' * Requires package "org.json" >= 20180130');
|
|
170
|
+
code.push(' * See here for installation details:');
|
|
171
|
+
code.push(' * https://search.maven.org/artifact/org.json/json');
|
|
172
|
+
code.push(' */');
|
|
173
|
+
code.blank();
|
|
174
|
+
}
|
|
175
|
+
function addImports(code, source) {
|
|
176
|
+
code.push('import org.apache.http.util.EntityUtils;');
|
|
177
|
+
code.push('import org.apache.http.NameValuePair;');
|
|
178
|
+
code.push('import org.apache.http.client.HttpClient;');
|
|
179
|
+
code.push('import org.apache.http.client.entity.UrlEncodedFormEntity;');
|
|
180
|
+
if (source.method) {
|
|
181
|
+
addHttpMethodImport(code, source.method);
|
|
182
|
+
}
|
|
183
|
+
if (source.securityOAuth2ExtraCalls?.length &&
|
|
184
|
+
source.securityOAuth2ExtraCalls?.[0].method.toLowerCase() !== source.method.toLowerCase()) {
|
|
185
|
+
addHttpMethodImport(code, source.securityOAuth2ExtraCalls?.[0].method);
|
|
186
|
+
}
|
|
187
|
+
code.push('import org.apache.http.impl.client.HttpClientBuilder;');
|
|
188
|
+
code.push('import org.apache.http.message.BasicNameValuePair;');
|
|
189
|
+
code.push('import org.apache.http.entity.StringEntity;');
|
|
190
|
+
code.push('import org.json.JSONObject;');
|
|
191
|
+
code.push('import org.json.JSONArray;');
|
|
192
|
+
code.push('import java.util.ArrayList;');
|
|
193
|
+
code.push('import java.util.List;');
|
|
194
|
+
code.push('import org.apache.http.entity.mime.MultipartEntity;');
|
|
195
|
+
code.push('import org.apache.http.entity.mime.content.StringBody;');
|
|
196
|
+
if (source.basicAuth) {
|
|
197
|
+
code.push('import java.util.Base64;');
|
|
198
|
+
}
|
|
199
|
+
code.blank();
|
|
200
|
+
}
|
|
201
|
+
function addHttpMethodImport(code, method) {
|
|
202
|
+
const methodFormatted = formatHttpMethod(method);
|
|
203
|
+
code.push(`import org.apache.http.client.methods.${methodFormatted};`);
|
|
204
|
+
}
|
|
205
|
+
function formatHttpMethod(method) {
|
|
206
|
+
return 'Http' + capitalizeFirst(method.toLowerCase());
|
|
207
|
+
}
|
|
208
|
+
function isString(str) {
|
|
209
|
+
return Object.prototype.toString.call(str) === '[object String]';
|
|
210
|
+
}
|
|
211
|
+
function isObject(obj) {
|
|
212
|
+
const type = typeof obj;
|
|
213
|
+
return type === 'function' || (type === 'object' && !!obj);
|
|
214
|
+
}
|
|
215
|
+
function formatValue(value) {
|
|
216
|
+
if (isString(value))
|
|
217
|
+
return JSON.stringify(value);
|
|
218
|
+
else if (value == null)
|
|
219
|
+
return 'JSONObject.NULL';
|
|
220
|
+
else
|
|
221
|
+
return value;
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=apachehttp.js.map
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import apachehttp from './apachehttp.js';
|
|
2
|
+
export default {
|
|
3
|
+
info: {
|
|
4
|
+
key: 'java8',
|
|
5
|
+
title: 'Java8+Apache',
|
|
6
|
+
extname: '.java',
|
|
7
|
+
default: 'apachehttp',
|
|
8
|
+
},
|
|
9
|
+
apachehttp,
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,147 @@
|
|
|
1
|
-
import
|
|
1
|
+
import stringifyObject from 'stringify-object';
|
|
2
|
+
import { CodeBuilder } from '../../helpers/code-builder.js';
|
|
3
|
+
import { addIndentation, getPreserveTransformer, buildUrlExpression, printUrlVariablesDeclarations, } from '../../helpers/code-helpers.js';
|
|
4
|
+
import { normalizeMimeType } from '../../../../utils.js';
|
|
5
|
+
import { HTTPSnippet } from '../../index.js';
|
|
6
|
+
import { Lang } from '../../helpers/constants.js';
|
|
7
|
+
import { MediaTypes } from '../../../../../constants.js';
|
|
8
|
+
const handler = function (source, originalOptions, { target, client }) {
|
|
9
|
+
const options = {
|
|
10
|
+
indent: ' ',
|
|
11
|
+
credentials: null,
|
|
12
|
+
...originalOptions,
|
|
13
|
+
};
|
|
14
|
+
const code = new CodeBuilder({
|
|
15
|
+
indentation: options.indent,
|
|
16
|
+
variablesPrefix: options.variablesPrefix,
|
|
17
|
+
capitalize: true,
|
|
18
|
+
lang: Lang.JAVASCRIPT,
|
|
19
|
+
});
|
|
20
|
+
const reqOpts = {
|
|
21
|
+
method: source.method.toUpperCase(),
|
|
22
|
+
};
|
|
23
|
+
// TODO: Should we also add cookies here (like in node.js fetch)?
|
|
24
|
+
if (Object.keys(source.headersObj).length) {
|
|
25
|
+
reqOpts.headers = source.headersObj;
|
|
26
|
+
}
|
|
27
|
+
let preserverOriginalAuthorizationHeader = false;
|
|
28
|
+
if (options.withComments) {
|
|
29
|
+
addComments(code);
|
|
30
|
+
}
|
|
31
|
+
if (source.securityOAuth2ExtraCalls?.length) {
|
|
32
|
+
const oAuth2PrefixCode = new HTTPSnippet(source.securityOAuth2ExtraCalls?.[0]).convert(target, client, { ...options, withImports: false, withComments: false, variablesPrefix: 'oAuth2' });
|
|
33
|
+
code.push(oAuth2PrefixCode);
|
|
34
|
+
code.blank();
|
|
35
|
+
reqOpts.headers = reqOpts.headers || {};
|
|
36
|
+
reqOpts.headers.Authorization = `'Bearer ' + oAuth2Data.access_token`;
|
|
37
|
+
preserverOriginalAuthorizationHeader = true;
|
|
38
|
+
}
|
|
39
|
+
if (options.credentials !== null) {
|
|
40
|
+
reqOpts.credentials = options.credentials;
|
|
41
|
+
}
|
|
42
|
+
const hasQueryVariables = Object.getOwnPropertyNames(source.queryObj).length;
|
|
43
|
+
if (hasQueryVariables) {
|
|
44
|
+
code
|
|
45
|
+
.push(`const ${code.var('query')} = new URLSearchParams(${stringifyObject(source.queryObj, {
|
|
46
|
+
indent: options.indent,
|
|
47
|
+
inlineCharacterLimit: 25,
|
|
48
|
+
})}).toString();`)
|
|
49
|
+
.blank();
|
|
50
|
+
}
|
|
51
|
+
if (source.postData) {
|
|
52
|
+
switch (normalizeMimeType(source.postData.mimeType)) {
|
|
53
|
+
case MediaTypes.URL_ENCODED:
|
|
54
|
+
reqOpts.body = source.postData.paramsObj
|
|
55
|
+
? `new URLSearchParams(${code.var('formData')}).toString()`
|
|
56
|
+
: source.postData.text;
|
|
57
|
+
if (source.postData.paramsObj) {
|
|
58
|
+
code
|
|
59
|
+
.push(`const ${code.var('formData')} = ${addIndentation(stringifyObject(source.postData.paramsObj, {
|
|
60
|
+
indent: options.indent,
|
|
61
|
+
inlineCharacterLimit: 25,
|
|
62
|
+
}), { level: 0, firstLine: false })};`)
|
|
63
|
+
.blank();
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case MediaTypes.JSON:
|
|
67
|
+
if (source.postData.jsonObj) {
|
|
68
|
+
reqOpts.body = `JSON.stringify(${addIndentation(stringifyObject(source.postData.jsonObj, {
|
|
69
|
+
indent: options.indent,
|
|
70
|
+
inlineCharacterLimit: 25,
|
|
71
|
+
}), { level: 1, firstLine: false })})`;
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
// TODO: handle this mime type corectly!
|
|
75
|
+
case MediaTypes.MULTIPART:
|
|
76
|
+
code.push(`const ${code.var('form')} = new FormData();`);
|
|
77
|
+
// Content type with boundary should be set automatically
|
|
78
|
+
delete reqOpts?.headers?.['Content-Type'];
|
|
79
|
+
source.postData.params.forEach(function (param) {
|
|
80
|
+
code.push(`${code.var('form')}.append(%s, %s);`, JSON.stringify(param.name), JSON.stringify(param.value || param.fileName || ''));
|
|
81
|
+
});
|
|
82
|
+
reqOpts.body = code.var('form');
|
|
83
|
+
code.blank();
|
|
84
|
+
break;
|
|
85
|
+
default:
|
|
86
|
+
if (source.postData.text) {
|
|
87
|
+
reqOpts.body = `\`${addIndentation(source.postData.text, {
|
|
88
|
+
level: 2,
|
|
89
|
+
indent: options.indent,
|
|
90
|
+
firstLine: false,
|
|
91
|
+
}).trim()}\``;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const isJSON = (reqOpts.headers &&
|
|
96
|
+
reqOpts.headers.Accept &&
|
|
97
|
+
normalizeMimeType(reqOpts.headers.Accept) === MediaTypes.JSON) ||
|
|
98
|
+
normalizeMimeType(source.postData?.mimeType) === MediaTypes.JSON;
|
|
99
|
+
if (source.basicAuth) {
|
|
100
|
+
const { username, password } = source.basicAuth;
|
|
101
|
+
reqOpts.headers = reqOpts.headers || {};
|
|
102
|
+
reqOpts.headers.Authorization = `'Basic ' + btoa('${username}:${password}')`;
|
|
103
|
+
preserverOriginalAuthorizationHeader = true;
|
|
104
|
+
}
|
|
105
|
+
printUrlVariablesDeclarations(source, code);
|
|
106
|
+
const URL = buildUrlExpression(source, code);
|
|
107
|
+
code
|
|
108
|
+
.push(`const ${code.var('resp')} = await fetch(`)
|
|
109
|
+
.push(1, '`' + URL + (hasQueryVariables ? '?${' + code.var('query') + '}' : '') + '`,')
|
|
110
|
+
.push(addIndentation(stringifyObject(reqOpts, {
|
|
111
|
+
indent: options.indent,
|
|
112
|
+
inlineCharacterLimit: 25,
|
|
113
|
+
transform: getPreserveTransformer({
|
|
114
|
+
body: true,
|
|
115
|
+
authorizationHeader: preserverOriginalAuthorizationHeader,
|
|
116
|
+
}),
|
|
117
|
+
}), { level: 1, indent: options.indent }))
|
|
118
|
+
.push(');')
|
|
119
|
+
.blank();
|
|
120
|
+
if (source.allResponseCodes?.includes('204')) {
|
|
121
|
+
code.push(`if (resp.status === 204) {`).push(1, "console.log('success');").push('} else {');
|
|
122
|
+
code
|
|
123
|
+
.push(1, `const ${code.var('data')} = await ${code.var('resp')}.${isJSON ? 'json()' : 'text()'};`)
|
|
124
|
+
.push(1, `console.log(${code.var('data')});`)
|
|
125
|
+
.push('}');
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
code
|
|
129
|
+
.push(`const ${code.var('data')} = await ${code.var('resp')}.${isJSON ? 'json()' : 'text()'};`)
|
|
130
|
+
.push(`console.log(${code.var('data')});`);
|
|
131
|
+
}
|
|
132
|
+
return code.join();
|
|
133
|
+
};
|
|
134
|
+
function addComments(code) {
|
|
135
|
+
code.push('/**');
|
|
136
|
+
code.push(' * Requires ES8-compatible browser: https://caniuse.com/async-functions');
|
|
137
|
+
code.push(' */');
|
|
138
|
+
code.blank();
|
|
139
|
+
}
|
|
140
|
+
export const info = {
|
|
141
|
+
key: 'fetch',
|
|
142
|
+
title: 'fetch',
|
|
143
|
+
link: 'https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch',
|
|
144
|
+
description: 'Perform asynchronous HTTP requests with the Fetch API',
|
|
145
|
+
};
|
|
146
|
+
export default handler;
|
|
147
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fetch from './fetch.js';
|
|
2
|
+
export default {
|
|
3
|
+
info: {
|
|
4
|
+
key: 'javascript',
|
|
5
|
+
title: 'JavaScript',
|
|
6
|
+
extname: '.js',
|
|
7
|
+
default: 'fetch',
|
|
8
|
+
},
|
|
9
|
+
fetch,
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,199 @@
|
|
|
1
|
-
import
|
|
1
|
+
import stringifyObject from 'stringify-object';
|
|
2
|
+
import { CodeBuilder } from '../../helpers/code-builder.js';
|
|
3
|
+
import { addIndentation, getPreserveTransformer, buildUrlExpression, printUrlVariablesDeclarations, } from '../../helpers/code-helpers.js';
|
|
4
|
+
import { Lang } from '../../helpers/constants.js';
|
|
5
|
+
import { normalizeMimeType } from '../../../../utils.js';
|
|
6
|
+
import { HTTPSnippet } from '../../index.js';
|
|
7
|
+
import { MediaTypes } from '../../../../../constants.js';
|
|
8
|
+
const handler = function (source, originalOptions, { target, client }) {
|
|
9
|
+
const options = Object.assign({
|
|
10
|
+
indent: ' ',
|
|
11
|
+
showBoilerplate: true,
|
|
12
|
+
level: 1,
|
|
13
|
+
}, originalOptions);
|
|
14
|
+
const { level } = options;
|
|
15
|
+
let includeFS = false;
|
|
16
|
+
const code = new CodeBuilder({
|
|
17
|
+
indentation: options.indent,
|
|
18
|
+
variablesPrefix: options.variablesPrefix,
|
|
19
|
+
capitalize: true,
|
|
20
|
+
lang: Lang.NODEJS,
|
|
21
|
+
});
|
|
22
|
+
if (options.withComments) {
|
|
23
|
+
addComments(code);
|
|
24
|
+
}
|
|
25
|
+
if (options.withImports) {
|
|
26
|
+
code.push("import fetch from 'node-fetch';");
|
|
27
|
+
code.blank();
|
|
28
|
+
}
|
|
29
|
+
if (options.showBoilerplate) {
|
|
30
|
+
code.push('async function run() {');
|
|
31
|
+
}
|
|
32
|
+
const reqOpts = {
|
|
33
|
+
method: source.method.toUpperCase(),
|
|
34
|
+
};
|
|
35
|
+
if (Object.keys(source.headersObj).length) {
|
|
36
|
+
reqOpts.headers = source.headersObj;
|
|
37
|
+
}
|
|
38
|
+
let preserverOriginalAuthorizationHeader = false;
|
|
39
|
+
if (source.securityOAuth2ExtraCalls?.length) {
|
|
40
|
+
const oAuth2PrefixCode = new HTTPSnippet(source.securityOAuth2ExtraCalls?.[0]).convert(target, client, {
|
|
41
|
+
...options,
|
|
42
|
+
withImports: false,
|
|
43
|
+
withComments: false,
|
|
44
|
+
variablesPrefix: 'oAuth2',
|
|
45
|
+
showBoilerplate: false,
|
|
46
|
+
level: 1,
|
|
47
|
+
});
|
|
48
|
+
code.push(oAuth2PrefixCode);
|
|
49
|
+
code.blank();
|
|
50
|
+
reqOpts.headers = reqOpts.headers || {};
|
|
51
|
+
reqOpts.headers.Authorization = `'Bearer ' + oAuth2Data.access_token`;
|
|
52
|
+
preserverOriginalAuthorizationHeader = true;
|
|
53
|
+
}
|
|
54
|
+
const hasQueryVariables = Object.getOwnPropertyNames(source.queryObj).length;
|
|
55
|
+
if (hasQueryVariables) {
|
|
56
|
+
code
|
|
57
|
+
.push(level, `const ${code.var('query')} = new URLSearchParams(${addIndentation(stringifyObject(source.queryObj, {
|
|
58
|
+
indent: options.indent,
|
|
59
|
+
inlineCharacterLimit: 25,
|
|
60
|
+
}), { level, indent: options.indent, firstLine: false })}).toString();`)
|
|
61
|
+
.blank();
|
|
62
|
+
}
|
|
63
|
+
if (source.postData) {
|
|
64
|
+
switch (normalizeMimeType(source.postData.mimeType)) {
|
|
65
|
+
case MediaTypes.URL_ENCODED:
|
|
66
|
+
reqOpts.body = source.postData.paramsObj
|
|
67
|
+
? `new URLSearchParams(${code.var('formData')}).toString()`
|
|
68
|
+
: source.postData.text;
|
|
69
|
+
if (source.postData.paramsObj) {
|
|
70
|
+
code
|
|
71
|
+
.push(level, `const ${code.var('formData')} = ${addIndentation(stringifyObject(source.postData.paramsObj, {
|
|
72
|
+
indent: options.indent,
|
|
73
|
+
inlineCharacterLimit: 25,
|
|
74
|
+
}), { level, firstLine: false })};`)
|
|
75
|
+
.blank();
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
case MediaTypes.JSON:
|
|
79
|
+
if (source.postData.jsonObj) {
|
|
80
|
+
reqOpts.body = `JSON.stringify(${addIndentation(stringifyObject(source.postData.jsonObj, {
|
|
81
|
+
indent: options.indent,
|
|
82
|
+
inlineCharacterLimit: 25,
|
|
83
|
+
}), { level, firstLine: false })})`;
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
// TODO: handle this mime type corectly!
|
|
87
|
+
case MediaTypes.MULTIPART:
|
|
88
|
+
// Content type with boundary should be set automatically
|
|
89
|
+
delete reqOpts?.headers?.['Content-Type'];
|
|
90
|
+
if (options.withImports) {
|
|
91
|
+
code.unshift("import FormData from 'form-data';");
|
|
92
|
+
}
|
|
93
|
+
code.push(level, `const ${code.var('form')} = new FormData();`);
|
|
94
|
+
source.postData.params.forEach(function (param) {
|
|
95
|
+
if (!param.fileName && !param.fileName && !param.contentType) {
|
|
96
|
+
code.push(level, "form.append('" + param.name + "','" + param.value + "');");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (param.fileName) {
|
|
100
|
+
includeFS = true;
|
|
101
|
+
code.blank();
|
|
102
|
+
code.push(level, `${code.var('form')}.append('" + param.name + "', fs.createReadStream('" + param.fileName + "'));`);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
reqOpts.body = code.var('form');
|
|
106
|
+
code.blank();
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
if (source.postData.text) {
|
|
110
|
+
reqOpts.body = `\`${addIndentation(source.postData.text, {
|
|
111
|
+
level: level + 1,
|
|
112
|
+
indent: options.indent,
|
|
113
|
+
firstLine: false,
|
|
114
|
+
}).trim()}\``;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// construct cookies argument
|
|
119
|
+
if (source.cookies.length) {
|
|
120
|
+
let cookies = '';
|
|
121
|
+
source.cookies.forEach(function (cookie) {
|
|
122
|
+
cookies =
|
|
123
|
+
cookies + encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value) + '; ';
|
|
124
|
+
});
|
|
125
|
+
cookies = cookies.trim();
|
|
126
|
+
if (reqOpts.headers) {
|
|
127
|
+
reqOpts.headers.cookie = cookies;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
reqOpts.headers = {};
|
|
131
|
+
reqOpts.headers.cookie = cookies;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (source.basicAuth) {
|
|
135
|
+
const { username, password } = source.basicAuth;
|
|
136
|
+
reqOpts.headers = reqOpts.headers || {};
|
|
137
|
+
reqOpts.headers.Authorization = `'Basic ' + Buffer.from('${username}:${password}').toString('base64')`;
|
|
138
|
+
preserverOriginalAuthorizationHeader = true;
|
|
139
|
+
}
|
|
140
|
+
if (includeFS && options.withImports) {
|
|
141
|
+
code.unshift("import fs from 'fs';");
|
|
142
|
+
}
|
|
143
|
+
const isJSON = (reqOpts.headers &&
|
|
144
|
+
reqOpts.headers.Accept &&
|
|
145
|
+
normalizeMimeType(reqOpts.headers.Accept) === MediaTypes.JSON) ||
|
|
146
|
+
normalizeMimeType(source.postData?.mimeType) === MediaTypes.JSON;
|
|
147
|
+
printUrlVariablesDeclarations(source, code, level);
|
|
148
|
+
const URL = buildUrlExpression(source, code);
|
|
149
|
+
code
|
|
150
|
+
.push(level, `const ${code.var('resp')} = await fetch(`)
|
|
151
|
+
.push(level + 1, '`' + URL + (hasQueryVariables ? '?${' + code.var('query') + '}' : '') + '`,')
|
|
152
|
+
.push(level + 1, addIndentation(stringifyObject(reqOpts, {
|
|
153
|
+
indent: options.indent,
|
|
154
|
+
inlineCharacterLimit: 25,
|
|
155
|
+
transform: getPreserveTransformer({
|
|
156
|
+
body: true,
|
|
157
|
+
authorizationHeader: preserverOriginalAuthorizationHeader,
|
|
158
|
+
}),
|
|
159
|
+
}), { level: level + 1, indent: options.indent, firstLine: false }))
|
|
160
|
+
.push(level, ');')
|
|
161
|
+
.blank();
|
|
162
|
+
if (source.allResponseCodes?.includes('204')) {
|
|
163
|
+
code
|
|
164
|
+
.push(level, `if (resp.status === 204) {`)
|
|
165
|
+
.push(level + 1, "console.log('success');")
|
|
166
|
+
.push(level, '} else {');
|
|
167
|
+
code
|
|
168
|
+
.push(level + 1, `const ${code.var('data')} = await ${code.var('resp')}.${isJSON ? 'json()' : 'text()'};`)
|
|
169
|
+
.push(level + 1, `console.log(${code.var('data')});`)
|
|
170
|
+
.push(level, '}');
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
code
|
|
174
|
+
.push(level, `const ${code.var('data')} = await ${code.var('resp')}.${isJSON ? 'json()' : 'text()'};`)
|
|
175
|
+
.push(level, `console.log(${code.var('data')});`);
|
|
176
|
+
}
|
|
177
|
+
if (options.showBoilerplate) {
|
|
178
|
+
code.push('}').blank().push('run();');
|
|
179
|
+
}
|
|
180
|
+
return code.join().replace(/"fs\.createReadStream\(\\"(.+)\\"\)"/, 'fs.createReadStream("$1")');
|
|
181
|
+
};
|
|
182
|
+
function addComments(code) {
|
|
183
|
+
code.push('/**');
|
|
184
|
+
code.push(' * Requires Node.js >= 14');
|
|
185
|
+
code.push(' *');
|
|
186
|
+
code.push(' * Requires module "node-fetch" >= 2.6.1');
|
|
187
|
+
code.push(' * See here for installation details:');
|
|
188
|
+
code.push(' * https://www.npmjs.com/package/node-fetch');
|
|
189
|
+
code.push(' */');
|
|
190
|
+
code.blank();
|
|
191
|
+
}
|
|
192
|
+
export const info = {
|
|
193
|
+
key: 'fetch',
|
|
194
|
+
title: 'Fetch',
|
|
195
|
+
link: 'https://github.com/bitinn/node-fetch',
|
|
196
|
+
description: 'Simplified HTTP node-fetch client',
|
|
197
|
+
};
|
|
198
|
+
export default handler;
|
|
199
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fetch from './fetch.js';
|
|
2
|
+
export default {
|
|
3
|
+
info: {
|
|
4
|
+
key: 'node',
|
|
5
|
+
title: 'Node.js',
|
|
6
|
+
extname: '.js',
|
|
7
|
+
default: 'fetch',
|
|
8
|
+
},
|
|
9
|
+
fetch,
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=index.js.map
|