Skip to content

Commit

Permalink
feat: add button to download api-docs json (#2612)
Browse files Browse the repository at this point in the history
* feat: add button to download api-docs json

* remove styles
  • Loading branch information
LeahMarieBush authored Oct 31, 2024
1 parent 594ff02 commit 06244f9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/views/open-api-docs-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import SidebarBackToLink from 'components/sidebar/components/sidebar-back-to-lin
import VersionSwitcher from 'components/version-switcher'
import OpenApiSidebarContents from 'components/open-api-sidebar-contents'
import { ApiDocsVersionAlert } from 'views/api-docs-view/components'
import StandaloneLink from '@components/standalone-link'
import { IconDownload16 } from '@hashicorp/flight-icons/svg-react/download-16'

// Local
import {
OpenApiDocsMobileMenuLevels,
Expand Down Expand Up @@ -40,6 +43,7 @@ function OpenApiDocsView({
versionSwitcherProps,
isVersionedUrl,
versionAlert,
schemaFileString,
}: OpenApiDocsViewProps) {
return (
<SidebarLayout
Expand Down Expand Up @@ -85,6 +89,15 @@ function OpenApiDocsView({
) : null
}
/>
<StandaloneLink
text="Download Spec"
icon={<IconDownload16 />}
iconPosition="leading"
download="hcp.swagger.json"
href={`data:text/json;charset=utf-8,${encodeURIComponent(
schemaFileString
)}`}
/>
</div>
<div className={s.operationsSection}>
<h2 className={s.operationsHeading}>Operations</h2>
Expand Down
1 change: 1 addition & 0 deletions src/views/open-api-docs-view/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export async function getStaticProps({
latestStableVersion: defaultVersion,
basePath,
},
schemaFileString,
},
}
}
5 changes: 5 additions & 0 deletions src/views/open-api-docs-view/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ export interface OpenApiDocsViewProps {
* Optional. If provided, a version alert will be shown.
*/
versionAlert?: ApiDocsVersionAlertProps

/**
* File string for downloading api-docs spec file
*/
schemaFileString: string
}

/**
Expand Down

0 comments on commit 06244f9

Please sign in to comment.