@redocly/openapi-docs 3.12.0 → 3.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/redocly-openapi-docs.min.js +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 +3 -3
|
@@ -1,3 +1,222 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { CodeBuilder } from '../../helpers/code-builder.js';
|
|
2
|
+
import { HTTPSnippet } from '../../index.js';
|
|
3
|
+
import { Lang } from '../../helpers/constants.js';
|
|
4
|
+
import { buildUrlExpression, printUrlVariablesDeclarations } from '../../helpers/code-helpers.js';
|
|
5
|
+
import { normalizeMimeType } from '../../../../utils.js';
|
|
6
|
+
import { MediaTypes } from '../../../../../constants.js';
|
|
7
|
+
const indent = 1;
|
|
8
|
+
function hasMimeType(postData = {}, mimeType) {
|
|
9
|
+
return normalizeMimeType(postData.mimeType) === mimeType;
|
|
10
|
+
}
|
|
11
|
+
const handler = function (source, originalOptions, { target, client }) {
|
|
12
|
+
const options = {
|
|
13
|
+
capitalize: true,
|
|
14
|
+
showBoilerplate: true,
|
|
15
|
+
checkErrors: true,
|
|
16
|
+
printBody: true,
|
|
17
|
+
timeout: -1,
|
|
18
|
+
indent: ' ',
|
|
19
|
+
...originalOptions,
|
|
20
|
+
};
|
|
21
|
+
const securityOAuth2ExtraCalls = source.securityOAuth2ExtraCalls?.[0];
|
|
22
|
+
const errorPlaceholder = options.checkErrors ? 'err' : '_';
|
|
23
|
+
const reqMethod = source.method.toUpperCase();
|
|
24
|
+
const code = new CodeBuilder({
|
|
25
|
+
indentation: options.indent,
|
|
26
|
+
variablesPrefix: options.variablesPrefix,
|
|
27
|
+
capitalize: options.capitalize,
|
|
28
|
+
lang: Lang.GO,
|
|
29
|
+
});
|
|
30
|
+
const errorCheck = () => {
|
|
31
|
+
if (options.checkErrors) {
|
|
32
|
+
code
|
|
33
|
+
.push(indent, 'if err != nil {')
|
|
34
|
+
.push(indent + 1, 'panic(err)')
|
|
35
|
+
.push(indent, '}');
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
// Create boilerplate
|
|
39
|
+
if (options.showBoilerplate) {
|
|
40
|
+
code.push('package main').blank().push('import (').push(indent, '"fmt"');
|
|
41
|
+
if (options.timeout > 0) {
|
|
42
|
+
code.push(indent, '"time"');
|
|
43
|
+
}
|
|
44
|
+
if (securityOAuth2ExtraCalls) {
|
|
45
|
+
code.push(indent, '"encoding/json"');
|
|
46
|
+
}
|
|
47
|
+
if (hasMimeType(source.postData, MediaTypes.MULTIPART)) {
|
|
48
|
+
code.push(indent, '"mime/multipart"');
|
|
49
|
+
code.push(indent, '"io"');
|
|
50
|
+
code.push(indent, '"bytes"');
|
|
51
|
+
}
|
|
52
|
+
if (hasMimeType(source.postData, MediaTypes.URL_ENCODED) ||
|
|
53
|
+
hasMimeType(source.securityOAuth2ExtraCalls?.[0]?.postData, MediaTypes.URL_ENCODED)) {
|
|
54
|
+
code.push(indent, '"net/url"');
|
|
55
|
+
code.push(indent, '"strconv"');
|
|
56
|
+
}
|
|
57
|
+
if (hasMimeType(source.postData, MediaTypes.JSON) ||
|
|
58
|
+
hasMimeType(source.securityOAuth2ExtraCalls?.[0]?.postData, MediaTypes.JSON)) {
|
|
59
|
+
code.push(indent, '"bytes"');
|
|
60
|
+
}
|
|
61
|
+
if ((source.postData && !hasMimeType(source.postData, MediaTypes.JSON)) ||
|
|
62
|
+
securityOAuth2ExtraCalls) {
|
|
63
|
+
code.push(indent, '"strings"');
|
|
64
|
+
}
|
|
65
|
+
code.push(indent, '"net/http"');
|
|
66
|
+
if (options.printBody) {
|
|
67
|
+
code.push(indent, '"io/ioutil"');
|
|
68
|
+
}
|
|
69
|
+
code.push(')').blank().push('func main() {');
|
|
70
|
+
}
|
|
71
|
+
// put headers values into quotation marks
|
|
72
|
+
if (Object.keys(source.allHeaders).length) {
|
|
73
|
+
Object.keys(source.allHeaders).forEach((key) => {
|
|
74
|
+
source.allHeaders[key] = `"${source.allHeaders[key]}"`;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (securityOAuth2ExtraCalls) {
|
|
78
|
+
const prefix = 'oAuth2';
|
|
79
|
+
const decoderErrorString = options.checkErrors ? `${errorPlaceholder} := ` : '';
|
|
80
|
+
const resString = options.capitalize ? 'Res' : 'res';
|
|
81
|
+
const oAuth2PrefixCode = new HTTPSnippet(securityOAuth2ExtraCalls).convert(target, client, {
|
|
82
|
+
...options,
|
|
83
|
+
printBody: false,
|
|
84
|
+
variablesPrefix: prefix,
|
|
85
|
+
showBoilerplate: false,
|
|
86
|
+
});
|
|
87
|
+
code
|
|
88
|
+
.push(oAuth2PrefixCode)
|
|
89
|
+
.blank()
|
|
90
|
+
.push(indent, `var ${prefix}${resString}Body struct {`)
|
|
91
|
+
.push(indent + 1, 'Access_token string')
|
|
92
|
+
.push(indent, '}')
|
|
93
|
+
.push(indent, `${decoderErrorString}json.NewDecoder(${prefix}${resString}.Body).Decode(&${prefix}${resString}Body)`)
|
|
94
|
+
.blank();
|
|
95
|
+
errorCheck();
|
|
96
|
+
source.allHeaders.Authorization = `"Bearer " + ${prefix}${resString}Body.Access_token`;
|
|
97
|
+
}
|
|
98
|
+
printUrlVariablesDeclarations(source, code, indent);
|
|
99
|
+
// Create client
|
|
100
|
+
if (options.timeout > 0) {
|
|
101
|
+
client = code.var('client');
|
|
102
|
+
code
|
|
103
|
+
.push(indent, '%s := http.Client{', client)
|
|
104
|
+
.push(indent + 1, 'Timeout: time.Duration(%s * time.Second),', options.timeout)
|
|
105
|
+
.push(indent, '}')
|
|
106
|
+
.blank();
|
|
107
|
+
}
|
|
108
|
+
// Set URL
|
|
109
|
+
code.push(indent, `${code.var('reqUrl')} := ${buildUrlExpression(source, code)}`);
|
|
110
|
+
if (source.postData) {
|
|
111
|
+
let stringifiedData;
|
|
112
|
+
switch (normalizeMimeType(source.postData.mimeType)) {
|
|
113
|
+
case MediaTypes.URL_ENCODED:
|
|
114
|
+
code.push(indent, '%s := url.Values{}', code.var('data'));
|
|
115
|
+
source.postData.params.forEach((param) => {
|
|
116
|
+
code.push(indent, '%s.Set("%s", "%s")', code.var('data'), param.name, param.value);
|
|
117
|
+
});
|
|
118
|
+
code.push(indent, '%s, %s := http.NewRequest("%s", %s, strings.NewReader(%s.Encode()))', code.var('req'), errorPlaceholder, reqMethod, code.var('reqUrl'), code.var('data'));
|
|
119
|
+
source.allHeaders['Content-Length'] = `strconv.Itoa(len(${code.var('data')}.Encode()))`;
|
|
120
|
+
break;
|
|
121
|
+
case MediaTypes.JSON:
|
|
122
|
+
/*
|
|
123
|
+
Note about next stringify:
|
|
124
|
+
GO buffers only JSON object with double-quotes for both key and value,
|
|
125
|
+
that is why we are using there JSON.stringify instead of stringify-object package.
|
|
126
|
+
Also to be more readable we add an extra indentation for each stringified code line.
|
|
127
|
+
*/
|
|
128
|
+
stringifiedData = JSON.stringify(source.postData.jsonObj, null, 2)
|
|
129
|
+
.split('\n')
|
|
130
|
+
.map((line) => options.indent + line)
|
|
131
|
+
.join('\n')
|
|
132
|
+
.trim(); // remove redundant spaces at the beginning
|
|
133
|
+
code.push(indent, `var ${code.var('data')} = []byte(\`${stringifiedData}\`)`);
|
|
134
|
+
code.push(indent, '%s, %s := http.NewRequest("%s", %s, bytes.NewBuffer(%s))', code.var('req'), errorPlaceholder, reqMethod, code.var('reqUrl'), code.var('data'));
|
|
135
|
+
break;
|
|
136
|
+
case MediaTypes.MULTIPART:
|
|
137
|
+
code
|
|
138
|
+
.push(indent, '%s := &bytes.Buffer{}', code.var('data'))
|
|
139
|
+
.push(indent, 'writer := multipart.NewWriter(%s)', code.var('data'));
|
|
140
|
+
source.postData.params.forEach((param) => {
|
|
141
|
+
if (!param.fileName && !param.contentType) {
|
|
142
|
+
code
|
|
143
|
+
.push(indent, '%s, _ := writer.CreateFormField("%s")', code.var(`${param.name}Fw`), param.name)
|
|
144
|
+
.push(indent, '_, %s = io.Copy(%s, strings.NewReader("%s"))', errorPlaceholder, code.var(`${param.name}Fw`), param.value);
|
|
145
|
+
errorCheck();
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (param.fileName) {
|
|
149
|
+
code.push(indent, '%s, %s = writer.CreateFormFile("%s", "%s")', code.var(`${param.name}Fw`), errorPlaceholder, param.name, param.fileName);
|
|
150
|
+
errorCheck();
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
code
|
|
154
|
+
.push(indent, 'writer.Close()')
|
|
155
|
+
.blank()
|
|
156
|
+
.push(indent, '%s := bytes.NewReader(%s.Bytes())', code.var('payload'), code.var('data'))
|
|
157
|
+
.push(indent, '%s, %s := http.NewRequest("%s", %s, %s)', code.var('req'), errorPlaceholder, reqMethod, code.var('reqUrl'), code.var('payload'));
|
|
158
|
+
source.allHeaders['Content-Type'] = 'writer.FormDataContentType()';
|
|
159
|
+
break;
|
|
160
|
+
default:
|
|
161
|
+
if (source.postData.text) {
|
|
162
|
+
code
|
|
163
|
+
.push(indent, '%s := strings.NewReader(%s)', code.var('payload'), JSON.stringify(source.postData?.text))
|
|
164
|
+
.push(indent, '%s, %s := http.NewRequest("%s", %s, %s)', code.var('req'), errorPlaceholder, reqMethod, code.var('reqUrl'), code.var('payload'));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
code.push(indent, '%s, %s := http.NewRequest("%s", %s, nil)', code.var('req'), errorPlaceholder, reqMethod, code.var('reqUrl'));
|
|
170
|
+
}
|
|
171
|
+
// Print query variables if present
|
|
172
|
+
const hasQueryVariables = Object.getOwnPropertyNames(source.queryObj).length;
|
|
173
|
+
if (hasQueryVariables) {
|
|
174
|
+
code.blank().push(indent, `${code.var('query')} := ${code.var('req')}.URL.Query()`);
|
|
175
|
+
for (const name in source.queryObj) {
|
|
176
|
+
const value = source.queryObj[name];
|
|
177
|
+
const isArrayString = typeof value === 'string' && /^\[.*\]$/.test(value);
|
|
178
|
+
const queryValue = isArrayString ? `\`${value}\`` : `"${value}"`;
|
|
179
|
+
code.push(indent, `${code.var('query')}.Add("${name}", ${queryValue})`);
|
|
180
|
+
}
|
|
181
|
+
code.push(indent, `${code.var('req')}.URL.RawQuery = ${code.var('query')}.Encode()`).blank();
|
|
182
|
+
}
|
|
183
|
+
errorCheck();
|
|
184
|
+
if (source.basicAuth) {
|
|
185
|
+
const { username, password } = source.basicAuth;
|
|
186
|
+
code.push(indent, `%s.SetBasicAuth("${username}", "${password}")`, code.var('req'));
|
|
187
|
+
}
|
|
188
|
+
// Add headers
|
|
189
|
+
if (Object.keys(source.allHeaders).length) {
|
|
190
|
+
Object.keys(source.allHeaders).forEach((key) => {
|
|
191
|
+
code.push(indent, '%s.Header.Add("%s", %s)', code.var('req'), key, source.allHeaders[key]);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
// Make request
|
|
195
|
+
code.push(indent, '%s, %s := %s.Do(%s)', code.var('res'), errorPlaceholder, client, code.var('req'));
|
|
196
|
+
errorCheck();
|
|
197
|
+
// Get Body
|
|
198
|
+
if (options.printBody) {
|
|
199
|
+
code
|
|
200
|
+
.push(indent, 'defer %s.Body.Close()', code.var('res'))
|
|
201
|
+
.push(indent, '%s, %s := ioutil.ReadAll(%s.Body)', code.var('body'), errorPlaceholder, code.var('res'));
|
|
202
|
+
errorCheck();
|
|
203
|
+
}
|
|
204
|
+
// Print it
|
|
205
|
+
code.blank().push(indent, 'fmt.Println(%s)', code.var('res'));
|
|
206
|
+
if (options.printBody) {
|
|
207
|
+
code.push(indent, 'fmt.Println(string(%s))', code.var('body'));
|
|
208
|
+
}
|
|
209
|
+
// End main block
|
|
210
|
+
if (options.showBoilerplate) {
|
|
211
|
+
code.push('}');
|
|
212
|
+
}
|
|
213
|
+
return code.join();
|
|
214
|
+
};
|
|
215
|
+
export const info = {
|
|
216
|
+
key: 'native',
|
|
217
|
+
title: 'NewRequest',
|
|
218
|
+
link: 'http://golang.org/pkg/net/http/#NewRequest',
|
|
219
|
+
description: 'Golang HTTP client request',
|
|
220
|
+
};
|
|
221
|
+
export default handler;
|
|
222
|
+
//# sourceMappingURL=native.js.map
|
|
@@ -1 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import javascript from './javascript/index.js';
|
|
2
|
+
import node from './node/index.js';
|
|
3
|
+
import python from './python/index.js';
|
|
4
|
+
import shell from './shell/index.js';
|
|
5
|
+
import java8 from './java8/index.js';
|
|
6
|
+
import java from './java/index.js';
|
|
7
|
+
import csharp from './csharp/index.js';
|
|
8
|
+
import csharpNewtonsoft from './csharpNewtonsoft/index.js';
|
|
9
|
+
import go from './go/index.js';
|
|
10
|
+
import php from './php/index.js';
|
|
11
|
+
import ruby from './ruby/index.js';
|
|
12
|
+
import r from './r/index.js';
|
|
13
|
+
const targets = {
|
|
14
|
+
javascript,
|
|
15
|
+
node,
|
|
16
|
+
python,
|
|
17
|
+
shell,
|
|
18
|
+
java8,
|
|
19
|
+
java,
|
|
20
|
+
csharp,
|
|
21
|
+
csharpNewtonsoft,
|
|
22
|
+
go,
|
|
23
|
+
php,
|
|
24
|
+
ruby,
|
|
25
|
+
r,
|
|
26
|
+
};
|
|
27
|
+
export default targets;
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,3 +1,184 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { CodeBuilder } from '../../helpers/code-builder.js';
|
|
2
|
+
import { HTTPSnippet } from '../../index.js';
|
|
3
|
+
import { normalizeMimeType } from '../../../../utils.js';
|
|
4
|
+
import { addIndentation, buildUrlExpression, printUrlVariablesDeclarations, } from '../../helpers/code-helpers.js';
|
|
5
|
+
import { Lang } from '../../helpers/constants.js';
|
|
6
|
+
import { MediaTypes } from '../../../../../constants.js';
|
|
7
|
+
const hasQueryParams = (source) => !!(source.uriObj.query && Object.keys(source.uriObj.query).length);
|
|
8
|
+
const getBody = (source) => source.postData && source.postData.mimeType === MediaTypes.URL_ENCODED
|
|
9
|
+
? 'HttpRequest.BodyPublishers.ofString(form)'
|
|
10
|
+
: source.postData
|
|
11
|
+
? 'HttpRequest.BodyPublishers.ofString(payload)'
|
|
12
|
+
: ['POST', 'PUT', 'PATCH'].includes(source.method.toUpperCase())
|
|
13
|
+
? 'HttpRequest.BodyPublishers.ofString("some body text")'
|
|
14
|
+
: '';
|
|
15
|
+
const handler = function (source, originalOptions, { target, client }) {
|
|
16
|
+
const options = Object.assign({ indent: ' ', withWrapper: true }, originalOptions);
|
|
17
|
+
const code = new CodeBuilder({
|
|
18
|
+
indentation: options.indent,
|
|
19
|
+
variablesPrefix: options.variablesPrefix,
|
|
20
|
+
capitalize: true,
|
|
21
|
+
lang: Lang.JAVA,
|
|
22
|
+
});
|
|
23
|
+
if (options.withComments) {
|
|
24
|
+
addComments(code, source);
|
|
25
|
+
}
|
|
26
|
+
if (options.withImports) {
|
|
27
|
+
addImports(code, source);
|
|
28
|
+
}
|
|
29
|
+
if (options.withWrapper) {
|
|
30
|
+
code.push('public class App {');
|
|
31
|
+
code.push(1, 'public static void main(String[] args) throws Exception {');
|
|
32
|
+
code.push(2, 'var httpClient = HttpClient.newBuilder().build();');
|
|
33
|
+
code.blank();
|
|
34
|
+
}
|
|
35
|
+
if (source.securityOAuth2ExtraCalls?.length) {
|
|
36
|
+
const oAuth2PrefixCode = new HTTPSnippet(source.securityOAuth2ExtraCalls?.[0]).convert(target, client, {
|
|
37
|
+
...options,
|
|
38
|
+
withImports: false,
|
|
39
|
+
withWrapper: false,
|
|
40
|
+
withComments: false,
|
|
41
|
+
variablesPrefix: 'oauth2',
|
|
42
|
+
});
|
|
43
|
+
code.push(oAuth2PrefixCode);
|
|
44
|
+
code.blank();
|
|
45
|
+
code.push(2, 'var oauth2Response = httpClient.send(oauth2Request, HttpResponse.BodyHandlers.ofString());');
|
|
46
|
+
code.push(2, 'var accessToken = new JSONObject(oauth2Response.body()).getString("access_token");');
|
|
47
|
+
code.blank();
|
|
48
|
+
}
|
|
49
|
+
if (source.postData) {
|
|
50
|
+
switch (normalizeMimeType(source.postData.mimeType)) {
|
|
51
|
+
case MediaTypes.URL_ENCODED:
|
|
52
|
+
if (source.postData.params) {
|
|
53
|
+
code.push(2, 'HashMap<String, String> params = new HashMap<>();');
|
|
54
|
+
source.postData.params.forEach((param) => {
|
|
55
|
+
code.push(2, 'params.put("%s", "%s");', param.name, param.value);
|
|
56
|
+
});
|
|
57
|
+
code.blank();
|
|
58
|
+
code.push(2, 'var form = params.keySet().stream()');
|
|
59
|
+
code.push(3, '.map(key -> key + "=" + URLEncoder.encode(params.get(key), StandardCharsets.UTF_8))');
|
|
60
|
+
code.push(3, '.collect(Collectors.joining("&"));');
|
|
61
|
+
code.blank();
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
case MediaTypes.JSON:
|
|
65
|
+
if (source.postData.jsonObj) {
|
|
66
|
+
code.push(2, `var payload = String.join("\\n"
|
|
67
|
+
${addIndentation(JSON.stringify(source.postData.jsonObj, null, 1)
|
|
68
|
+
.replace(/"/g, '\\"')
|
|
69
|
+
.replace(/^/gm, ', "')
|
|
70
|
+
.replace(/$/gm, '"'), { level: 3, indent: options.indent, firstLine: false })}`);
|
|
71
|
+
code.push(2, ');');
|
|
72
|
+
code.blank();
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
case MediaTypes.XML:
|
|
76
|
+
if (source.postData.text) {
|
|
77
|
+
code.push(2, 'var payload = String.join("\\n"');
|
|
78
|
+
source.postData.text
|
|
79
|
+
.trim()
|
|
80
|
+
.split('\n')
|
|
81
|
+
.forEach((item) => {
|
|
82
|
+
const line = item.replace(/"/g, '\\"');
|
|
83
|
+
code.push(3, `"${line}", `);
|
|
84
|
+
});
|
|
85
|
+
code.push(2, ');');
|
|
86
|
+
code.blank();
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
case MediaTypes.MULTIPART:
|
|
90
|
+
if (source.postData.params) {
|
|
91
|
+
code.push(2, 'var multipartBody = MultipartBodyPublisher.newBuilder();');
|
|
92
|
+
if (source.postData.params) {
|
|
93
|
+
source.postData.params.forEach((param) => {
|
|
94
|
+
code.push(2, 'multipartBody.append("%s", "%s");', param.name, param.value);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
code.push(2, 'var body = multipartBody.build();');
|
|
98
|
+
code.blank();
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (hasQueryParams(source)) {
|
|
104
|
+
code.push(2, 'HashMap<String, String> params = new HashMap<>();');
|
|
105
|
+
for (const [key, value] of Object.entries(source.uriObj.query)) {
|
|
106
|
+
code.push(2, 'params.put("%s", "%s");', key, value);
|
|
107
|
+
}
|
|
108
|
+
code.blank();
|
|
109
|
+
code.push(2, 'var query = params.keySet().stream()');
|
|
110
|
+
code.push(3, '.map(key -> key + "=" + URLEncoder.encode(params.get(key), StandardCharsets.UTF_8))');
|
|
111
|
+
code.push(3, '.collect(Collectors.joining("&"));');
|
|
112
|
+
code.blank();
|
|
113
|
+
}
|
|
114
|
+
code.push(2, `var ${code.var('host')} = "%s";`, source.uriObj.protocol + '//' + source.uriObj.host);
|
|
115
|
+
printUrlVariablesDeclarations(source, code, 2);
|
|
116
|
+
const URLSource = { ...source, ...{ pathname: source.uriObj.pathname } };
|
|
117
|
+
code.push(2, `var ${code.var('pathname')} = %s;`, buildUrlExpression(URLSource, code));
|
|
118
|
+
code.push(2, `var ${code.var('request')} = HttpRequest.newBuilder()`);
|
|
119
|
+
if (source.method.toUpperCase() === 'PATCH')
|
|
120
|
+
code.push(3, '.method("PATCH", %s)', getBody(source));
|
|
121
|
+
else
|
|
122
|
+
code.push(3, '.%s(%s)', source.method.toUpperCase(), getBody(source));
|
|
123
|
+
code.push(3, `.uri(URI.create(${code.var('host')} + ${code.var('pathname')} %s))`, hasQueryParams(source) ? "+ '?' + query" : '');
|
|
124
|
+
if (source.securityOAuth2ExtraCalls?.length) {
|
|
125
|
+
source.allHeaders.Authorization = '"Bearer " + accessToken';
|
|
126
|
+
}
|
|
127
|
+
const headers = Object.keys(source.allHeaders);
|
|
128
|
+
if (headers.length) {
|
|
129
|
+
headers.forEach((key) => {
|
|
130
|
+
code.push(3, '.header("%s", %s)', key, key === 'Authorization' && source.securityOAuth2ExtraCalls?.length
|
|
131
|
+
? source.allHeaders[key] // raw expression, not a string
|
|
132
|
+
: `"${source.allHeaders[key]}"`);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (source.basicAuth) {
|
|
136
|
+
const { username, password } = source.basicAuth;
|
|
137
|
+
code.push(3, `.header("Authorization", "Basic " + Base64.getEncoder().encodeToString(("${username}:${password}").getBytes()))`);
|
|
138
|
+
}
|
|
139
|
+
code.push(3, '.build();');
|
|
140
|
+
if (options.withWrapper) {
|
|
141
|
+
code.blank();
|
|
142
|
+
code.push(2, 'var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());');
|
|
143
|
+
code.blank();
|
|
144
|
+
code.push(2, 'System.out.println(response.body());');
|
|
145
|
+
code.push(1, '}');
|
|
146
|
+
code.push('}');
|
|
147
|
+
}
|
|
148
|
+
return code.join();
|
|
149
|
+
};
|
|
150
|
+
export const info = {
|
|
151
|
+
key: 'httpclient',
|
|
152
|
+
title: 'HttpClient',
|
|
153
|
+
link: 'https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpClient.html',
|
|
154
|
+
description: 'HttpClient (Java SE 11 & JDK 11 )',
|
|
155
|
+
};
|
|
156
|
+
export default handler;
|
|
157
|
+
function addComments(code, source) {
|
|
158
|
+
code.push('/**');
|
|
159
|
+
code.push(' * Requires JDK >= 11');
|
|
160
|
+
if (source.securityOAuth2ExtraCalls?.length) {
|
|
161
|
+
code.push(' *');
|
|
162
|
+
code.push(' * Requires package "org.json" >= 20201115');
|
|
163
|
+
code.push(' * See here for installation details:');
|
|
164
|
+
code.push(' * https://search.maven.org/artifact/org.json/json');
|
|
165
|
+
}
|
|
166
|
+
code.push(' */');
|
|
167
|
+
code.blank();
|
|
168
|
+
}
|
|
169
|
+
function addImports(code, source) {
|
|
170
|
+
code.push('import java.net.*;');
|
|
171
|
+
code.push('import java.net.http.*;');
|
|
172
|
+
code.push('import java.util.*;');
|
|
173
|
+
if ((normalizeMimeType(source.postData?.mimeType) === MediaTypes.URL_ENCODED &&
|
|
174
|
+
source.postData?.params) ||
|
|
175
|
+
source.securityOAuth2ExtraCalls?.length ||
|
|
176
|
+
hasQueryParams(source)) {
|
|
177
|
+
code.push('import java.nio.charset.StandardCharsets;');
|
|
178
|
+
code.push('import java.util.stream.Collectors;');
|
|
179
|
+
}
|
|
180
|
+
if (source.securityOAuth2ExtraCalls?.length)
|
|
181
|
+
code.push('import org.json.JSONObject;');
|
|
182
|
+
code.blank();
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=httpclient.js.map
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import httpclient from './httpclient.js';
|
|
2
|
+
export default {
|
|
3
|
+
info: {
|
|
4
|
+
key: 'java',
|
|
5
|
+
title: 'Java',
|
|
6
|
+
extname: '.java',
|
|
7
|
+
default: 'httpclient',
|
|
8
|
+
},
|
|
9
|
+
httpclient,
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=index.js.map
|