1
0
mirror of synced 2025-12-22 19:34:15 -05:00
Files
docs/components/rest/RestOperation.tsx
Robert Sese 50a8de0769 Separate REST error responses (#26082)
* Add error response variant

* Add response table styles

* Already filtered

* Don't need these styles

* Fallback to http code status messsage

* Add translation strings

* Proper heading level

Co-authored-by: Grace Park <gracepark@github.com>

* Match table styling with params table

* Typing unnecessary

Co-authored-by: Peter Bengtsson <mail@peterbe.com>

* Typing unnecessary

Co-authored-by: Peter Bengtsson <mail@peterbe.com>

* Work with the status code as a number

* Move error responses to operation end

* Make RestResponseTable a standalone component

Co-authored-by: Grace Park <gracepark@github.com>
Co-authored-by: Peter Bengtsson <mail@peterbe.com>
2022-03-15 21:14:53 +00:00

55 lines
1.9 KiB
TypeScript

import { RestOperationHeading } from './RestOperationHeading'
import { RestHTTPMethod } from './RestHTTPMethod'
import { RestParameterTable } from './RestParameterTable'
import { RestCodeSamples } from './RestCodeSamples'
import { RestResponse } from './RestResponse'
import { Operation } from './types'
import { RestNotes } from './RestNotes'
import { RestPreviewNotice } from './RestPreviewNotice'
type Props = {
operation: Operation
index: number
}
export function RestOperation({ operation }: Props) {
const previews = operation['x-github'].previews
const hasRequiredPreviews = previews
? previews.filter((preview) => preview.required).length > 0
: false
return (
<div>
<RestOperationHeading
slug={operation.slug}
summary={operation.summary}
descriptionHTML={operation.descriptionHTML}
/>
<RestHTTPMethod verb={operation.verb} requestPath={operation.requestPath} />
{operation.parameters && (
<RestParameterTable
slug={operation.slug}
hasRequiredPreviews={hasRequiredPreviews}
xGitHub={operation['x-github']}
parameters={operation.parameters}
bodyParameters={operation.bodyParameters}
/>
)}
{operation['x-codeSamples'] && operation['x-codeSamples'].length > 0 && (
<RestCodeSamples slug={operation.slug} xCodeSamples={operation['x-codeSamples']} />
)}
<RestResponse responses={operation.responses} />
{(operation.notes.length > 0 || operation['x-github'].enabledForGitHubApps) && (
<RestNotes
notes={operation.notes}
enabledForGitHubApps={operation['x-github'].enabledForGitHubApps}
/>
)}
{previews && (
<RestPreviewNotice slug={operation.slug} previews={operation['x-github'].previews} />
)}
<RestResponse responses={operation.responses} variant="error" />
</div>
)
}