@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/models/schema.js
CHANGED
|
@@ -1,2 +1,474 @@
|
|
|
1
|
-
import{REDOCLY_TEAMS_RBAC
|
|
2
|
-
|
|
1
|
+
import { REDOCLY_TEAMS_RBAC } from '@redocly/config';
|
|
2
|
+
import { isObject } from '@redocly/theme/core/openapi';
|
|
3
|
+
import { pushRef } from '../services/OpenAPIParser.js';
|
|
4
|
+
import { detectType, extractExtensions, getValueFromMdParsedExtension, humanizeConstraints, isNamedDefinition, isPrimitiveType, JsonPointer, pluralizeType, sortByDeprecated, sortByRequired, } from '../utils/index.js';
|
|
5
|
+
import { getField } from './field.js';
|
|
6
|
+
export function getSchema({ parser, schemaOrRef, pointer, options, isChild = false, baseRefsStack = [], deps, absolutePointer, }) {
|
|
7
|
+
const { resolved, refsStack: newRefsStack } = parser.deref(schemaOrRef, baseRefsStack, true);
|
|
8
|
+
const schemaPointer = schemaOrRef.$ref || pointer || absolutePointer || '';
|
|
9
|
+
const refsStack = pushRef(newRefsStack, schemaPointer);
|
|
10
|
+
const schema = parser.mergeAllOf(resolved, schemaPointer, refsStack, schemaOrRef.$ref || absolutePointer);
|
|
11
|
+
const type = schema.type || detectType(schema);
|
|
12
|
+
const schemaModel = {
|
|
13
|
+
operationPointer: deps.operation?.pointer || absolutePointer || '',
|
|
14
|
+
schemaOrRef,
|
|
15
|
+
isChild,
|
|
16
|
+
typePrefix: '',
|
|
17
|
+
pointer: schemaPointer,
|
|
18
|
+
absolutePointer,
|
|
19
|
+
refsStack,
|
|
20
|
+
rawSchema: resolved,
|
|
21
|
+
type,
|
|
22
|
+
isCircular: !!schema['x-circular-ref'],
|
|
23
|
+
isComplex: !!schema['x-complex'],
|
|
24
|
+
title: schema.title ||
|
|
25
|
+
(isNamedDefinition(schemaPointer) && JsonPointer.baseName(schemaPointer)) ||
|
|
26
|
+
'',
|
|
27
|
+
description: getValueFromMdParsedExtension(schema, 'description') || '',
|
|
28
|
+
format: schema.format,
|
|
29
|
+
enum: schema.enum || [],
|
|
30
|
+
example: schema.example,
|
|
31
|
+
deprecated: !!schema.deprecated,
|
|
32
|
+
pattern: schema.pattern,
|
|
33
|
+
externalDocs: schema.externalDocs,
|
|
34
|
+
displayFormat: schema.format,
|
|
35
|
+
isPrimitive: isPrimitiveType(schema, type),
|
|
36
|
+
constraints: humanizeConstraints(schema),
|
|
37
|
+
default: schema.default,
|
|
38
|
+
readOnly: !!schema.readOnly,
|
|
39
|
+
writeOnly: !!schema.writeOnly,
|
|
40
|
+
const: schema.const || '',
|
|
41
|
+
contentEncoding: schema.contentEncoding,
|
|
42
|
+
contentMediaType: schema.contentMediaType,
|
|
43
|
+
minItems: schema.minItems,
|
|
44
|
+
maxItems: schema.maxItems,
|
|
45
|
+
nullable: schema.nullable || schema['x-nullable'],
|
|
46
|
+
schema,
|
|
47
|
+
displayType: '',
|
|
48
|
+
items: undefined,
|
|
49
|
+
extensions: undefined,
|
|
50
|
+
oneOfType: '',
|
|
51
|
+
discriminatorProp: undefined,
|
|
52
|
+
oneOf: undefined,
|
|
53
|
+
[REDOCLY_TEAMS_RBAC]: schema[REDOCLY_TEAMS_RBAC],
|
|
54
|
+
['x-enumDescriptions']: getValueFromMdParsedExtension(schema, 'x-enumDescriptions'),
|
|
55
|
+
get fields() {
|
|
56
|
+
if (!schemaModel.isCircular &&
|
|
57
|
+
!schemaModel.isComplex &&
|
|
58
|
+
(hasType(schemaModel, 'object') || (hasType(schemaModel, 'array') && hasArrayItems(schema)))) {
|
|
59
|
+
return buildFields(parser, schema, schemaPointer, options, refsStack, deps);
|
|
60
|
+
}
|
|
61
|
+
return;
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
if (schema.nullable || schema['x-nullable']) {
|
|
65
|
+
if (Array.isArray(schemaModel.type) &&
|
|
66
|
+
!schemaModel.type.some((value) => value === null || value === 'null')) {
|
|
67
|
+
schemaModel.type = [...schemaModel.type, 'null'];
|
|
68
|
+
}
|
|
69
|
+
else if (!Array.isArray(schemaModel.type) &&
|
|
70
|
+
(schemaModel.type !== null || schemaModel.type !== 'null')) {
|
|
71
|
+
schemaModel.type = [schemaModel.type, 'null'];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
schemaModel.displayType = Array.isArray(schemaModel.type)
|
|
75
|
+
? schemaModel.type.map((item) => (item === null ? 'null' : item)).join(' or ')
|
|
76
|
+
: schemaModel.type;
|
|
77
|
+
if (schemaModel.isCircular) {
|
|
78
|
+
return schemaModel;
|
|
79
|
+
}
|
|
80
|
+
if ((schema.if && schema.then) || (schema.if && schema.else)) {
|
|
81
|
+
const { oneOf, oneOfType } = initConditionalOperators({
|
|
82
|
+
schema,
|
|
83
|
+
parser,
|
|
84
|
+
pointer: schemaPointer,
|
|
85
|
+
options,
|
|
86
|
+
deps,
|
|
87
|
+
refsStack,
|
|
88
|
+
});
|
|
89
|
+
schemaModel.oneOf = oneOf;
|
|
90
|
+
schemaModel.oneOfType = oneOfType;
|
|
91
|
+
return schemaModel;
|
|
92
|
+
}
|
|
93
|
+
if (!isChild && getDiscriminator(schema) !== undefined) {
|
|
94
|
+
const { oneOf, discriminatorProp } = initDiscriminator({
|
|
95
|
+
schema,
|
|
96
|
+
parser,
|
|
97
|
+
deps: deps,
|
|
98
|
+
mergedSchema: schema,
|
|
99
|
+
options: options,
|
|
100
|
+
pointer: schemaPointer,
|
|
101
|
+
refsStack,
|
|
102
|
+
});
|
|
103
|
+
schemaModel.oneOf = oneOf;
|
|
104
|
+
schemaModel.discriminatorProp = discriminatorProp;
|
|
105
|
+
return schemaModel;
|
|
106
|
+
}
|
|
107
|
+
else if (isChild &&
|
|
108
|
+
Array.isArray(schema.oneOf) &&
|
|
109
|
+
schema.oneOf.find((s) => s.$ref === schemaPointer)) {
|
|
110
|
+
// we hit allOf of the schema with the parent discriminator
|
|
111
|
+
delete schema.oneOf;
|
|
112
|
+
}
|
|
113
|
+
if (schema.oneOf !== undefined) {
|
|
114
|
+
const { oneOf, displayType } = initOneOf({
|
|
115
|
+
schemaOneOf: schema.oneOf,
|
|
116
|
+
parser,
|
|
117
|
+
deps,
|
|
118
|
+
options,
|
|
119
|
+
pointer: schemaPointer,
|
|
120
|
+
refsStack,
|
|
121
|
+
schema,
|
|
122
|
+
});
|
|
123
|
+
schemaModel.oneOfType = 'One of';
|
|
124
|
+
if (oneOf) {
|
|
125
|
+
schemaModel.oneOf = oneOf;
|
|
126
|
+
}
|
|
127
|
+
schemaModel.displayType = displayType;
|
|
128
|
+
if (schema.anyOf !== undefined) {
|
|
129
|
+
console.warn(`oneOf and anyOf are not supported on the same level. Skipping anyOf at ${schemaPointer}`);
|
|
130
|
+
}
|
|
131
|
+
return schemaModel;
|
|
132
|
+
}
|
|
133
|
+
if (schema.anyOf !== undefined) {
|
|
134
|
+
const { oneOf, displayType } = initOneOf({
|
|
135
|
+
schemaOneOf: schema.anyOf,
|
|
136
|
+
parser,
|
|
137
|
+
deps,
|
|
138
|
+
options,
|
|
139
|
+
pointer: schemaPointer,
|
|
140
|
+
refsStack,
|
|
141
|
+
schema,
|
|
142
|
+
});
|
|
143
|
+
if (oneOf) {
|
|
144
|
+
schemaModel.oneOf = oneOf;
|
|
145
|
+
}
|
|
146
|
+
schemaModel.displayType = displayType;
|
|
147
|
+
schemaModel.oneOfType = 'Any of';
|
|
148
|
+
return schemaModel;
|
|
149
|
+
}
|
|
150
|
+
if (hasType(schemaModel, 'array')) {
|
|
151
|
+
if (schema.items && !hasArrayItems(schema)) {
|
|
152
|
+
schemaModel.items = getSchema({
|
|
153
|
+
parser,
|
|
154
|
+
schemaOrRef: Object.assign({ type: 'object' }, schema.items),
|
|
155
|
+
pointer: schemaPointer + '/items',
|
|
156
|
+
options,
|
|
157
|
+
baseRefsStack: refsStack,
|
|
158
|
+
deps,
|
|
159
|
+
absolutePointer: JsonPointer.join(schema.absolutePointer || '', ['items']),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
schemaModel.displayType =
|
|
163
|
+
schema.prefixItems || Array.isArray(schema.items)
|
|
164
|
+
? 'items'
|
|
165
|
+
: pluralizeType(schemaModel.items?.displayType || schemaModel.displayType);
|
|
166
|
+
schemaModel.displayFormat = schemaModel.items?.format || '';
|
|
167
|
+
schemaModel.typePrefix = schemaModel.items?.typePrefix || '' + 'Array of ';
|
|
168
|
+
schemaModel.title = schemaModel.title || schemaModel.items?.title || '';
|
|
169
|
+
schemaModel.isPrimitive =
|
|
170
|
+
schemaModel.items?.isPrimitive !== undefined
|
|
171
|
+
? schemaModel.items?.isPrimitive
|
|
172
|
+
: schemaModel.isPrimitive;
|
|
173
|
+
if (schemaModel.example === undefined && schemaModel.items?.example !== undefined) {
|
|
174
|
+
schemaModel.example = [schemaModel.items.example];
|
|
175
|
+
}
|
|
176
|
+
if (schemaModel.items?.isPrimitive) {
|
|
177
|
+
schemaModel.enum = schemaModel.items.enum;
|
|
178
|
+
schemaModel['x-enumDescriptions'] = getValueFromMdParsedExtension(schemaModel.items, 'x-enumDescriptions');
|
|
179
|
+
}
|
|
180
|
+
if (Array.isArray(schemaModel.type)) {
|
|
181
|
+
const filteredType = schemaModel.type.filter((item) => item !== 'array');
|
|
182
|
+
if (filteredType.length) {
|
|
183
|
+
schemaModel.displayType += ` or ${filteredType.join(' or ')}`;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (options.showExtensions) {
|
|
188
|
+
schemaModel.extensions = extractExtensions(schema, options.showExtensions);
|
|
189
|
+
}
|
|
190
|
+
return schemaModel;
|
|
191
|
+
}
|
|
192
|
+
function initDiscriminator({ schema, parser, pointer, options, refsStack, deps, mergedSchema, }) {
|
|
193
|
+
const discriminator = getDiscriminator(schema);
|
|
194
|
+
const discriminatorProp = discriminator?.propertyName;
|
|
195
|
+
const implicitInvertedMapping = parser.findDerived([
|
|
196
|
+
...(mergedSchema['x-parentRefs'] || []),
|
|
197
|
+
pointer,
|
|
198
|
+
]);
|
|
199
|
+
if (schema.oneOf) {
|
|
200
|
+
for (const variant of schema.oneOf) {
|
|
201
|
+
if (variant.$ref === undefined) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const name = JsonPointer.baseName(variant.$ref);
|
|
205
|
+
implicitInvertedMapping[variant.$ref] = name;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const mapping = discriminator?.mapping || {};
|
|
209
|
+
// Defines if the mapping is exhaustive. This avoids having references
|
|
210
|
+
// that overlap with the mapping entries
|
|
211
|
+
let isLimitedToMapping = discriminator?.['x-explicitMappingOnly'] || false;
|
|
212
|
+
// if there are no mappings, assume non-exhaustive
|
|
213
|
+
if (Object.keys(mapping).length === 0) {
|
|
214
|
+
isLimitedToMapping = false;
|
|
215
|
+
}
|
|
216
|
+
const explicitInvertedMapping = {};
|
|
217
|
+
for (const name in mapping) {
|
|
218
|
+
const $ref = mapping[name];
|
|
219
|
+
if (Array.isArray(explicitInvertedMapping[$ref])) {
|
|
220
|
+
explicitInvertedMapping[$ref].push(name);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
// overrides implicit mapping here
|
|
224
|
+
explicitInvertedMapping[$ref] = [name];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const invertedMapping = isLimitedToMapping
|
|
228
|
+
? { ...explicitInvertedMapping }
|
|
229
|
+
: { ...implicitInvertedMapping, ...explicitInvertedMapping };
|
|
230
|
+
let refs = [];
|
|
231
|
+
for (const $ref of Object.keys(invertedMapping)) {
|
|
232
|
+
const names = invertedMapping[$ref];
|
|
233
|
+
if (Array.isArray(names)) {
|
|
234
|
+
for (const name of names) {
|
|
235
|
+
refs.push({ $ref, name });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
refs.push({ $ref, name: names });
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// Make the listing respects the mapping
|
|
243
|
+
// in case a mapping is defined, the user usually wants to have the order shown
|
|
244
|
+
// as it was defined in the yaml. This will sort the names given the provided
|
|
245
|
+
// mapping (if provided).
|
|
246
|
+
// The logic is:
|
|
247
|
+
// - If a name is among the mapping, promote it to first
|
|
248
|
+
// - Names among the mapping are sorted by their order in the mapping
|
|
249
|
+
// - Names outside the mapping are sorted alphabetically
|
|
250
|
+
const names = Object.keys(mapping);
|
|
251
|
+
if (names.length !== 0) {
|
|
252
|
+
refs = refs.sort((left, right) => {
|
|
253
|
+
const indexLeft = names.indexOf(left.name);
|
|
254
|
+
const indexRight = names.indexOf(right.name);
|
|
255
|
+
if (indexLeft < 0 && indexRight < 0) {
|
|
256
|
+
// out of mapping, order by name
|
|
257
|
+
return left.name.localeCompare(right.name);
|
|
258
|
+
}
|
|
259
|
+
else if (indexLeft < 0) {
|
|
260
|
+
// the right is found, so mapping wins
|
|
261
|
+
return 1;
|
|
262
|
+
}
|
|
263
|
+
else if (indexRight < 0) {
|
|
264
|
+
// left wins as it's in mapping
|
|
265
|
+
return -1;
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
return indexLeft - indexRight;
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
const oneOf = refs.map(({ $ref, name }, index) => {
|
|
273
|
+
const innerSchema = getSchema({
|
|
274
|
+
parser,
|
|
275
|
+
schemaOrRef: { $ref },
|
|
276
|
+
pointer: $ref,
|
|
277
|
+
options,
|
|
278
|
+
isChild: true,
|
|
279
|
+
baseRefsStack: refsStack.slice(0, -1),
|
|
280
|
+
deps: {
|
|
281
|
+
...deps,
|
|
282
|
+
parentFieldFullPath: deps.parentFieldFullPath
|
|
283
|
+
? deps.parentFieldFullPath + '&d=' + index
|
|
284
|
+
: '&d=' + index.toString(),
|
|
285
|
+
},
|
|
286
|
+
absolutePointer: mergedSchema.absolutePointer,
|
|
287
|
+
});
|
|
288
|
+
innerSchema.title = name;
|
|
289
|
+
return innerSchema;
|
|
290
|
+
});
|
|
291
|
+
return {
|
|
292
|
+
oneOf,
|
|
293
|
+
discriminatorProp,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function initOneOf({ schemaOneOf, parser, refsStack, pointer, schema, options, deps, }) {
|
|
297
|
+
const oneOf = schemaOneOf.map((variant, idx) => {
|
|
298
|
+
const { resolved: derefVariant, refsStack: derefRefsStack } = parser.deref(variant, refsStack, true);
|
|
299
|
+
const merged = parser.mergeAllOf(derefVariant, pointer + '/oneOf/' + idx, derefRefsStack);
|
|
300
|
+
// try to infer title
|
|
301
|
+
const title = isNamedDefinition(variant.$ref) && !merged.title
|
|
302
|
+
? JsonPointer.baseName(variant.$ref)
|
|
303
|
+
: `${merged.title || ''}${(merged.const && JSON.stringify(merged.const)) || ''}`;
|
|
304
|
+
const resultSchema = getSchema({
|
|
305
|
+
parser,
|
|
306
|
+
// merge base schema into each of oneOf's subschemas
|
|
307
|
+
schemaOrRef: {
|
|
308
|
+
// variant may already have allOf so merge it to not get overwritten
|
|
309
|
+
...merged,
|
|
310
|
+
title,
|
|
311
|
+
allOf: [{ ...schema, oneOf: undefined, anyOf: undefined }],
|
|
312
|
+
// if specific child schemas are listed in oneOf/anyOf, they are not supposed to be discriminated
|
|
313
|
+
discriminator: derefVariant.allOf ? undefined : merged.discriminator,
|
|
314
|
+
},
|
|
315
|
+
pointer: variant.$ref || pointer + '/oneOf/' + idx,
|
|
316
|
+
options,
|
|
317
|
+
baseRefsStack: derefRefsStack,
|
|
318
|
+
deps: {
|
|
319
|
+
...deps,
|
|
320
|
+
parentFieldFullPath: deps.parentFieldFullPath
|
|
321
|
+
? deps.parentFieldFullPath + '&oneOf=' + idx
|
|
322
|
+
: '&oneOf=' + idx.toString(),
|
|
323
|
+
},
|
|
324
|
+
});
|
|
325
|
+
return resultSchema;
|
|
326
|
+
});
|
|
327
|
+
const displayType = [
|
|
328
|
+
...new Set(oneOf.map((schema) => {
|
|
329
|
+
let name = schema.typePrefix +
|
|
330
|
+
(schema.title && !options.hideSchemaTitles
|
|
331
|
+
? `${schema.title} (${schema.displayType})`
|
|
332
|
+
: schema.displayType);
|
|
333
|
+
if (name.indexOf(' or ') > -1) {
|
|
334
|
+
name = `(${name})`;
|
|
335
|
+
}
|
|
336
|
+
return name;
|
|
337
|
+
})),
|
|
338
|
+
].join(' or ');
|
|
339
|
+
return { oneOf, displayType };
|
|
340
|
+
}
|
|
341
|
+
function initConditionalOperators({ schema, parser, pointer, options, refsStack, deps, }) {
|
|
342
|
+
const { if: ifOperator, else: elseOperator = {}, then: thenOperator = {}, ...restSchema } = schema;
|
|
343
|
+
const groupedOperators = [
|
|
344
|
+
{
|
|
345
|
+
allOf: [restSchema, thenOperator, ifOperator],
|
|
346
|
+
title: (ifOperator && ifOperator['x-displayName']) || ifOperator?.title || 'case 1',
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
allOf: [restSchema, elseOperator],
|
|
350
|
+
title: (elseOperator && elseOperator['x-displayName']) || elseOperator?.title || 'case 2',
|
|
351
|
+
},
|
|
352
|
+
];
|
|
353
|
+
const oneOf = groupedOperators.map((variant, idx) => getSchema({
|
|
354
|
+
parser,
|
|
355
|
+
schemaOrRef: {
|
|
356
|
+
...variant,
|
|
357
|
+
},
|
|
358
|
+
pointer: pointer + '/oneOf/' + idx,
|
|
359
|
+
options,
|
|
360
|
+
baseRefsStack: refsStack,
|
|
361
|
+
deps: {
|
|
362
|
+
...deps,
|
|
363
|
+
parentFieldFullPath: deps.parentFieldFullPath
|
|
364
|
+
? deps.parentFieldFullPath + '&oneOf=' + idx
|
|
365
|
+
: '&oneOf=' + idx.toString(),
|
|
366
|
+
},
|
|
367
|
+
}));
|
|
368
|
+
const oneOfType = 'One of';
|
|
369
|
+
return { oneOf, oneOfType };
|
|
370
|
+
}
|
|
371
|
+
function normalizeField(field, fieldName, $ref) {
|
|
372
|
+
if (field) {
|
|
373
|
+
return field;
|
|
374
|
+
}
|
|
375
|
+
console.warn(`Field "${fieldName}" is invalid, skipping.\n Field must be an object but got ${typeof field} at "${$ref}"`);
|
|
376
|
+
return {};
|
|
377
|
+
}
|
|
378
|
+
function buildFields(parser, schema, $ref, options, refsStack, deps) {
|
|
379
|
+
let props = schema.properties ||
|
|
380
|
+
(hasType(schema, 'array') ? schema.prefixItems || schema.items : undefined) ||
|
|
381
|
+
{};
|
|
382
|
+
const patternProps = schema.patternProperties || {};
|
|
383
|
+
// TODO: if schema has $ref and allOf,anyOf,oneOf,if,then,else, ignore schema.additionalProperties
|
|
384
|
+
const additionalProps = schema.additionalProperties || schema.unevaluatedProperties;
|
|
385
|
+
const itemsProps = schema.prefixItems ? schema.items : schema.additionalItems;
|
|
386
|
+
const defaults = schema.default || {};
|
|
387
|
+
let fields = Object.keys(props).map((fieldName) => {
|
|
388
|
+
const field = normalizeField(props[fieldName], fieldName, $ref);
|
|
389
|
+
const required = schema.required === undefined ? false : schema.required.indexOf(fieldName) > -1;
|
|
390
|
+
return getField(parser, {
|
|
391
|
+
name: schema.properties ? fieldName : `[${fieldName}]`,
|
|
392
|
+
required,
|
|
393
|
+
schema: {
|
|
394
|
+
...field,
|
|
395
|
+
example: schema.example?.[fieldName] || field.example,
|
|
396
|
+
default: field.default === undefined && defaults ? defaults[fieldName] : field.default,
|
|
397
|
+
},
|
|
398
|
+
}, $ref + '/properties/' + fieldName, options, deps, refsStack, JsonPointer.join(schema.absolutePointer || '', ['properties', fieldName]));
|
|
399
|
+
});
|
|
400
|
+
if (options.sortRequiredPropsFirst) {
|
|
401
|
+
fields = sortByRequired(fields, schema.required);
|
|
402
|
+
}
|
|
403
|
+
fields.push(...Object.keys(patternProps).map((fieldName) => {
|
|
404
|
+
const field = normalizeField(patternProps[fieldName], fieldName, $ref);
|
|
405
|
+
return getField(parser, {
|
|
406
|
+
name: fieldName,
|
|
407
|
+
required: false,
|
|
408
|
+
schema: field,
|
|
409
|
+
kind: 'patternProperties',
|
|
410
|
+
}, `${$ref}/patternProperties/${fieldName}`, options, deps, refsStack);
|
|
411
|
+
}));
|
|
412
|
+
if (isObject(additionalProps) || additionalProps === true) {
|
|
413
|
+
fields.push(getField(parser, {
|
|
414
|
+
name: (isObject(additionalProps)
|
|
415
|
+
? additionalProps['x-additionalPropertiesName'] || 'property name'
|
|
416
|
+
: 'property name').concat('*'),
|
|
417
|
+
required: false,
|
|
418
|
+
schema: additionalProps === true ? {} : additionalProps,
|
|
419
|
+
kind: 'additionalProperties',
|
|
420
|
+
}, $ref + '/additionalProperties', options, deps, refsStack, JsonPointer.join(schema.absolutePointer || '', ['additionalProperties'])));
|
|
421
|
+
}
|
|
422
|
+
fields.push(...buildAdditionalItems({
|
|
423
|
+
parser,
|
|
424
|
+
schema: itemsProps,
|
|
425
|
+
fieldsCount: fields.length,
|
|
426
|
+
$ref,
|
|
427
|
+
options,
|
|
428
|
+
refsStack,
|
|
429
|
+
deps,
|
|
430
|
+
}));
|
|
431
|
+
return sortByDeprecated(fields);
|
|
432
|
+
}
|
|
433
|
+
function buildAdditionalItems({ parser, schema = false, fieldsCount, $ref, options, refsStack, deps, }) {
|
|
434
|
+
if (typeof schema === 'boolean') {
|
|
435
|
+
return schema
|
|
436
|
+
? [
|
|
437
|
+
getField(parser, {
|
|
438
|
+
name: `[${fieldsCount}...]`,
|
|
439
|
+
schema: {},
|
|
440
|
+
kind: 'additionalItems',
|
|
441
|
+
}, `${$ref}/additionalItems`, options, deps, refsStack),
|
|
442
|
+
]
|
|
443
|
+
: [];
|
|
444
|
+
}
|
|
445
|
+
if (Array.isArray(schema)) {
|
|
446
|
+
return [
|
|
447
|
+
...schema.map((field, idx) => getField(parser, {
|
|
448
|
+
name: `[${fieldsCount + idx}]`,
|
|
449
|
+
schema: field,
|
|
450
|
+
kind: 'additionalItems',
|
|
451
|
+
}, `${$ref}/additionalItems/${idx}`, options, deps, refsStack)),
|
|
452
|
+
];
|
|
453
|
+
}
|
|
454
|
+
if (isObject(schema)) {
|
|
455
|
+
return [
|
|
456
|
+
getField(parser, {
|
|
457
|
+
name: `[${fieldsCount}...]`,
|
|
458
|
+
schema: schema,
|
|
459
|
+
kind: 'additionalItems',
|
|
460
|
+
}, `${$ref}/additionalItems`, options, deps, refsStack),
|
|
461
|
+
];
|
|
462
|
+
}
|
|
463
|
+
return [];
|
|
464
|
+
}
|
|
465
|
+
function getDiscriminator(schema) {
|
|
466
|
+
return schema.discriminator || schema['x-discriminator'];
|
|
467
|
+
}
|
|
468
|
+
function hasType(schema, type) {
|
|
469
|
+
return schema.type === type || (Array.isArray(schema.type) && schema.type.includes(type));
|
|
470
|
+
}
|
|
471
|
+
function hasArrayItems(schema) {
|
|
472
|
+
return Boolean(Array.isArray(schema.items) || Array.isArray(schema.prefixItems));
|
|
473
|
+
}
|
|
474
|
+
//# sourceMappingURL=schema.js.map
|
package/lib/models/security.js
CHANGED
|
@@ -1 +1,84 @@
|
|
|
1
|
-
import{getValueFromMdParsedExtension
|
|
1
|
+
import { getValueFromMdParsedExtension } from '../utils/index.js';
|
|
2
|
+
export function getSecurity(requirements = [], parser) {
|
|
3
|
+
return requirements
|
|
4
|
+
.map((requirement) => getSecurityRequirement({ requirement, parser }))
|
|
5
|
+
.filter(({ schemes }) => schemes.length > 0);
|
|
6
|
+
}
|
|
7
|
+
function getSecurityRequirement({ requirement, parser, }) {
|
|
8
|
+
const schemes = (parser.definition.components && parser.definition.components.securitySchemes) || {};
|
|
9
|
+
const filteredSchemes = Object.keys(requirement || {})
|
|
10
|
+
.map((id) => {
|
|
11
|
+
const scheme = parser.deref(schemes[id]).resolved;
|
|
12
|
+
const scopes = requirement[id] || [];
|
|
13
|
+
if (!scheme) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
...scheme,
|
|
18
|
+
id,
|
|
19
|
+
sectionId: id,
|
|
20
|
+
scopes,
|
|
21
|
+
};
|
|
22
|
+
})
|
|
23
|
+
.filter(Boolean);
|
|
24
|
+
return {
|
|
25
|
+
schemes: filteredSchemes,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function getSecurityScheme(parser, id, scheme) {
|
|
29
|
+
if (!parser?.deref) {
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
const { resolved: info } = parser.deref(scheme);
|
|
33
|
+
const sectionId = id;
|
|
34
|
+
const type = info.type;
|
|
35
|
+
const description = getValueFromMdParsedExtension(info, 'description') || '';
|
|
36
|
+
let apiKey = undefined;
|
|
37
|
+
let http = undefined;
|
|
38
|
+
let openId = undefined;
|
|
39
|
+
let flows = {};
|
|
40
|
+
switch (info.type) {
|
|
41
|
+
case 'apiKey': {
|
|
42
|
+
apiKey = {
|
|
43
|
+
name: info.name,
|
|
44
|
+
in: info.in,
|
|
45
|
+
};
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case 'http': {
|
|
49
|
+
http = {
|
|
50
|
+
scheme: info.scheme,
|
|
51
|
+
bearerFormat: info.bearerFormat,
|
|
52
|
+
};
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case 'openIdConnect': {
|
|
56
|
+
openId = {
|
|
57
|
+
connectUrl: info.openIdConnectUrl,
|
|
58
|
+
};
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case 'oauth2': {
|
|
62
|
+
flows = info.flows;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
id,
|
|
68
|
+
sectionId,
|
|
69
|
+
type,
|
|
70
|
+
description,
|
|
71
|
+
apiKey,
|
|
72
|
+
http,
|
|
73
|
+
flows,
|
|
74
|
+
openId,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export function getSecuritySchemes({ parser, }) {
|
|
78
|
+
if (!parser) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
const schemes = parser.definition?.components?.securitySchemes || {};
|
|
82
|
+
return Object.keys(schemes).map((name) => getSecurityScheme(parser, name, schemes[name]));
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=security.js.map
|
package/lib/models/tab.js
CHANGED
package/lib/models/types.js
CHANGED