@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
package/lib/utils/openapi.js
CHANGED
|
@@ -1 +1,592 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { dirname } from 'path';
|
|
2
|
+
import UrlTemplate from 'url-template';
|
|
3
|
+
import { IS_BROWSER } from '@redocly/theme/core/openapi';
|
|
4
|
+
import { deleteEmptyArrayItem, isArrayOfObjects, isNumeric, removeQueryStringAndHash, resolveUrl, sanitizeItemId, normalizeText, getValueFromMdParsedExtension, isAbsoluteUrl, } from './helpers.js';
|
|
5
|
+
import { DEFAULT_TAG_SLUG, MediaTypes } from '../constants.js';
|
|
6
|
+
import { JsonPointer } from './JsonPointer.js';
|
|
7
|
+
import { joinWithSeparator } from '../services/index.js';
|
|
8
|
+
import { tryDecodeURIComponent } from './string.js';
|
|
9
|
+
import { getUrlDirname } from './url.js';
|
|
10
|
+
function isWildcardStatusCode(statusCode) {
|
|
11
|
+
return typeof statusCode === 'string' && /\dxx/i.test(statusCode);
|
|
12
|
+
}
|
|
13
|
+
export function isStatusCode(statusCode) {
|
|
14
|
+
return statusCode === 'default' || isNumeric(statusCode) || isWildcardStatusCode(statusCode);
|
|
15
|
+
}
|
|
16
|
+
export function getStatusCodeType(statusCode, defaultAsError = false) {
|
|
17
|
+
if (statusCode === 'default') {
|
|
18
|
+
return defaultAsError ? 'error' : 'success';
|
|
19
|
+
}
|
|
20
|
+
let code = typeof statusCode === 'string' ? parseInt(statusCode, 10) : statusCode;
|
|
21
|
+
if (isWildcardStatusCode(statusCode)) {
|
|
22
|
+
code *= 100; // parseInt('2xx') parses to 2
|
|
23
|
+
}
|
|
24
|
+
if (code < 100 || code > 599) {
|
|
25
|
+
throw new Error('invalid HTTP code');
|
|
26
|
+
}
|
|
27
|
+
let res = 'success';
|
|
28
|
+
if (code >= 300 && code < 400) {
|
|
29
|
+
res = 'redirect';
|
|
30
|
+
}
|
|
31
|
+
else if (code >= 400) {
|
|
32
|
+
res = 'error';
|
|
33
|
+
}
|
|
34
|
+
else if (code < 200) {
|
|
35
|
+
res = 'info';
|
|
36
|
+
}
|
|
37
|
+
return res;
|
|
38
|
+
}
|
|
39
|
+
const operationNames = {
|
|
40
|
+
get: true,
|
|
41
|
+
post: true,
|
|
42
|
+
put: true,
|
|
43
|
+
head: true,
|
|
44
|
+
patch: true,
|
|
45
|
+
delete: true,
|
|
46
|
+
options: true,
|
|
47
|
+
$ref: true,
|
|
48
|
+
};
|
|
49
|
+
export function isOperationName(key) {
|
|
50
|
+
return key in operationNames;
|
|
51
|
+
}
|
|
52
|
+
export function getOperationName(operation) {
|
|
53
|
+
const { operationId, pathName } = operation;
|
|
54
|
+
const _description = normalizeText(getValueFromMdParsedExtension(operation, 'description'));
|
|
55
|
+
return (normalizeText(getValueFromMdParsedExtension(operation, 'summary')) ||
|
|
56
|
+
operationId ||
|
|
57
|
+
(_description && _description.substring(0, 50)) ||
|
|
58
|
+
pathName ||
|
|
59
|
+
'<no summary>');
|
|
60
|
+
}
|
|
61
|
+
export function getOperationId(operation, parent) {
|
|
62
|
+
if (parent?.id) {
|
|
63
|
+
return joinWithSeparator(parent.id, sanitizeItemId(operation.operationId ? operation.operationId : pointerToId(operation.pointer))).toLowerCase();
|
|
64
|
+
}
|
|
65
|
+
if (!operation.tags?.length) {
|
|
66
|
+
return sanitizeItemId(operation.operationId
|
|
67
|
+
? joinWithSeparator(DEFAULT_TAG_SLUG, operation.operationId)
|
|
68
|
+
: pointerToId(operation.pointer));
|
|
69
|
+
}
|
|
70
|
+
return sanitizeItemId(operation.operationId ? operation.operationId : pointerToId(operation.pointer));
|
|
71
|
+
}
|
|
72
|
+
function pointerToId(pointer) {
|
|
73
|
+
return pointer?.startsWith('/') ? pointer.slice(1, pointer.length) : pointer;
|
|
74
|
+
}
|
|
75
|
+
const schemaKeywordTypes = {
|
|
76
|
+
multipleOf: 'number',
|
|
77
|
+
maximum: 'number',
|
|
78
|
+
exclusiveMaximum: 'number',
|
|
79
|
+
minimum: 'number',
|
|
80
|
+
exclusiveMinimum: 'number',
|
|
81
|
+
maxLength: 'string',
|
|
82
|
+
minLength: 'string',
|
|
83
|
+
pattern: 'string',
|
|
84
|
+
contentEncoding: 'string',
|
|
85
|
+
contentMediaType: 'string',
|
|
86
|
+
items: 'array',
|
|
87
|
+
maxItems: 'array',
|
|
88
|
+
minItems: 'array',
|
|
89
|
+
uniqueItems: 'array',
|
|
90
|
+
maxProperties: 'object',
|
|
91
|
+
minProperties: 'object',
|
|
92
|
+
required: 'object',
|
|
93
|
+
additionalProperties: 'object',
|
|
94
|
+
unevaluatedProperties: 'object',
|
|
95
|
+
patternProperties: 'object',
|
|
96
|
+
properties: 'object',
|
|
97
|
+
};
|
|
98
|
+
export function detectType(schema) {
|
|
99
|
+
if (schema.type !== undefined && !Array.isArray(schema.type)) {
|
|
100
|
+
return schema.type;
|
|
101
|
+
}
|
|
102
|
+
const keywords = Object.keys(schemaKeywordTypes);
|
|
103
|
+
for (const keyword of keywords) {
|
|
104
|
+
const type = schemaKeywordTypes[keyword];
|
|
105
|
+
if (schema[keyword] !== undefined) {
|
|
106
|
+
return type;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return 'any';
|
|
110
|
+
}
|
|
111
|
+
export function isPrimitiveType(schema, type = schema.type) {
|
|
112
|
+
if (schema['x-circular-ref']) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
if (schema['x-complex']) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
if ((schema.if && schema.then) || (schema.if && schema.else)) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
let isPrimitive = true;
|
|
125
|
+
const isArray = Array.isArray(type);
|
|
126
|
+
if (type === 'object' || (isArray && type?.includes('object'))) {
|
|
127
|
+
isPrimitive =
|
|
128
|
+
schema.properties !== undefined
|
|
129
|
+
? Object.keys(schema.properties).length === 0
|
|
130
|
+
: schema.additionalProperties === undefined &&
|
|
131
|
+
schema.unevaluatedProperties === undefined &&
|
|
132
|
+
schema.patternProperties === undefined;
|
|
133
|
+
}
|
|
134
|
+
if (Array.isArray(schema.items) || Array.isArray(schema.prefixItems)) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
if (schema.items !== undefined &&
|
|
138
|
+
typeof schema.items !== 'boolean' &&
|
|
139
|
+
(type === 'array' || (isArray && type?.includes('array')))) {
|
|
140
|
+
isPrimitive = isPrimitiveType(schema.items, schema.items.type);
|
|
141
|
+
}
|
|
142
|
+
return isPrimitive;
|
|
143
|
+
}
|
|
144
|
+
export function isJsonLike(contentType) {
|
|
145
|
+
return contentType.search(/json/i) !== -1;
|
|
146
|
+
}
|
|
147
|
+
export function isXmlLike(contentType) {
|
|
148
|
+
return contentType?.search(/xml/i) !== -1;
|
|
149
|
+
}
|
|
150
|
+
export function isFormUrlEncoded(contentType) {
|
|
151
|
+
return contentType === MediaTypes.URL_ENCODED;
|
|
152
|
+
}
|
|
153
|
+
export function isMultipartFormData(contentType) {
|
|
154
|
+
return contentType === MediaTypes.MULTIPART;
|
|
155
|
+
}
|
|
156
|
+
function delimitedEncodeField(fieldVal, fieldName, delimiter) {
|
|
157
|
+
if (Array.isArray(fieldVal)) {
|
|
158
|
+
return fieldVal.map((v) => v.toString()).join(delimiter);
|
|
159
|
+
}
|
|
160
|
+
else if (typeof fieldVal === 'object') {
|
|
161
|
+
return Object.keys(fieldVal)
|
|
162
|
+
.map((k) => `${k}${delimiter}${fieldVal[k]}`)
|
|
163
|
+
.join(delimiter);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
return fieldName + '=' + fieldVal.toString();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function deepObjectEncodeField(fieldVal, fieldName) {
|
|
170
|
+
if (Array.isArray(fieldVal)) {
|
|
171
|
+
console.warn('deepObject style cannot be used with array value:' + fieldVal.toString());
|
|
172
|
+
return '';
|
|
173
|
+
}
|
|
174
|
+
else if (typeof fieldVal === 'object') {
|
|
175
|
+
return Object.keys(fieldVal)
|
|
176
|
+
.map((k) => (fieldVal[k] ? `${fieldName}[${k}]=${fieldVal[k]}` : undefined))
|
|
177
|
+
.filter(Boolean)
|
|
178
|
+
.join('&');
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
console.warn('deepObject style cannot be used with non-object value:' + fieldVal.toString());
|
|
182
|
+
return '';
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function serializeFormValue(name, explode, value) {
|
|
186
|
+
// Use RFC6570 safe name ([a-zA-Z0-9_]) and replace with our name later
|
|
187
|
+
// e.g. URI.template doesn't parse names with hyphen (-) which are valid query param names
|
|
188
|
+
const safeName = '__redoc_param_name__';
|
|
189
|
+
const suffix = explode ? '*' : '';
|
|
190
|
+
const template = UrlTemplate.parse(`{?${safeName}${suffix}}`);
|
|
191
|
+
return template
|
|
192
|
+
.expand({ [safeName]: value })
|
|
193
|
+
.substring(1)
|
|
194
|
+
.replace(/__redoc_param_name__/g, name);
|
|
195
|
+
}
|
|
196
|
+
function serializeSimpleValue(explode, value) {
|
|
197
|
+
const suffix = explode ? '*' : '';
|
|
198
|
+
// name is not important here, so use RFC6570 safe name ([a-zA-Z0-9_])
|
|
199
|
+
const name = '__redoc_param_name__';
|
|
200
|
+
const template = UrlTemplate.parse(`{${name}${suffix}}`);
|
|
201
|
+
return tryDecodeURIComponent(template.expand({ [name]: value }));
|
|
202
|
+
}
|
|
203
|
+
/*
|
|
204
|
+
* Should be used only for url-form-encoded body payloads
|
|
205
|
+
* To be used for parameters should be extended with other style values
|
|
206
|
+
*/
|
|
207
|
+
export function urlFormEncodePayload(payload, encoding = {}) {
|
|
208
|
+
if (Array.isArray(payload)) {
|
|
209
|
+
throw new Error('Payload must have fields: ' + payload.toString());
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
return Object.keys(payload)
|
|
213
|
+
.map((fieldName) => {
|
|
214
|
+
const fieldVal = payload[fieldName];
|
|
215
|
+
const { style = 'form', explode = true } = encoding[fieldName] || {};
|
|
216
|
+
switch (style) {
|
|
217
|
+
case 'form':
|
|
218
|
+
return serializeFormValue(fieldName, explode, fieldVal);
|
|
219
|
+
case 'spaceDelimited':
|
|
220
|
+
return delimitedEncodeField(fieldVal, fieldName, '%20');
|
|
221
|
+
case 'pipeDelimited':
|
|
222
|
+
return delimitedEncodeField(fieldVal, fieldName, '|');
|
|
223
|
+
case 'deepObject':
|
|
224
|
+
return deepObjectEncodeField(fieldVal, fieldName);
|
|
225
|
+
default:
|
|
226
|
+
// TODO implement rest of styles for path parameters
|
|
227
|
+
console.warn('Incorrect or unsupported encoding style: ' + style);
|
|
228
|
+
return '';
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
.join('&');
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function serializePathParameter(name, style, explode, value) {
|
|
235
|
+
const suffix = explode ? '*' : '';
|
|
236
|
+
let prefix = '';
|
|
237
|
+
if (style === 'label') {
|
|
238
|
+
prefix = '.';
|
|
239
|
+
}
|
|
240
|
+
else if (style === 'matrix') {
|
|
241
|
+
prefix = ';';
|
|
242
|
+
}
|
|
243
|
+
// Use RFC6570 safe name ([a-zA-Z0-9_]) and replace with our name later
|
|
244
|
+
// e.g. URI.template doesn't parse names with hyphen (-) which are valid query param names
|
|
245
|
+
const safeName = '__redoc_param_name__';
|
|
246
|
+
const template = UrlTemplate.parse(`{${prefix}${safeName}${suffix}}`);
|
|
247
|
+
return template.expand({ [safeName]: value }).replace(/__redoc_param_name__/g, name);
|
|
248
|
+
}
|
|
249
|
+
export function serializeQueryParameter(name, style, explode, value) {
|
|
250
|
+
const serializationByStyle = (val) => {
|
|
251
|
+
switch (style) {
|
|
252
|
+
case 'form':
|
|
253
|
+
return serializeFormValue(name, explode, val);
|
|
254
|
+
case 'spaceDelimited':
|
|
255
|
+
if (!Array.isArray(val) && typeof val !== 'object') {
|
|
256
|
+
console.warn('The style spaceDelimited is applicable to arrays or objects');
|
|
257
|
+
return '';
|
|
258
|
+
}
|
|
259
|
+
if (explode) {
|
|
260
|
+
return serializeFormValue(name, explode, val);
|
|
261
|
+
}
|
|
262
|
+
return delimitedEncodeField(value, name, '%20');
|
|
263
|
+
case 'pipeDelimited':
|
|
264
|
+
if (!Array.isArray(val) && typeof val !== 'object') {
|
|
265
|
+
console.warn('The style pipeDelimited is applicable to arrays or objects');
|
|
266
|
+
return '';
|
|
267
|
+
}
|
|
268
|
+
if (explode) {
|
|
269
|
+
return serializeFormValue(name, explode, val);
|
|
270
|
+
}
|
|
271
|
+
return delimitedEncodeField(value, name, '|');
|
|
272
|
+
case 'deepObject':
|
|
273
|
+
if (!explode || Array.isArray(val) || typeof val !== 'object') {
|
|
274
|
+
console.warn('The style deepObject is only applicable for objects with explode=true');
|
|
275
|
+
return '';
|
|
276
|
+
}
|
|
277
|
+
return deepObjectEncodeField(val, name);
|
|
278
|
+
case 'simple': {
|
|
279
|
+
return serializeSimpleValue(explode, value);
|
|
280
|
+
}
|
|
281
|
+
default:
|
|
282
|
+
console.warn('Unexpected style for query: ' + style);
|
|
283
|
+
return '';
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
if (isArrayOfObjects(value)) {
|
|
287
|
+
value = deleteEmptyArrayItem(value).map((value) => serializationByStyle(value));
|
|
288
|
+
}
|
|
289
|
+
return serializationByStyle(value);
|
|
290
|
+
}
|
|
291
|
+
function serializeHeaderParameter(style, explode, value) {
|
|
292
|
+
switch (style) {
|
|
293
|
+
case 'simple': {
|
|
294
|
+
return serializeSimpleValue(explode, value);
|
|
295
|
+
}
|
|
296
|
+
default:
|
|
297
|
+
console.warn('Unexpected style for header: ' + style);
|
|
298
|
+
return '';
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function serializeCookieParameter(name, style, explode, value) {
|
|
302
|
+
switch (style) {
|
|
303
|
+
case 'form':
|
|
304
|
+
return serializeFormValue(name, explode, value);
|
|
305
|
+
default:
|
|
306
|
+
console.warn('Unexpected style for cookie: ' + style);
|
|
307
|
+
return '';
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
export function serializeParameterValueWithMime(value, mime) {
|
|
311
|
+
if (isJsonLike(mime)) {
|
|
312
|
+
return JSON.stringify(value);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
console.warn(`Parameter serialization as ${mime} is not supported`);
|
|
316
|
+
return '';
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
export function serializeParameterValue(parameter, value) {
|
|
320
|
+
const { name, style, explode = false, serializationMime } = parameter;
|
|
321
|
+
if (serializationMime) {
|
|
322
|
+
switch (parameter.in) {
|
|
323
|
+
case 'path':
|
|
324
|
+
case 'header':
|
|
325
|
+
return serializeParameterValueWithMime(value, serializationMime);
|
|
326
|
+
case 'cookie':
|
|
327
|
+
case 'query':
|
|
328
|
+
return `${name}=${serializeParameterValueWithMime(value, serializationMime)}`;
|
|
329
|
+
default:
|
|
330
|
+
console.warn('Unexpected parameter location: ' + parameter.in);
|
|
331
|
+
return '';
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (!style) {
|
|
335
|
+
console.warn(`Missing style attribute or content for parameter ${name}`);
|
|
336
|
+
return '';
|
|
337
|
+
}
|
|
338
|
+
switch (parameter.in) {
|
|
339
|
+
case 'path':
|
|
340
|
+
return serializePathParameter(name, style, explode, value);
|
|
341
|
+
case 'query':
|
|
342
|
+
return serializeQueryParameter(name, style, explode, value);
|
|
343
|
+
case 'header':
|
|
344
|
+
return serializeHeaderParameter(style, explode, value);
|
|
345
|
+
case 'cookie':
|
|
346
|
+
return serializeCookieParameter(name, style, explode, value);
|
|
347
|
+
default:
|
|
348
|
+
console.warn('Unexpected parameter location: ' + parameter.in);
|
|
349
|
+
return '';
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
export function langFromMime(contentType) {
|
|
353
|
+
if (contentType.search(/xml/i) !== -1) {
|
|
354
|
+
return 'xml';
|
|
355
|
+
}
|
|
356
|
+
return 'clike';
|
|
357
|
+
}
|
|
358
|
+
const DEFINITION_NAME_REGEX = /^#\/components\/(schemas|pathItems)\/([^/]+)$/;
|
|
359
|
+
export function isNamedDefinition(pointer) {
|
|
360
|
+
return DEFINITION_NAME_REGEX.test(pointer || '');
|
|
361
|
+
}
|
|
362
|
+
export function getDefinitionName(pointer) {
|
|
363
|
+
return pointer?.match(DEFINITION_NAME_REGEX)?.pop();
|
|
364
|
+
}
|
|
365
|
+
function humanizeMultipleOfConstraint(multipleOf) {
|
|
366
|
+
if (multipleOf === undefined) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const strigifiedMultipleOf = multipleOf.toString(10);
|
|
370
|
+
if (!/^0\.0*1$/.test(strigifiedMultipleOf)) {
|
|
371
|
+
return `multiple of ${strigifiedMultipleOf}`;
|
|
372
|
+
}
|
|
373
|
+
return `decimal places <= ${strigifiedMultipleOf.split('.')[1].length}`;
|
|
374
|
+
}
|
|
375
|
+
function humanizeRangeConstraint(description, min, max) {
|
|
376
|
+
let stringRange;
|
|
377
|
+
if (min !== undefined && max !== undefined) {
|
|
378
|
+
if (min === max) {
|
|
379
|
+
stringRange = `= ${min} ${description}`;
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
stringRange = `[ ${min} .. ${max} ] ${description}`;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
else if (max !== undefined) {
|
|
386
|
+
stringRange = `<= ${max} ${description}`;
|
|
387
|
+
}
|
|
388
|
+
else if (min !== undefined) {
|
|
389
|
+
if (min === 1) {
|
|
390
|
+
stringRange = 'non-empty';
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
stringRange = `>= ${min} ${description}`;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return stringRange;
|
|
397
|
+
}
|
|
398
|
+
export function humanizeNumberRange(schema) {
|
|
399
|
+
const minimum = typeof schema.exclusiveMinimum === 'number'
|
|
400
|
+
? Math.min(schema.exclusiveMinimum, schema.minimum ?? Infinity)
|
|
401
|
+
: schema.minimum;
|
|
402
|
+
const maximum = typeof schema.exclusiveMaximum === 'number'
|
|
403
|
+
? Math.max(schema.exclusiveMaximum, schema.maximum ?? -Infinity)
|
|
404
|
+
: schema.maximum;
|
|
405
|
+
const exclusiveMinimum = typeof schema.exclusiveMinimum === 'number' || schema.exclusiveMinimum;
|
|
406
|
+
const exclusiveMaximum = typeof schema.exclusiveMaximum === 'number' || schema.exclusiveMaximum;
|
|
407
|
+
if (minimum !== undefined && maximum !== undefined) {
|
|
408
|
+
return `${exclusiveMinimum ? '( ' : '[ '}${minimum} .. ${maximum}${exclusiveMaximum ? ' )' : ' ]'}`;
|
|
409
|
+
}
|
|
410
|
+
else if (maximum !== undefined) {
|
|
411
|
+
return `${exclusiveMaximum ? '< ' : '<= '}${maximum}`;
|
|
412
|
+
}
|
|
413
|
+
else if (minimum !== undefined) {
|
|
414
|
+
return `${exclusiveMinimum ? '> ' : '>= '}${minimum}`;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
export function humanizeConstraints(schema) {
|
|
418
|
+
const res = [];
|
|
419
|
+
const stringRange = humanizeRangeConstraint('characters', schema.minLength, schema.maxLength);
|
|
420
|
+
if (stringRange !== undefined) {
|
|
421
|
+
res.push(stringRange);
|
|
422
|
+
}
|
|
423
|
+
const arrayRange = humanizeRangeConstraint('items', schema.minItems, schema.maxItems);
|
|
424
|
+
if (arrayRange !== undefined) {
|
|
425
|
+
res.push(arrayRange);
|
|
426
|
+
}
|
|
427
|
+
const propertiesRange = humanizeRangeConstraint(schema.minProperties === 1 && schema.maxProperties === 1 ? 'property' : 'properties', schema.minProperties, schema.maxProperties);
|
|
428
|
+
if (propertiesRange !== undefined) {
|
|
429
|
+
res.push(propertiesRange);
|
|
430
|
+
}
|
|
431
|
+
const multipleOfConstraint = humanizeMultipleOfConstraint(schema.multipleOf);
|
|
432
|
+
if (multipleOfConstraint !== undefined) {
|
|
433
|
+
res.push(multipleOfConstraint);
|
|
434
|
+
}
|
|
435
|
+
const numberRange = humanizeNumberRange(schema);
|
|
436
|
+
if (numberRange !== undefined) {
|
|
437
|
+
res.push(numberRange);
|
|
438
|
+
}
|
|
439
|
+
if (schema.uniqueItems) {
|
|
440
|
+
res.push('unique');
|
|
441
|
+
}
|
|
442
|
+
return res;
|
|
443
|
+
}
|
|
444
|
+
export function sortByRequired(fields, order = []) {
|
|
445
|
+
const unrequiredFields = [];
|
|
446
|
+
const orderedFields = [];
|
|
447
|
+
const unorderedFields = [];
|
|
448
|
+
fields.forEach((field) => {
|
|
449
|
+
if (field.required) {
|
|
450
|
+
if (order.includes(field.name)) {
|
|
451
|
+
orderedFields.push(field);
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
unorderedFields.push(field);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
unrequiredFields.push(field);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
orderedFields.sort((a, b) => order.indexOf(a.name) - order.indexOf(b.name));
|
|
462
|
+
return [...orderedFields, ...unorderedFields, ...unrequiredFields];
|
|
463
|
+
}
|
|
464
|
+
export function sortByDeprecated(fields) {
|
|
465
|
+
return fields.sort((a, b) => Number(a.deprecated) - Number(b.deprecated));
|
|
466
|
+
}
|
|
467
|
+
export function mergeParams(parser, pathParams = [], operationParams = [], { pathPointer, operationPointer }) {
|
|
468
|
+
const operationParamNames = {};
|
|
469
|
+
operationParams.forEach((param) => {
|
|
470
|
+
({ resolved: param } = parser.deref(param));
|
|
471
|
+
operationParamNames[param.name + '_' + param.in] = true;
|
|
472
|
+
});
|
|
473
|
+
const pathParamsPointer = pathParams
|
|
474
|
+
.map((paramOrRef, index) => ({
|
|
475
|
+
paramOrRef,
|
|
476
|
+
pointer: JsonPointer.join(pathPointer, ['parameters', String(index)]),
|
|
477
|
+
}))
|
|
478
|
+
// filter out path params overridden by operation ones with the same name
|
|
479
|
+
.filter(({ paramOrRef }) => {
|
|
480
|
+
({ resolved: paramOrRef } = parser.deref(paramOrRef));
|
|
481
|
+
return !operationParamNames[paramOrRef.name + '_' + paramOrRef.in];
|
|
482
|
+
});
|
|
483
|
+
const operationParamsPointer = operationParams.map((paramOrRef, index) => ({
|
|
484
|
+
paramOrRef,
|
|
485
|
+
pointer: JsonPointer.join(operationPointer, ['parameters', String(index)]),
|
|
486
|
+
}));
|
|
487
|
+
return [...pathParamsPointer, ...operationParamsPointer];
|
|
488
|
+
}
|
|
489
|
+
export function normalizeServers(specUrl, servers) {
|
|
490
|
+
const getHref = () => {
|
|
491
|
+
if (!IS_BROWSER) {
|
|
492
|
+
return globalThis.SSR_HOSTNAME || '';
|
|
493
|
+
}
|
|
494
|
+
const href = window.location.href;
|
|
495
|
+
return href.endsWith('.html') ? dirname(href) : href;
|
|
496
|
+
};
|
|
497
|
+
const baseUrl = specUrl === undefined
|
|
498
|
+
? removeQueryStringAndHash(getHref())
|
|
499
|
+
: isAbsoluteUrl(specUrl)
|
|
500
|
+
? getUrlDirname(specUrl)
|
|
501
|
+
: dirname(specUrl);
|
|
502
|
+
if (servers.length === 0) {
|
|
503
|
+
// Behaviour defined in OpenAPI spec: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#openapi-object
|
|
504
|
+
servers = [
|
|
505
|
+
{
|
|
506
|
+
url: '/',
|
|
507
|
+
},
|
|
508
|
+
];
|
|
509
|
+
}
|
|
510
|
+
return servers.map((server) => {
|
|
511
|
+
return {
|
|
512
|
+
...server,
|
|
513
|
+
url: baseUrl ? resolveUrl(baseUrl, server.url) : server.url,
|
|
514
|
+
description: server.description || '',
|
|
515
|
+
};
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
export const shortenHTTPVerb = (verb) => ({
|
|
519
|
+
delete: 'del',
|
|
520
|
+
options: 'opts',
|
|
521
|
+
})[verb] || verb;
|
|
522
|
+
export function isRedocExtension(key) {
|
|
523
|
+
const redocExtensions = {
|
|
524
|
+
'x-circular-ref': true,
|
|
525
|
+
'x-complex': true,
|
|
526
|
+
'x-parentRefs': true,
|
|
527
|
+
'x-refsStack': true,
|
|
528
|
+
'x-codeSamples': true,
|
|
529
|
+
'x-displayName': true,
|
|
530
|
+
'x-examples': true,
|
|
531
|
+
'x-logo': true,
|
|
532
|
+
'x-nullable': true,
|
|
533
|
+
'x-servers': true,
|
|
534
|
+
'x-tagGroups': true,
|
|
535
|
+
'x-traitTag': true,
|
|
536
|
+
'x-additionalPropertiesName': true,
|
|
537
|
+
'x-explicitMappingOnly': true,
|
|
538
|
+
'x-enumDescriptions': true,
|
|
539
|
+
'x-hideReplay': true,
|
|
540
|
+
'x-feedback': true,
|
|
541
|
+
'x-badges': true,
|
|
542
|
+
'x-assertionType': true,
|
|
543
|
+
'x-rbac': true,
|
|
544
|
+
};
|
|
545
|
+
return key in redocExtensions || key.startsWith('x-parsed-md-');
|
|
546
|
+
}
|
|
547
|
+
export function extractExtensions(obj, showExtensions) {
|
|
548
|
+
return Object.keys(obj)
|
|
549
|
+
.filter((key) => {
|
|
550
|
+
if (showExtensions === true) {
|
|
551
|
+
return key.startsWith('x-') && !isRedocExtension(key);
|
|
552
|
+
}
|
|
553
|
+
return key.startsWith('x-') && showExtensions.indexOf(key) > -1;
|
|
554
|
+
})
|
|
555
|
+
.reduce((acc, key) => {
|
|
556
|
+
acc[key] = obj[key];
|
|
557
|
+
return acc;
|
|
558
|
+
}, {});
|
|
559
|
+
}
|
|
560
|
+
export function pluralizeType(displayType) {
|
|
561
|
+
return displayType
|
|
562
|
+
.split(' or ')
|
|
563
|
+
.map((type) => type.replace(/^(string|object|number|integer|array|boolean)s?( ?.*)/, '$1s$2'))
|
|
564
|
+
.join(' or ');
|
|
565
|
+
}
|
|
566
|
+
export function getContentWithLegacyExamples(info) {
|
|
567
|
+
let mediaContent = info.content;
|
|
568
|
+
const xExamples = info['x-examples']; // converted from OAS2 body param
|
|
569
|
+
const xExample = info['x-example']; // converted from OAS2 body param
|
|
570
|
+
if (xExamples) {
|
|
571
|
+
mediaContent = { ...mediaContent };
|
|
572
|
+
for (const mime of Object.keys(xExamples)) {
|
|
573
|
+
const examples = xExamples[mime];
|
|
574
|
+
mediaContent[mime] = {
|
|
575
|
+
...mediaContent[mime],
|
|
576
|
+
examples,
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
else if (xExample) {
|
|
581
|
+
mediaContent = { ...mediaContent };
|
|
582
|
+
for (const mime of Object.keys(xExample)) {
|
|
583
|
+
const example = xExample[mime];
|
|
584
|
+
mediaContent[mime] = {
|
|
585
|
+
...mediaContent[mime],
|
|
586
|
+
example,
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return mediaContent;
|
|
591
|
+
}
|
|
592
|
+
//# sourceMappingURL=openapi.js.map
|
package/lib/utils/parameters.js
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
-
import{fromSessionStorage
|
|
1
|
+
import { fromSessionStorage, toSessionStorage } from './session-storage.js';
|
|
2
|
+
export function getParameterValue(_in, name) {
|
|
3
|
+
try {
|
|
4
|
+
return JSON.parse(fromSessionStorage(`${_in}.${name}`));
|
|
5
|
+
}
|
|
6
|
+
catch {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function setParameterValue(_in, name, value) {
|
|
11
|
+
toSessionStorage(`${_in}.${name}`, JSON.stringify(value));
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=parameters.js.map
|
package/lib/utils/path.js
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
-
import{tryDecodeURIComponent
|
|
1
|
+
import { tryDecodeURIComponent } from './string.js';
|
|
2
|
+
export function pathIncludesLink(location, link) {
|
|
3
|
+
return link
|
|
4
|
+
? tryDecodeURIComponent(location.pathname + location.hash).includes(tryDecodeURIComponent(link.toLowerCase()))
|
|
5
|
+
: false;
|
|
6
|
+
}
|
|
7
|
+
export function pathMatchedLink(location, link = '') {
|
|
8
|
+
const lowercaseLink = tryDecodeURIComponent(link.toLowerCase());
|
|
9
|
+
return (tryDecodeURIComponent(location.pathname) === lowercaseLink ||
|
|
10
|
+
tryDecodeURIComponent(location.hash) === lowercaseLink ||
|
|
11
|
+
tryDecodeURIComponent(location.pathname + location.hash) === lowercaseLink);
|
|
12
|
+
}
|
|
13
|
+
export function normalizePath(path) {
|
|
14
|
+
if (!path.startsWith('/')) {
|
|
15
|
+
path = '/' + path;
|
|
16
|
+
}
|
|
17
|
+
if (path.endsWith('/')) {
|
|
18
|
+
path = path.slice(0, -1);
|
|
19
|
+
}
|
|
20
|
+
return path;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=path.js.map
|