-
Notifications
You must be signed in to change notification settings - Fork 1
[DEV-2699] Add rapidoc as api viewer #1668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
47acca5
29362be
f1ba8df
d02ed6b
f50021b
297c0f9
37f18ee
30212f9
b56aa21
f2fe415
043b16c
2345b22
87256ef
121af18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"nextjs-website": minor | ||
--- | ||
|
||
Switch api viewer to rapi-doc | ||
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,26 +1,70 @@ | ||||||
'use client'; | ||||||
import { FC } from 'react'; | ||||||
import { API } from '@stoplight/elements'; | ||||||
import '@stoplight/elements/styles.min.css'; | ||||||
import { Box, useTheme } from '@mui/material'; | ||||||
import { Product } from '@/lib/types/product'; | ||||||
import 'rapidoc'; | ||||||
|
||||||
// Extend JSX to recognize the custom element <rapi-doc> | ||||||
declare global { | ||||||
MarBert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||||||
namespace JSX { | ||||||
interface IntrinsicElements { | ||||||
'rapi-doc': React.DetailedHTMLProps< | ||||||
React.HTMLAttributes<HTMLElement>, | ||||||
HTMLElement | ||||||
> & { | ||||||
'spec-url'?: string; | ||||||
theme?: string; | ||||||
'render-style'?: string; | ||||||
'show-header'?: string; | ||||||
'primary-color'?: string; | ||||||
}; | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
type ApiViewerProps = { | ||||||
specURL: string; | ||||||
product: Product; | ||||||
MarBert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
hideTryIt?: boolean; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hideTryIt prop is still defined in ApiViewerProps but is no longer used in the component. This creates an inconsistent API where the prop is accepted but ignored.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
}; | ||||||
const ApiViewer: FC<ApiViewerProps> = ({ | ||||||
hideTryIt = true, | ||||||
specURL, | ||||||
product, | ||||||
}) => { | ||||||
|
||||||
const ApiViewer: FC<ApiViewerProps> = ({ specURL, product }) => { | ||||||
MarBert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
const { palette } = useTheme(); | ||||||
|
||||||
// function that return current API component type | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is unclear and doesn't accurately describe what the function does. It should be updated to describe that the function renders a RapiDoc API viewer component.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
return ( | ||||||
<API | ||||||
apiDescriptionUrl={specURL} | ||||||
hideTryIt={hideTryIt} | ||||||
basePath={`/${product.slug}/api`} | ||||||
router={typeof window === 'undefined' ? 'memory' : 'hash'} | ||||||
/> | ||||||
<Box | ||||||
sx={{ | ||||||
mt: 2, | ||||||
MarBert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
display: 'flex', | ||||||
height: '100%', | ||||||
width: '100%', | ||||||
overflow: 'hidden', | ||||||
}} | ||||||
> | ||||||
<rapi-doc | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i tried to add custom css like here: https://rapidocweb.com/api.html but it doesn't seem to work. The border is an inline style option, so there is some part in the rapidoc parser that sets it. |
||||||
spec-url={specURL} | ||||||
theme='light' | ||||||
nav-bg-color='#EBEEF5' | ||||||
MarBert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
MarBert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
bg-color={palette.background.paper} | ||||||
text-color={palette.text.primary} | ||||||
nav-text-color={palette.text.primary} | ||||||
regular-font='Titillium Web' | ||||||
mono-font='Titillium Web' | ||||||
font-size='largest' | ||||||
MarBert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
render-style='focused' | ||||||
show-header='false' | ||||||
allow-authentication='false' | ||||||
primary-color={palette.primary.main} | ||||||
scroll-y-offset='0' | ||||||
auto-scroll='false' | ||||||
allow-try='false' | ||||||
allow-server-selection='false' | ||||||
show-method-in-nav-bar='as-plain-text' | ||||||
show-components='true' | ||||||
MarBert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
></rapi-doc> | ||||||
</Box> | ||||||
); | ||||||
}; | ||||||
|
||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,8 @@ | |
"dependencies": { | ||
"crypto-js": "^4.2.0", | ||
"elliptic": "^6.6.1", | ||
"koa": "^3.0.0" | ||
"koa": "^3.0.0", | ||
"rapidoc": "^9.3.8" | ||
}, | ||
"packageManager": "[email protected]", | ||
"name": "developer-portal" | ||
|
Uh oh!
There was an error while loading. Please reload this page.