@stoplight/elements-core 9.0.10 → 9.0.12-beta-0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.storybook/main.js +6 -0
- package/.storybook/manager.js +1 -0
- package/.storybook/preview.jsx +50 -0
- package/dist/LICENSE +190 -0
- package/dist/README.md +1 -0
- package/{index.esm.js → dist/index.esm.js} +64 -20
- package/{index.js → dist/index.js} +64 -21
- package/{index.mjs → dist/index.mjs} +64 -20
- package/dist/package.json +64 -0
- package/dist/styled.d.ts +5 -0
- package/jest.config.js +10 -0
- package/package.json +74 -14
- package/src/__fixtures__/articles/basic.md +10 -0
- package/src/__fixtures__/articles/kitchen-sink.md +318 -0
- package/src/__fixtures__/articles/long-page-heading.md +955 -0
- package/src/__fixtures__/articles/multiple-try-its.md +54 -0
- package/src/__fixtures__/articles/schema-with-refs.ts +82 -0
- package/src/__fixtures__/http-request.json +11 -0
- package/src/__fixtures__/models/model-with-no-examples.json +15 -0
- package/src/__fixtures__/models/model-with-one-example.json +23 -0
- package/src/__fixtures__/models/model-with-three-examples.json +35 -0
- package/src/__fixtures__/operations/application-octet-stream-post.ts +39 -0
- package/src/__fixtures__/operations/base64-file-upload.ts +43 -0
- package/src/__fixtures__/operations/big-response.ts +4690 -0
- package/src/__fixtures__/operations/bundled-parameter.ts +128 -0
- package/src/__fixtures__/operations/empty-response.ts +15 -0
- package/src/__fixtures__/operations/examples-request-body.ts +135 -0
- package/src/__fixtures__/operations/head-todos.ts +49 -0
- package/src/__fixtures__/operations/invalid-response-example.ts +45 -0
- package/src/__fixtures__/operations/multipart-formdata-post.ts +61 -0
- package/src/__fixtures__/operations/operation-minimal.ts +11 -0
- package/src/__fixtures__/operations/operation-parameters.ts +337 -0
- package/src/__fixtures__/operations/operation-with-examples.ts +113 -0
- package/src/__fixtures__/operations/operation-without-servers.ts +16 -0
- package/src/__fixtures__/operations/patch-todos.ts +49 -0
- package/src/__fixtures__/operations/put-todos.ts +862 -0
- package/src/__fixtures__/operations/referenced-body.ts +62 -0
- package/src/__fixtures__/operations/request-body-empty-schema.ts +35 -0
- package/src/__fixtures__/operations/request-body.ts +62 -0
- package/src/__fixtures__/operations/securedOperation.ts +118 -0
- package/src/__fixtures__/operations/security-basic.ts +24 -0
- package/src/__fixtures__/operations/security-bearer.ts +25 -0
- package/src/__fixtures__/operations/simple-get.ts +17 -0
- package/src/__fixtures__/operations/simple.ts +103 -0
- package/src/__fixtures__/operations/string-numeric-enums.ts +32 -0
- package/src/__fixtures__/operations/urlencoded-post-oneof.ts +81 -0
- package/src/__fixtures__/operations/urlencoded-post.ts +54 -0
- package/src/__fixtures__/operations/vendor-extensions.ts +337 -0
- package/src/__fixtures__/operations/with-url-variables.ts +47 -0
- package/src/__fixtures__/operations/x-code-samples.ts +348 -0
- package/src/__fixtures__/schemas/circular.ts +1906 -0
- package/src/__fixtures__/schemas/contact.json +293 -0
- package/src/__fixtures__/schemas/media-entry.json +69 -0
- package/src/__fixtures__/schemas/simple.json +27 -0
- package/src/__fixtures__/schemas/todo-full.v1.json +35 -0
- package/src/__fixtures__/schemas/todo-partial.v1.json +14 -0
- package/src/__fixtures__/schemas/user.v1.json +17 -0
- package/src/__fixtures__/security-schemes/index.ts +38 -0
- package/src/__fixtures__/services/petstore.ts +167 -0
- package/src/__fixtures__/services/with-unnamed-servers.ts +38 -0
- package/src/__fixtures__/services/with-url-variables.ts +83 -0
- package/src/__fixtures__/services/without-origin.ts +20 -0
- package/src/__fixtures__/table-of-contents/nested.ts +44 -0
- package/src/__fixtures__/table-of-contents/studio-template.ts +100 -0
- package/src/__fixtures__/table-of-contents/studio.ts +559 -0
- package/src/components/Docs/Article/Article.spec.tsx +38 -0
- package/src/components/Docs/Article/Article.stories.tsx +17 -0
- package/src/components/Docs/Article/index.tsx +38 -0
- package/src/components/Docs/Docs.stories.tsx +33 -0
- package/src/components/Docs/Docs.tsx +272 -0
- package/src/components/Docs/HttpOperation/Badges.tsx +49 -0
- package/src/components/Docs/HttpOperation/Body.tsx +115 -0
- package/src/components/Docs/HttpOperation/Callbacks.tsx +89 -0
- package/src/components/Docs/HttpOperation/HttpOperation.spec.tsx +787 -0
- package/src/components/Docs/HttpOperation/HttpOperation.stories.ts +14 -0
- package/src/components/Docs/HttpOperation/HttpOperation.tsx +260 -0
- package/src/components/Docs/HttpOperation/LazySchemaTreePreviewer.tsx +651 -0
- package/src/components/Docs/HttpOperation/Parameters.spec.tsx +101 -0
- package/src/components/Docs/HttpOperation/Parameters.tsx +118 -0
- package/src/components/Docs/HttpOperation/Request.tsx +152 -0
- package/src/components/Docs/HttpOperation/Responses.tsx +301 -0
- package/src/components/Docs/HttpOperation/index.ts +1 -0
- package/src/components/Docs/HttpService/AdditionalInfo.stories.ts +48 -0
- package/src/components/Docs/HttpService/AdditionalInfo.tsx +61 -0
- package/src/components/Docs/HttpService/ExportButton.tsx +35 -0
- package/src/components/Docs/HttpService/HttpService.spec.tsx +429 -0
- package/src/components/Docs/HttpService/HttpService.stories.ts +14 -0
- package/src/components/Docs/HttpService/HttpService.tsx +99 -0
- package/src/components/Docs/HttpService/SecuritySchemes.tsx +82 -0
- package/src/components/Docs/HttpService/ServerInfo.tsx +196 -0
- package/src/components/Docs/HttpService/index.ts +1 -0
- package/src/components/Docs/Model/Model.spec.tsx +241 -0
- package/src/components/Docs/Model/Model.stories.tsx +16 -0
- package/src/components/Docs/Model/Model.tsx +192 -0
- package/src/components/Docs/Model/index.ts +1 -0
- package/src/components/Docs/NodeVendorExtensions.tsx +55 -0
- package/src/components/Docs/Sections.tsx +54 -0
- package/src/components/Docs/Security/PanelContent.tsx +38 -0
- package/src/components/Docs/Security/index.ts +1 -0
- package/src/components/Docs/Skeleton.tsx +12 -0
- package/src/components/Docs/TwoColumnLayout.tsx +27 -0
- package/src/components/Docs/index.ts +1 -0
- package/src/components/Docs/story-helper.ts +46 -0
- package/src/components/Docs/story-renderer-helper.tsx +56 -0
- package/src/components/Layout/MobileTopNav.tsx +78 -0
- package/src/components/Layout/ResponsiveSidebarLayout.tsx +175 -0
- package/src/components/Layout/SidebarLayout.tsx +107 -0
- package/src/components/LinkHeading.tsx +21 -0
- package/src/components/LoadMore.tsx +20 -0
- package/src/components/Loading/Loading.tsx +9 -0
- package/src/components/Logo.tsx +25 -0
- package/src/components/MarkdownViewer/CustomComponents/CodeComponent.spec.ts +90 -0
- package/src/components/MarkdownViewer/CustomComponents/CodeComponent.tsx +164 -0
- package/src/components/MarkdownViewer/CustomComponents/Provider.tsx +20 -0
- package/src/components/MarkdownViewer/CustomComponents/ReactRouterLink.tsx +27 -0
- package/src/components/MarkdownViewer/CustomComponents/ResolvedImage.tsx +86 -0
- package/src/components/MarkdownViewer/CustomComponents/ScrollToHashElement.tsx +96 -0
- package/src/components/MarkdownViewer/MarkdownViewer.spec.tsx +170 -0
- package/src/components/MarkdownViewer/index.tsx +10 -0
- package/src/components/NonIdealState.tsx +20 -0
- package/src/components/PoweredByLink.tsx +30 -0
- package/src/components/RequestSamples/RequestSamples.stories.tsx +67 -0
- package/src/components/RequestSamples/RequestSamples.tsx +246 -0
- package/src/components/RequestSamples/__tests__/RequestSamples.test.tsx +131 -0
- package/src/components/RequestSamples/__tests__/__snapshots__/convertRequestToSample.spec.ts.snap +746 -0
- package/src/components/RequestSamples/__tests__/convertRequestToSample.spec.ts +118 -0
- package/src/components/RequestSamples/convertRequestToSample.ts +56 -0
- package/src/components/RequestSamples/extractCodeSamples.ts +50 -0
- package/src/components/RequestSamples/index.ts +2 -0
- package/src/components/RequestSamples/requestSampleConfigs.ts +182 -0
- package/src/components/ResponseExamples/ResponseExamples.spec.tsx +121 -0
- package/src/components/ResponseExamples/ResponseExamples.stories.tsx +21 -0
- package/src/components/ResponseExamples/ResponseExamples.tsx +79 -0
- package/src/components/TableOfContents/TableOfContents.spec.tsx +301 -0
- package/src/components/TableOfContents/TableOfContents.stories.tsx +121 -0
- package/src/components/TableOfContents/TableOfContents.tsx +406 -0
- package/src/components/TableOfContents/constants.ts +45 -0
- package/src/components/TableOfContents/index.ts +2 -0
- package/src/components/TableOfContents/types.ts +51 -0
- package/src/components/TableOfContents/utils.ts +84 -0
- package/src/components/TryIt/Auth/APIKeyAuth.tsx +19 -0
- package/src/components/TryIt/Auth/Auth.tsx +169 -0
- package/src/components/TryIt/Auth/AuthTokenInput.tsx +37 -0
- package/src/components/TryIt/Auth/BasicAuth.tsx +62 -0
- package/src/components/TryIt/Auth/BearerAuth.tsx +19 -0
- package/src/components/TryIt/Auth/DigestAuth.tsx +35 -0
- package/src/components/TryIt/Auth/OAuth2Auth.tsx +19 -0
- package/src/components/TryIt/Auth/authentication-utils.ts +113 -0
- package/src/components/TryIt/Body/BinaryBody.tsx +52 -0
- package/src/components/TryIt/Body/FormDataBody.tsx +145 -0
- package/src/components/TryIt/Body/RequestBody.tsx +71 -0
- package/src/components/TryIt/Body/__tests__/BinaryBody.test.tsx +29 -0
- package/src/components/TryIt/Body/__tests__/FormDataBody.test.tsx +94 -0
- package/src/components/TryIt/Body/request-body-utils.ts +127 -0
- package/src/components/TryIt/Body/useTextRequestBodyState.ts +27 -0
- package/src/components/TryIt/Mocking/MockingButton.tsx +98 -0
- package/src/components/TryIt/Mocking/mocking-utils.ts +56 -0
- package/src/components/TryIt/Mocking/useMockingOptions.ts +6 -0
- package/src/components/TryIt/Parameters/FileUploadParameterEditors.tsx +62 -0
- package/src/components/TryIt/Parameters/OperationParameters.tsx +39 -0
- package/src/components/TryIt/Parameters/ParameterEditor.tsx +118 -0
- package/src/components/TryIt/Parameters/__tests__/parameter-utils.spec.ts +60 -0
- package/src/components/TryIt/Parameters/parameter-utils.spec.ts +118 -0
- package/src/components/TryIt/Parameters/parameter-utils.ts +179 -0
- package/src/components/TryIt/Parameters/useOperationParameters.ts +60 -0
- package/src/components/TryIt/Response/ReponseCodeViewer.tsx +28 -0
- package/src/components/TryIt/Response/Response.spec.tsx +174 -0
- package/src/components/TryIt/Response/Response.tsx +172 -0
- package/src/components/TryIt/Response/hooks/useLineCount.ts +7 -0
- package/src/components/TryIt/Servers/ServerVariables.tsx +33 -0
- package/src/components/TryIt/Servers/ServersDropdown.tsx +53 -0
- package/src/components/TryIt/Servers/VariableEditor.tsx +51 -0
- package/src/components/TryIt/Servers/useServerVariables.ts +19 -0
- package/src/components/TryIt/TryIt.spec.tsx +1511 -0
- package/src/components/TryIt/TryIt.stories.tsx +77 -0
- package/src/components/TryIt/TryIt.tsx +384 -0
- package/src/components/TryIt/TryItWithRequestSamples.spec.tsx +143 -0
- package/src/components/TryIt/TryItWithRequestSamples.stories.tsx +32 -0
- package/src/components/TryIt/TryItWithRequestSamples.tsx +42 -0
- package/src/components/TryIt/build-request.spec.ts +213 -0
- package/src/components/TryIt/build-request.ts +357 -0
- package/src/components/TryIt/chosenServer.ts +5 -0
- package/src/components/TryIt/index.ts +3 -0
- package/src/components/__tests__/LinkHeading.spec.tsx +125 -0
- package/src/constants.ts +176 -0
- package/src/containers/MockingProvider.tsx +23 -0
- package/src/context/InlineRefResolver.spec.tsx +183 -0
- package/src/context/InlineRefResolver.tsx +94 -0
- package/src/context/Options.tsx +27 -0
- package/src/context/Persistence.tsx +24 -0
- package/src/context/RouterType.tsx +9 -0
- package/src/core.css +97 -0
- package/src/hoc/utils.ts +5 -0
- package/src/hoc/withMosaicProvider.spec.tsx +48 -0
- package/src/hoc/withMosaicProvider.tsx +28 -0
- package/src/hoc/withQueryClientProvider.spec.tsx +38 -0
- package/src/hoc/withQueryClientProvider.tsx +35 -0
- package/src/hoc/withRouter.tsx +71 -0
- package/src/hooks/useBundleRefsIntoDocument.ts +60 -0
- package/src/hooks/useFirstRender.ts +8 -0
- package/src/hooks/useIsCompact.ts +26 -0
- package/src/hooks/useParsedData.ts +99 -0
- package/src/hooks/useParsedValue.ts +19 -0
- package/src/hooks/useResponsiveLayout.tsx +51 -0
- package/src/hooks/useRouter.tsx +31 -0
- package/src/hooks/useUniqueId.ts +4 -0
- package/src/index.ts +48 -0
- package/src/styled.tsx +22 -0
- package/src/styles.css +4 -0
- package/src/types.ts +170 -0
- package/src/utils/__tests__/securitySchemes.spec.ts +137 -0
- package/src/utils/exampleGeneration/exampleGeneration.spec.tsx +18 -0
- package/src/utils/exampleGeneration/exampleGeneration.ts +110 -0
- package/src/utils/fileToBase64.ts +11 -0
- package/src/utils/guards.ts +48 -0
- package/src/utils/headers.ts +316 -0
- package/src/utils/http-spec/IServer.ts +100 -0
- package/src/utils/http-spec/__tests__/IServer.spec.ts +51 -0
- package/src/utils/http-spec/examples.ts +5 -0
- package/src/utils/http.ts +9 -0
- package/src/utils/jotai/persistAtom.ts +31 -0
- package/src/utils/node.ts +19 -0
- package/src/utils/oas/__tests__/security.spec.ts +18 -0
- package/src/utils/oas/security.ts +76 -0
- package/src/utils/ref-resolving/ReferenceResolver.ts +29 -0
- package/src/utils/ref-resolving/resolvedObject.test.ts +415 -0
- package/src/utils/ref-resolving/resolvedObject.ts +109 -0
- package/src/utils/securitySchemes.ts +117 -0
- package/src/utils/string.ts +15 -0
- package/src/utils/tests/chooseOption.ts +7 -0
- package/src/web-components/createElementClass.ts +154 -0
- package/tsconfig.build.json +14 -0
- package/tsconfig.json +7 -0
- package/styled.d.ts +0 -12
- /package/{__fixtures__ → dist/__fixtures__}/articles/schema-with-refs.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/application-octet-stream-post.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/base64-file-upload.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/big-response.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/examples-request-body.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/head-todos.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/multipart-formdata-post.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/operation-minimal.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/operation-parameters.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/operation-with-examples.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/operation-without-servers.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/patch-todos.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/put-todos.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/referenced-body.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/request-body-empty-schema.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/request-body.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/securedOperation.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/security-basic.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/security-bearer.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/simple-get.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/string-numeric-enums.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/urlencoded-post-oneof.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/urlencoded-post.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/operations/with-url-variables.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/security-schemes/index.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/services/petstore.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/services/with-unnamed-servers.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/services/with-url-variables.d.ts +0 -0
- /package/{__fixtures__ → dist/__fixtures__}/services/without-origin.d.ts +0 -0
- /package/{components → dist/components}/Docs/Article/Article.spec.d.ts +0 -0
- /package/{components → dist/components}/Docs/Article/Article.stories.d.ts +0 -0
- /package/{components → dist/components}/Docs/Article/index.d.ts +0 -0
- /package/{components → dist/components}/Docs/Docs.d.ts +0 -0
- /package/{components → dist/components}/Docs/Docs.stories.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpOperation/Badges.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpOperation/Body.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpOperation/Callbacks.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpOperation/HttpOperation.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpOperation/HttpOperation.spec.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpOperation/HttpOperation.stories.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpOperation/LazySchemaTreePreviewer.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpOperation/Parameters.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpOperation/Parameters.spec.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpOperation/Request.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpOperation/Responses.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpOperation/index.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpService/AdditionalInfo.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpService/AdditionalInfo.stories.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpService/ExportButton.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpService/HttpService.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpService/HttpService.spec.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpService/HttpService.stories.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpService/SecuritySchemes.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpService/ServerInfo.d.ts +0 -0
- /package/{components → dist/components}/Docs/HttpService/index.d.ts +0 -0
- /package/{components → dist/components}/Docs/Model/Model.d.ts +0 -0
- /package/{components → dist/components}/Docs/Model/Model.spec.d.ts +0 -0
- /package/{components → dist/components}/Docs/Model/Model.stories.d.ts +0 -0
- /package/{components → dist/components}/Docs/Model/index.d.ts +0 -0
- /package/{components → dist/components}/Docs/NodeVendorExtensions.d.ts +0 -0
- /package/{components → dist/components}/Docs/Sections.d.ts +0 -0
- /package/{components → dist/components}/Docs/Security/PanelContent.d.ts +0 -0
- /package/{components → dist/components}/Docs/Security/index.d.ts +0 -0
- /package/{components → dist/components}/Docs/Skeleton.d.ts +0 -0
- /package/{components → dist/components}/Docs/TwoColumnLayout.d.ts +0 -0
- /package/{components → dist/components}/Docs/index.d.ts +0 -0
- /package/{components → dist/components}/Docs/story-helper.d.ts +0 -0
- /package/{components → dist/components}/Docs/story-renderer-helper.d.ts +0 -0
- /package/{components → dist/components}/Layout/MobileTopNav.d.ts +0 -0
- /package/{components → dist/components}/Layout/ResponsiveSidebarLayout.d.ts +0 -0
- /package/{components → dist/components}/Layout/SidebarLayout.d.ts +0 -0
- /package/{components → dist/components}/LinkHeading.d.ts +0 -0
- /package/{components → dist/components}/LoadMore.d.ts +0 -0
- /package/{components → dist/components}/Loading/Loading.d.ts +0 -0
- /package/{components → dist/components}/Logo.d.ts +0 -0
- /package/{components → dist/components}/MarkdownViewer/CustomComponents/CodeComponent.d.ts +0 -0
- /package/{components → dist/components}/MarkdownViewer/CustomComponents/CodeComponent.spec.d.ts +0 -0
- /package/{components → dist/components}/MarkdownViewer/CustomComponents/Provider.d.ts +0 -0
- /package/{components → dist/components}/MarkdownViewer/CustomComponents/ReactRouterLink.d.ts +0 -0
- /package/{components → dist/components}/MarkdownViewer/CustomComponents/ResolvedImage.d.ts +0 -0
- /package/{components → dist/components}/MarkdownViewer/CustomComponents/ScrollToHashElement.d.ts +0 -0
- /package/{components → dist/components}/MarkdownViewer/MarkdownViewer.spec.d.ts +0 -0
- /package/{components → dist/components}/MarkdownViewer/index.d.ts +0 -0
- /package/{components → dist/components}/NonIdealState.d.ts +0 -0
- /package/{components → dist/components}/PoweredByLink.d.ts +0 -0
- /package/{components → dist/components}/RequestSamples/RequestSamples.d.ts +0 -0
- /package/{components → dist/components}/RequestSamples/RequestSamples.stories.d.ts +0 -0
- /package/{components → dist/components}/RequestSamples/convertRequestToSample.d.ts +0 -0
- /package/{components → dist/components}/RequestSamples/extractCodeSamples.d.ts +0 -0
- /package/{components → dist/components}/RequestSamples/index.d.ts +0 -0
- /package/{components → dist/components}/RequestSamples/requestSampleConfigs.d.ts +0 -0
- /package/{components → dist/components}/ResponseExamples/ResponseExamples.d.ts +0 -0
- /package/{components → dist/components}/ResponseExamples/ResponseExamples.spec.d.ts +0 -0
- /package/{components → dist/components}/ResponseExamples/ResponseExamples.stories.d.ts +0 -0
- /package/{components → dist/components}/TableOfContents/TableOfContents.d.ts +0 -0
- /package/{components → dist/components}/TableOfContents/TableOfContents.spec.d.ts +0 -0
- /package/{components → dist/components}/TableOfContents/TableOfContents.stories.d.ts +0 -0
- /package/{components → dist/components}/TableOfContents/constants.d.ts +0 -0
- /package/{components → dist/components}/TableOfContents/index.d.ts +0 -0
- /package/{components → dist/components}/TableOfContents/types.d.ts +0 -0
- /package/{components → dist/components}/TableOfContents/utils.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Auth/APIKeyAuth.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Auth/Auth.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Auth/AuthTokenInput.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Auth/BasicAuth.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Auth/BearerAuth.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Auth/DigestAuth.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Auth/OAuth2Auth.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Auth/authentication-utils.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Body/BinaryBody.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Body/FormDataBody.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Body/RequestBody.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Body/request-body-utils.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Body/useTextRequestBodyState.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Mocking/MockingButton.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Mocking/mocking-utils.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Mocking/useMockingOptions.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Parameters/FileUploadParameterEditors.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Parameters/OperationParameters.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Parameters/ParameterEditor.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Parameters/parameter-utils.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Parameters/parameter-utils.spec.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Parameters/useOperationParameters.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Response/ReponseCodeViewer.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Response/Response.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Response/Response.spec.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Response/hooks/useLineCount.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Servers/ServerVariables.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Servers/ServersDropdown.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Servers/VariableEditor.d.ts +0 -0
- /package/{components → dist/components}/TryIt/Servers/useServerVariables.d.ts +0 -0
- /package/{components → dist/components}/TryIt/TryIt.d.ts +0 -0
- /package/{components → dist/components}/TryIt/TryIt.spec.d.ts +0 -0
- /package/{components → dist/components}/TryIt/TryIt.stories.d.ts +0 -0
- /package/{components → dist/components}/TryIt/TryItWithRequestSamples.d.ts +0 -0
- /package/{components → dist/components}/TryIt/TryItWithRequestSamples.spec.d.ts +0 -0
- /package/{components → dist/components}/TryIt/TryItWithRequestSamples.stories.d.ts +0 -0
- /package/{components → dist/components}/TryIt/build-request.d.ts +0 -0
- /package/{components → dist/components}/TryIt/build-request.spec.d.ts +0 -0
- /package/{components → dist/components}/TryIt/chosenServer.d.ts +0 -0
- /package/{components → dist/components}/TryIt/index.d.ts +0 -0
- /package/{constants.d.ts → dist/constants.d.ts} +0 -0
- /package/{containers → dist/containers}/MockingProvider.d.ts +0 -0
- /package/{context → dist/context}/InlineRefResolver.d.ts +0 -0
- /package/{context → dist/context}/InlineRefResolver.spec.d.ts +0 -0
- /package/{context → dist/context}/Options.d.ts +0 -0
- /package/{context → dist/context}/Persistence.d.ts +0 -0
- /package/{context → dist/context}/RouterType.d.ts +0 -0
- /package/{core.css → dist/core.css} +0 -0
- /package/{hoc → dist/hoc}/utils.d.ts +0 -0
- /package/{hoc → dist/hoc}/withMosaicProvider.d.ts +0 -0
- /package/{hoc → dist/hoc}/withMosaicProvider.spec.d.ts +0 -0
- /package/{hoc → dist/hoc}/withQueryClientProvider.d.ts +0 -0
- /package/{hoc → dist/hoc}/withQueryClientProvider.spec.d.ts +0 -0
- /package/{hoc → dist/hoc}/withRouter.d.ts +0 -0
- /package/{hooks → dist/hooks}/useBundleRefsIntoDocument.d.ts +0 -0
- /package/{hooks → dist/hooks}/useFirstRender.d.ts +0 -0
- /package/{hooks → dist/hooks}/useIsCompact.d.ts +0 -0
- /package/{hooks → dist/hooks}/useParsedData.d.ts +0 -0
- /package/{hooks → dist/hooks}/useParsedValue.d.ts +0 -0
- /package/{hooks → dist/hooks}/useResponsiveLayout.d.ts +0 -0
- /package/{hooks → dist/hooks}/useRouter.d.ts +0 -0
- /package/{hooks → dist/hooks}/useUniqueId.d.ts +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{styles.min.css → dist/styles.min.css} +0 -0
- /package/{types.d.ts → dist/types.d.ts} +0 -0
- /package/{utils → dist/utils}/exampleGeneration/exampleGeneration.d.ts +0 -0
- /package/{utils → dist/utils}/exampleGeneration/exampleGeneration.spec.d.ts +0 -0
- /package/{utils → dist/utils}/fileToBase64.d.ts +0 -0
- /package/{utils → dist/utils}/guards.d.ts +0 -0
- /package/{utils → dist/utils}/headers.d.ts +0 -0
- /package/{utils → dist/utils}/http-spec/IServer.d.ts +0 -0
- /package/{utils → dist/utils}/http-spec/examples.d.ts +0 -0
- /package/{utils → dist/utils}/http.d.ts +0 -0
- /package/{utils → dist/utils}/jotai/persistAtom.d.ts +0 -0
- /package/{utils → dist/utils}/node.d.ts +0 -0
- /package/{utils → dist/utils}/oas/security.d.ts +0 -0
- /package/{utils → dist/utils}/ref-resolving/ReferenceResolver.d.ts +0 -0
- /package/{utils → dist/utils}/ref-resolving/resolvedObject.d.ts +0 -0
- /package/{utils → dist/utils}/ref-resolving/resolvedObject.test.d.ts +0 -0
- /package/{utils → dist/utils}/securitySchemes.d.ts +0 -0
- /package/{utils → dist/utils}/string.d.ts +0 -0
- /package/{utils → dist/utils}/tests/chooseOption.d.ts +0 -0
- /package/{web-components → dist/web-components}/createElementClass.d.ts +0 -0
|
@@ -0,0 +1,651 @@
|
|
|
1
|
+
import { Box, Flex, VStack } from '@stoplight/mosaic';
|
|
2
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
interface LazySchemaTreePreviewerProps {
|
|
5
|
+
schema: any;
|
|
6
|
+
root?: any;
|
|
7
|
+
title?: string;
|
|
8
|
+
level?: number;
|
|
9
|
+
path?: string;
|
|
10
|
+
maskState?: Record<string, { checked: boolean; required: 0 | 1 | 2 }>;
|
|
11
|
+
setMaskState?: React.Dispatch<React.SetStateAction<Record<string, { checked: boolean; required: 0 | 1 | 2 }>>>;
|
|
12
|
+
hideData?: Array<{ path: string; required?: boolean }>;
|
|
13
|
+
complexData?: ComplexData;
|
|
14
|
+
parentRequired?: string[];
|
|
15
|
+
propertyKey?: string;
|
|
16
|
+
_subType?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface SchemaWithMinItems {
|
|
20
|
+
minItems?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface SchemaWithEnum {
|
|
24
|
+
enum?: any[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type ComplexData = Array<{ location: string; isComplex?: boolean; paths: Array<{ path: string; required?: boolean }> }>;
|
|
28
|
+
|
|
29
|
+
type Schema = SchemaWithMinItems | SchemaWithEnum | object;
|
|
30
|
+
|
|
31
|
+
const TYPES = ['string', 'integer', 'boolean', 'any', 'number'];
|
|
32
|
+
|
|
33
|
+
function resolvePointer(obj: any, pointer: string) {
|
|
34
|
+
const parts = pointer.replace(/^#\//, '').split('/');
|
|
35
|
+
return parts.reduce((acc, key) => acc && acc[key], obj);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function detectCircularPath(path: string): boolean {
|
|
39
|
+
const ignored = ['properties', 'items'];
|
|
40
|
+
const parts = path.split('/').filter(part => !ignored.includes(part));
|
|
41
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
42
|
+
const current = parts[i];
|
|
43
|
+
const rest = parts.slice(i + 1);
|
|
44
|
+
if (rest.includes(current)) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
function dereference(node: any, root: any, visited: WeakSet<object> = new WeakSet(), depth = 0, maxDepth = 10): any {
|
|
51
|
+
if (!node || typeof node !== 'object') return node;
|
|
52
|
+
if (depth > maxDepth) return node;
|
|
53
|
+
|
|
54
|
+
if (node.$ref || node['x-iata-$ref']) {
|
|
55
|
+
let refPath = node.$ref || node['x-iata-$ref'];
|
|
56
|
+
if (refPath.includes('#/%24defs')) {
|
|
57
|
+
refPath = refPath.replace('#/%24defs', '$defs');
|
|
58
|
+
} else {
|
|
59
|
+
refPath = refPath.replace('__bundled__', 'definitions');
|
|
60
|
+
}
|
|
61
|
+
if (visited.has(node))
|
|
62
|
+
return { circular: true, $ref: refPath, title: node.title, type: 'any', description: node.description };
|
|
63
|
+
|
|
64
|
+
visited.add(node);
|
|
65
|
+
const target = resolvePointer(root, refPath);
|
|
66
|
+
if (!target) return node;
|
|
67
|
+
const result = { ...target };
|
|
68
|
+
if ('description' in node) result.description = node.description;
|
|
69
|
+
if ('title' in node) result.title = node.title;
|
|
70
|
+
return dereference(result, root, visited, depth + 1, maxDepth);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (Array.isArray(node)) {
|
|
74
|
+
return node.map(item => dereference(item, root, visited, depth + 1, maxDepth));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const result: Record<string, any> = {};
|
|
78
|
+
for (const key in node) {
|
|
79
|
+
result[key] = dereference(node[key], root, visited, depth + 1, maxDepth);
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const trimSlashes = (str: string) => {
|
|
85
|
+
return str.replace(/^\/|\/$/g, '');
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
function isPropertiesAllHidden(path: string, hideData: Array<{ path: string; required?: boolean }>) {
|
|
89
|
+
const current = trimSlashes(path);
|
|
90
|
+
const parts = current.split('/');
|
|
91
|
+
for (let i = parts.length; i >= 2; i--) {
|
|
92
|
+
if (parts[i - 1] === 'properties') {
|
|
93
|
+
const ancestorPropPath = parts.slice(0, i).join('/');
|
|
94
|
+
const block = hideData.find(
|
|
95
|
+
h => trimSlashes(h.path) === ancestorPropPath && ancestorPropPath.endsWith('/properties'),
|
|
96
|
+
);
|
|
97
|
+
if (block && block.required === undefined) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function isRequiredOverride(path: string, hideData: Array<{ path: string; required?: boolean }>) {
|
|
106
|
+
const entry = hideData.find(h => trimSlashes(h.path) === trimSlashes(path));
|
|
107
|
+
return entry && typeof entry.required === 'boolean' ? entry.required : undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// New utility for array/items-based hiding
|
|
111
|
+
function isPathHidden(path: string, hideData: Array<{ path: string; required?: boolean }>, complexData: ComplexData) {
|
|
112
|
+
const isComplex = checkIfIsComplex(path, complexData);
|
|
113
|
+
|
|
114
|
+
if (isComplex === null) {
|
|
115
|
+
return false;
|
|
116
|
+
} else if (isComplex) {
|
|
117
|
+
const normalizedPath = trimSlashes(path);
|
|
118
|
+
|
|
119
|
+
// Direct match (root-level or property-level)
|
|
120
|
+
const direct = hideData.find(h => trimSlashes(h.path) === normalizedPath);
|
|
121
|
+
if (direct && direct.required === undefined) return true;
|
|
122
|
+
|
|
123
|
+
// Check for ancestor "properties" disables (properties/carr/properties, etc)
|
|
124
|
+
if (isPropertiesAllHidden(path, hideData)) return true;
|
|
125
|
+
|
|
126
|
+
// Check for array/items disables: e.g. properties/aircraftGroup/items/aircraft/items/aircraftGroup
|
|
127
|
+
// Go up the path looking for a hideData.path which is a prefix of this path and ends with '/items/[field]'
|
|
128
|
+
for (const h of hideData) {
|
|
129
|
+
const hPath = trimSlashes(h.path);
|
|
130
|
+
if (h.required !== undefined) continue;
|
|
131
|
+
// Must be prefix
|
|
132
|
+
if (
|
|
133
|
+
normalizedPath.length > hPath.length &&
|
|
134
|
+
normalizedPath.startsWith(hPath) &&
|
|
135
|
+
// hPath is items/field (array hiding)
|
|
136
|
+
(hPath.endsWith('/items') || (hPath.match(/\/items\/[^\/]+$/) && normalizedPath.startsWith(hPath + '/')))
|
|
137
|
+
) {
|
|
138
|
+
// Hide all descendants under this path
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
} else {
|
|
144
|
+
return !hideData.some(h => h.path === path || h.path.startsWith(path + '/'));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const checkIfIsComplex = (path: string, complexData: ComplexData) => {
|
|
149
|
+
let isComplex = null;
|
|
150
|
+
for (const complex of complexData) {
|
|
151
|
+
if (path.startsWith(complex.location)) {
|
|
152
|
+
isComplex = complex?.isComplex;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return isComplex;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const LazySchemaTreePreviewer: React.FC<LazySchemaTreePreviewerProps> = ({
|
|
160
|
+
schema,
|
|
161
|
+
root = schema,
|
|
162
|
+
title,
|
|
163
|
+
level = 1,
|
|
164
|
+
path = '',
|
|
165
|
+
hideData = [],
|
|
166
|
+
complexData = [],
|
|
167
|
+
parentRequired,
|
|
168
|
+
propertyKey,
|
|
169
|
+
_subType,
|
|
170
|
+
}) => {
|
|
171
|
+
const [expanded, setExpanded] = useState(false);
|
|
172
|
+
const [selectedSchemaIndex, setSelectedSchemaIndex] = useState(0);
|
|
173
|
+
const [showSchemaDropdown, setShowSchemaDropdown] = useState(false);
|
|
174
|
+
const [isHoveringSelector, setIsHoveringSelector] = useState(false);
|
|
175
|
+
const isRoot = level === 1 && (title === undefined || path === '');
|
|
176
|
+
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
setSelectedSchemaIndex(0);
|
|
179
|
+
}, [schema?.anyOf, schema?.oneOf]);
|
|
180
|
+
const thisNodeRequiredOverride = isRequiredOverride(path, hideData);
|
|
181
|
+
|
|
182
|
+
const shouldHideAllChildren =
|
|
183
|
+
(isRoot && hideData.some(h => trimSlashes(h.path) === 'properties' && h.required === undefined)) ||
|
|
184
|
+
(!isRoot && isPropertiesAllHidden(path, hideData));
|
|
185
|
+
|
|
186
|
+
// Check if the node has expandable children
|
|
187
|
+
const hasExpandableChildren = useMemo(() => {
|
|
188
|
+
if (shouldHideAllChildren) return false;
|
|
189
|
+
if (schema?.type === 'object' && (schema?.properties || schema?.allOf || schema?.anyOf || schema?.oneOf)) {
|
|
190
|
+
let props = schema?.properties;
|
|
191
|
+
if (schema?.allOf) {
|
|
192
|
+
schema?.allOf.forEach((item: any) => {
|
|
193
|
+
props = { ...props, ...item.properties };
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
if (schema?.anyOf && schema?.anyOf.length > 0) {
|
|
197
|
+
const selectedSchema = schema?.anyOf[selectedSchemaIndex] || schema?.anyOf[0];
|
|
198
|
+
props = { ...props, ...selectedSchema.properties };
|
|
199
|
+
}
|
|
200
|
+
if (schema?.oneOf && schema?.oneOf.length > 0) {
|
|
201
|
+
const selectedSchema = schema?.oneOf[selectedSchemaIndex] || schema?.oneOf[0];
|
|
202
|
+
props = { ...props, ...selectedSchema.properties };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (props && Object.keys(props).length > 0) {
|
|
206
|
+
for (const [key] of Object.entries(props)) {
|
|
207
|
+
const childPath = `${path}/properties/${key}`;
|
|
208
|
+
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
209
|
+
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
210
|
+
if (!shouldHideChild) return true;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (
|
|
215
|
+
schema?.type === 'array' &&
|
|
216
|
+
schema?.items &&
|
|
217
|
+
Object.keys(schema?.items).length > 0 &&
|
|
218
|
+
!schema?.items?.circular
|
|
219
|
+
) {
|
|
220
|
+
const resolvedItems = dereference(schema?.items, root);
|
|
221
|
+
const itemsPath = `${path}/items`;
|
|
222
|
+
|
|
223
|
+
if (resolvedItems && resolvedItems.type === 'object' && resolvedItems.properties) {
|
|
224
|
+
for (const [key] of Object.entries(resolvedItems.properties)) {
|
|
225
|
+
const childPath = `${itemsPath}/properties/${key}`;
|
|
226
|
+
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
227
|
+
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
228
|
+
if (!shouldHideChild) return true;
|
|
229
|
+
}
|
|
230
|
+
} else if (
|
|
231
|
+
resolvedItems &&
|
|
232
|
+
resolvedItems.type === 'array' &&
|
|
233
|
+
resolvedItems.items &&
|
|
234
|
+
resolvedItems.items.length > 0
|
|
235
|
+
) {
|
|
236
|
+
const childPath = `${path}/items`;
|
|
237
|
+
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
238
|
+
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
239
|
+
if (!shouldHideChild) return true;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return false;
|
|
244
|
+
}, [schema, path, hideData, complexData, shouldHideAllChildren, root, selectedSchemaIndex]);
|
|
245
|
+
|
|
246
|
+
const shouldHideNode = useMemo(() => {
|
|
247
|
+
if (isRoot) return false;
|
|
248
|
+
if (isPathHidden(path, hideData, complexData) && thisNodeRequiredOverride === undefined) return true;
|
|
249
|
+
return false;
|
|
250
|
+
}, [path, hideData, isRoot, thisNodeRequiredOverride, complexData]);
|
|
251
|
+
|
|
252
|
+
if (!schema || shouldHideNode) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const displayTitle = level === 1 && (title === undefined || path === '') ? '' : title ?? schema?.title ?? 'Node';
|
|
257
|
+
|
|
258
|
+
const handleToggle = () => {
|
|
259
|
+
const circular = detectCircularPath(path);
|
|
260
|
+
if (!circular) {
|
|
261
|
+
setExpanded(prev => !prev);
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const renderChildren = () => {
|
|
266
|
+
if (shouldHideAllChildren) return null;
|
|
267
|
+
if (!expanded && !isRoot) return null;
|
|
268
|
+
|
|
269
|
+
const children: JSX.Element[] = [];
|
|
270
|
+
|
|
271
|
+
if (schema?.type === 'object' && (schema?.properties || schema?.allOf || schema?.anyOf || schema?.oneOf)) {
|
|
272
|
+
let props = schema?.properties;
|
|
273
|
+
|
|
274
|
+
if (schema?.allOf) {
|
|
275
|
+
schema?.allOf.forEach((item: any) => {
|
|
276
|
+
props = { ...props, ...item.properties };
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
if (schema?.anyOf && schema?.anyOf.length > 0) {
|
|
280
|
+
const selectedSchema = schema?.anyOf[selectedSchemaIndex] || schema?.anyOf[0];
|
|
281
|
+
props = { ...props, ...selectedSchema.properties };
|
|
282
|
+
}
|
|
283
|
+
if (schema?.oneOf && schema?.oneOf.length > 0) {
|
|
284
|
+
const selectedSchema = schema?.oneOf[selectedSchemaIndex] || schema?.oneOf[0];
|
|
285
|
+
props = { ...props, ...selectedSchema.properties };
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
for (const [key, child] of Object.entries(props || {})) {
|
|
289
|
+
const childPath = `${path}/properties/${key}`;
|
|
290
|
+
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
291
|
+
|
|
292
|
+
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
293
|
+
const resolved = dereference(child, root);
|
|
294
|
+
|
|
295
|
+
if (!shouldHideChild) {
|
|
296
|
+
children.push(
|
|
297
|
+
<li key={key}>
|
|
298
|
+
<LazySchemaTreePreviewer
|
|
299
|
+
schema={resolved}
|
|
300
|
+
root={root}
|
|
301
|
+
title={key}
|
|
302
|
+
level={level + 1}
|
|
303
|
+
path={childPath}
|
|
304
|
+
hideData={hideData}
|
|
305
|
+
complexData={complexData}
|
|
306
|
+
parentRequired={schema?.required}
|
|
307
|
+
propertyKey={key}
|
|
308
|
+
_subType={resolved?.items?.type}
|
|
309
|
+
/>
|
|
310
|
+
</li>,
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
} else if (
|
|
315
|
+
schema?.type === 'array' &&
|
|
316
|
+
schema?.items &&
|
|
317
|
+
Object.keys(schema?.items).length > 0 &&
|
|
318
|
+
!schema?.items?.circular
|
|
319
|
+
) {
|
|
320
|
+
const resolvedItems = dereference(schema?.items, root);
|
|
321
|
+
const itemsPath = `${path}/items`;
|
|
322
|
+
|
|
323
|
+
if (resolvedItems && resolvedItems.type === 'object' && resolvedItems.properties) {
|
|
324
|
+
for (const [key, child] of Object.entries(resolvedItems.properties)) {
|
|
325
|
+
const childPath = `${itemsPath}/properties/${key}`;
|
|
326
|
+
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
327
|
+
|
|
328
|
+
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
329
|
+
const resolved = dereference(child, root);
|
|
330
|
+
|
|
331
|
+
if (!shouldHideChild) {
|
|
332
|
+
children.push(
|
|
333
|
+
<li key={key}>
|
|
334
|
+
<LazySchemaTreePreviewer
|
|
335
|
+
schema={resolved}
|
|
336
|
+
root={root}
|
|
337
|
+
title={key}
|
|
338
|
+
level={level + 2}
|
|
339
|
+
path={childPath}
|
|
340
|
+
hideData={hideData}
|
|
341
|
+
complexData={complexData}
|
|
342
|
+
parentRequired={resolvedItems.required}
|
|
343
|
+
propertyKey={key}
|
|
344
|
+
_subType={resolvedItems?.items?.type}
|
|
345
|
+
/>
|
|
346
|
+
</li>,
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
} else if (resolvedItems && resolvedItems.type === 'array' && resolvedItems.items.length > 0) {
|
|
351
|
+
const childPath = `${path}/items`;
|
|
352
|
+
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
353
|
+
|
|
354
|
+
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
355
|
+
|
|
356
|
+
if (!shouldHideChild) {
|
|
357
|
+
children.push(
|
|
358
|
+
<li key="items">
|
|
359
|
+
<LazySchemaTreePreviewer
|
|
360
|
+
schema={resolvedItems}
|
|
361
|
+
root={root}
|
|
362
|
+
title="items"
|
|
363
|
+
level={level + 1}
|
|
364
|
+
path={childPath}
|
|
365
|
+
hideData={hideData}
|
|
366
|
+
complexData={complexData}
|
|
367
|
+
parentRequired={schema?.required}
|
|
368
|
+
propertyKey="items"
|
|
369
|
+
_subType={resolvedItems?.items?.type}
|
|
370
|
+
/>
|
|
371
|
+
</li>,
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return children.length > 0 ? <ul className="ml-6 border-l border-gray-200 pl-2">{children}</ul> : null;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
const combinedSchemaSelector = () => {
|
|
380
|
+
return (
|
|
381
|
+
<>
|
|
382
|
+
<Box
|
|
383
|
+
pos="fixed"
|
|
384
|
+
top={0}
|
|
385
|
+
left={0}
|
|
386
|
+
right={0}
|
|
387
|
+
bottom={0}
|
|
388
|
+
bg="transparent"
|
|
389
|
+
style={{ zIndex: 999 }}
|
|
390
|
+
onClick={() => setShowSchemaDropdown(false)}
|
|
391
|
+
/>
|
|
392
|
+
<Box
|
|
393
|
+
pos="absolute"
|
|
394
|
+
bg="canvas"
|
|
395
|
+
rounded
|
|
396
|
+
boxShadow="md"
|
|
397
|
+
style={{
|
|
398
|
+
zIndex: 1000,
|
|
399
|
+
top: '100%',
|
|
400
|
+
left: 0,
|
|
401
|
+
minWidth: '150px',
|
|
402
|
+
maxWidth: '200px',
|
|
403
|
+
marginTop: '2px',
|
|
404
|
+
border: '1px solid rgba(0, 0, 0, 0.1)',
|
|
405
|
+
}}
|
|
406
|
+
fontSize="sm"
|
|
407
|
+
onClick={(e: React.MouseEvent<HTMLDivElement>) => e.stopPropagation()}
|
|
408
|
+
>
|
|
409
|
+
{(schema?.anyOf || schema?.oneOf)?.map((schemaOption: any, index: number) => (
|
|
410
|
+
<Box
|
|
411
|
+
key={index}
|
|
412
|
+
px={3}
|
|
413
|
+
py={2}
|
|
414
|
+
cursor="pointer"
|
|
415
|
+
bg={selectedSchemaIndex === index ? 'primary-tint' : 'canvas'}
|
|
416
|
+
fontSize="xs"
|
|
417
|
+
display="flex"
|
|
418
|
+
alignItems="center"
|
|
419
|
+
style={{
|
|
420
|
+
borderBottom:
|
|
421
|
+
index < (schema?.anyOf || schema?.oneOf).length - 1 ? '1px solid rgba(0, 0, 0, 0.1)' : 'none',
|
|
422
|
+
gap: '8px',
|
|
423
|
+
}}
|
|
424
|
+
onMouseEnter={(e: React.MouseEvent<HTMLDivElement>) => {
|
|
425
|
+
if (selectedSchemaIndex !== index) {
|
|
426
|
+
e.currentTarget.style.backgroundColor = 'var(--sl-color-canvas-tint)';
|
|
427
|
+
}
|
|
428
|
+
}}
|
|
429
|
+
onMouseLeave={(e: React.MouseEvent<HTMLDivElement>) => {
|
|
430
|
+
if (selectedSchemaIndex !== index) {
|
|
431
|
+
e.currentTarget.style.backgroundColor = 'var(--sl-color-canvas)';
|
|
432
|
+
}
|
|
433
|
+
}}
|
|
434
|
+
onClick={() => {
|
|
435
|
+
setSelectedSchemaIndex(index);
|
|
436
|
+
setShowSchemaDropdown(false);
|
|
437
|
+
}}
|
|
438
|
+
>
|
|
439
|
+
<Box flex={1} color="body">
|
|
440
|
+
{schemaOption.type || 'object'}
|
|
441
|
+
</Box>
|
|
442
|
+
{selectedSchemaIndex === index && (
|
|
443
|
+
<Box color="primary" fontSize="xs">
|
|
444
|
+
✓
|
|
445
|
+
</Box>
|
|
446
|
+
)}
|
|
447
|
+
</Box>
|
|
448
|
+
))}
|
|
449
|
+
</Box>
|
|
450
|
+
</>
|
|
451
|
+
);
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
const renderMinEnums = (schema: Schema) => {
|
|
455
|
+
if (!schema || typeof schema !== 'object') return null;
|
|
456
|
+
const boxStyle: any = {
|
|
457
|
+
background: 'rgba(245, 247, 250, 0.5)',
|
|
458
|
+
border: '1px solid #a0aec0',
|
|
459
|
+
borderRadius: '4px',
|
|
460
|
+
padding: '0px 2px',
|
|
461
|
+
display: 'inline-block',
|
|
462
|
+
overflowWrap: 'break-word',
|
|
463
|
+
textAlign: 'left',
|
|
464
|
+
maxWidth: 'fit-content',
|
|
465
|
+
maxHeight: 'fit-content',
|
|
466
|
+
};
|
|
467
|
+
if ('minItems' in schema) {
|
|
468
|
+
const schemaWithMinItems = schema as SchemaWithMinItems;
|
|
469
|
+
if (typeof schemaWithMinItems.minItems === 'number') {
|
|
470
|
+
return (
|
|
471
|
+
<Box className="sl-text-muted" fontFamily="ui" fontWeight="normal" mr={2} style={boxStyle}>
|
|
472
|
+
{`>=${schemaWithMinItems.minItems} items`}
|
|
473
|
+
</Box>
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
if ('enum' in schema && Array.isArray((schema as SchemaWithEnum).enum)) {
|
|
479
|
+
return (
|
|
480
|
+
<div>
|
|
481
|
+
Allowed values:{' '}
|
|
482
|
+
{(schema as SchemaWithEnum).enum!.map((val, idx) => (
|
|
483
|
+
<Box key={idx} className="sl-text-muted" fontFamily="ui" fontWeight="normal" mr={2} style={boxStyle}>
|
|
484
|
+
{val}
|
|
485
|
+
</Box>
|
|
486
|
+
))}
|
|
487
|
+
</div>
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
return null;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
const isRequired = parentRequired && propertyKey && parentRequired.includes(propertyKey);
|
|
494
|
+
let showRequiredLabel = false;
|
|
495
|
+
const hideDataEntry = hideData.find(hideEntry => trimSlashes(hideEntry.path) === trimSlashes(path));
|
|
496
|
+
if (hideDataEntry?.required === true || (hideDataEntry?.required === undefined && isRequired)) {
|
|
497
|
+
showRequiredLabel = true;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
if (schema?.$ref) {
|
|
501
|
+
// eslint-disable-next-line no-param-reassign
|
|
502
|
+
schema = dereference(schema, root);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return (
|
|
506
|
+
<div className="mb-1">
|
|
507
|
+
<Flex maxW="full" pl={3} py={2} data-test="schema-row" pos="relative">
|
|
508
|
+
<VStack spacing={1} maxW="full" className="w-full">
|
|
509
|
+
<Flex onClick={!isRoot ? handleToggle : undefined} className={`w-full ${isRoot ? '' : 'cursor-pointer'}`}>
|
|
510
|
+
{!isRoot ? (
|
|
511
|
+
<Box mr={2} className="sl-font-mono sl-font-semibold sl-mr-2">
|
|
512
|
+
{hasExpandableChildren &&
|
|
513
|
+
!TYPES.includes(schema?.type) &&
|
|
514
|
+
!detectCircularPath(path) &&
|
|
515
|
+
!schema?.items?.circular &&
|
|
516
|
+
!schema?.circular ? (
|
|
517
|
+
<i
|
|
518
|
+
role="img"
|
|
519
|
+
aria-hidden="true"
|
|
520
|
+
className={`sl-icon fal ${expanded ? 'fa-chevron-down' : 'fa-chevron-right'} fa-fw fa-sm`}
|
|
521
|
+
></i>
|
|
522
|
+
) : (
|
|
523
|
+
<span className="sl-icon fal fa-fw fa-sm" aria-hidden="true"></span>
|
|
524
|
+
)}
|
|
525
|
+
{' ' + displayTitle}
|
|
526
|
+
</Box>
|
|
527
|
+
) : null}
|
|
528
|
+
{!isRoot ? (
|
|
529
|
+
<Box mr={2} pos="relative">
|
|
530
|
+
<Box
|
|
531
|
+
display="inline-flex"
|
|
532
|
+
alignItems="center"
|
|
533
|
+
onMouseEnter={() => {
|
|
534
|
+
if (schema?.anyOf || schema?.oneOf) {
|
|
535
|
+
setIsHoveringSelector(true);
|
|
536
|
+
}
|
|
537
|
+
}}
|
|
538
|
+
onMouseLeave={() => {
|
|
539
|
+
if (!showSchemaDropdown) {
|
|
540
|
+
setIsHoveringSelector(false);
|
|
541
|
+
}
|
|
542
|
+
}}
|
|
543
|
+
onClick={(e: React.MouseEvent<HTMLDivElement>) => {
|
|
544
|
+
if (schema?.anyOf || schema?.oneOf) {
|
|
545
|
+
e.stopPropagation();
|
|
546
|
+
setShowSchemaDropdown(prev => !prev);
|
|
547
|
+
}
|
|
548
|
+
}}
|
|
549
|
+
style={{
|
|
550
|
+
cursor: schema?.anyOf || schema?.oneOf ? 'pointer' : 'default',
|
|
551
|
+
}}
|
|
552
|
+
>
|
|
553
|
+
<span className="sl-truncate sl-text-muted">
|
|
554
|
+
{(() => {
|
|
555
|
+
let typeDisplay =
|
|
556
|
+
schema?.type === 'object' && schema?.title ? schema?.title : schema?.type || root?.title;
|
|
557
|
+
|
|
558
|
+
if (schema?.anyOf && schema?.anyOf.length > 0) {
|
|
559
|
+
return `any of ${typeDisplay}`;
|
|
560
|
+
} else if (schema?.oneOf && schema?.oneOf.length > 0) {
|
|
561
|
+
return `one of ${typeDisplay}`;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
return typeDisplay;
|
|
565
|
+
})()}
|
|
566
|
+
{schema?.items && schema?.items?.title !== undefined ? ` [${schema?.items?.title}] ` : null}
|
|
567
|
+
</span>
|
|
568
|
+
{(schema?.anyOf || schema?.oneOf) && (
|
|
569
|
+
<Box
|
|
570
|
+
display="inline-flex"
|
|
571
|
+
alignItems="center"
|
|
572
|
+
ml={1}
|
|
573
|
+
style={{
|
|
574
|
+
opacity: isHoveringSelector ? 1 : 0.6,
|
|
575
|
+
transition: 'opacity 0.2s',
|
|
576
|
+
}}
|
|
577
|
+
>
|
|
578
|
+
<i
|
|
579
|
+
className="sl-icon fas fa-chevron-down"
|
|
580
|
+
style={{
|
|
581
|
+
fontSize: '10px',
|
|
582
|
+
opacity: 0.6,
|
|
583
|
+
}}
|
|
584
|
+
/>
|
|
585
|
+
</Box>
|
|
586
|
+
)}
|
|
587
|
+
</Box>
|
|
588
|
+
<span className="text-gray-500">{schema?.format !== undefined ? `<${schema?.format}>` : null}</span>
|
|
589
|
+
{(schema?.anyOf || schema?.oneOf) && showSchemaDropdown && combinedSchemaSelector()}
|
|
590
|
+
</Box>
|
|
591
|
+
) : null}
|
|
592
|
+
</Flex>
|
|
593
|
+
<Flex pl={1} w="full" align="start" direction="col" style={{ overflow: 'visible', paddingLeft: '20px' }}>
|
|
594
|
+
{schema?.description && (
|
|
595
|
+
<Box fontFamily="ui" fontWeight="light">
|
|
596
|
+
<span className="sl-prose sl-markdown-viewer" style={{ fontSize: '12px' }}>
|
|
597
|
+
{schema?.description}
|
|
598
|
+
</span>
|
|
599
|
+
</Box>
|
|
600
|
+
)}
|
|
601
|
+
{!isRoot && schema?.examples !== undefined && (
|
|
602
|
+
<Flex align="center" mb={1} style={{ flexWrap: 'wrap' }}>
|
|
603
|
+
<span className="text-gray-500" style={{ marginRight: 8, flexShrink: 0 }}>
|
|
604
|
+
Example
|
|
605
|
+
</span>
|
|
606
|
+
<Box
|
|
607
|
+
className="sl-text-muted"
|
|
608
|
+
fontFamily="ui"
|
|
609
|
+
fontWeight="normal"
|
|
610
|
+
mr={2}
|
|
611
|
+
style={{
|
|
612
|
+
background: 'rgba(245, 247, 250, 0.5)',
|
|
613
|
+
border: '1px solid #a0aec0',
|
|
614
|
+
borderRadius: '4px',
|
|
615
|
+
padding: '4px 8px',
|
|
616
|
+
display: 'inline-block',
|
|
617
|
+
overflowWrap: 'break-word',
|
|
618
|
+
textAlign: 'left',
|
|
619
|
+
maxWidth: '530px',
|
|
620
|
+
}}
|
|
621
|
+
>
|
|
622
|
+
{JSON.stringify(schema?.examples)}
|
|
623
|
+
</Box>
|
|
624
|
+
</Flex>
|
|
625
|
+
)}
|
|
626
|
+
</Flex>
|
|
627
|
+
<Flex pl={1} w="full" align="start" direction="col" style={{ overflow: 'visible', paddingLeft: '20px' }}>
|
|
628
|
+
{schema &&
|
|
629
|
+
typeof schema === 'object' &&
|
|
630
|
+
('minItems' in schema || 'enum' in schema) &&
|
|
631
|
+
renderMinEnums(schema)}
|
|
632
|
+
</Flex>
|
|
633
|
+
</VStack>
|
|
634
|
+
{!isRoot && (
|
|
635
|
+
<label className="inline-flex items-top ml-2">
|
|
636
|
+
<Box mr={2} fontFamily="ui" fontWeight="normal">
|
|
637
|
+
{showRequiredLabel && (
|
|
638
|
+
<div className="sl-ml-2 sl-text-warning">
|
|
639
|
+
<span style={{ marginLeft: '10px' }}>required</span>
|
|
640
|
+
</div>
|
|
641
|
+
)}
|
|
642
|
+
</Box>
|
|
643
|
+
</label>
|
|
644
|
+
)}
|
|
645
|
+
</Flex>
|
|
646
|
+
{renderChildren()}
|
|
647
|
+
</div>
|
|
648
|
+
);
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
export default LazySchemaTreePreviewer;
|