Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7c78cb3

Browse files
Handle OpenAPI ignored responses
1 parent 262a9b1 commit 7c78cb3

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

‎.changeset/shaggy-crabs-return.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@gitbook/openapi-parser': patch
3+
'@gitbook/react-openapi': patch
4+
---
5+
6+
Handle OpenAPI ignored responses

‎packages/openapi-parser/src/helpers/shouldIgnoreEntity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { OpenAPIV3 } from '@scalar/openapi-types';
44
* Check if an entity should be ignored
55
*/
66
export function shouldIgnoreEntity(
7-
data: undefined | OpenAPIV3.TagObject | OpenAPIV3.OperationObject
7+
data: undefined | OpenAPIV3.TagObject | OpenAPIV3.OperationObject|OpenAPIV3.ResponseObject
88
) {
99
return data?.['x-internal'] === true || data?.['x-gitbook-ignore'] === true;
1010
}

‎packages/react-openapi/src/OpenAPIResponseExample.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type{OpenAPIV3 } from '@gitbook/openapi-parser';
1+
import {typeOpenAPIV3,shouldIgnoreEntity } from '@gitbook/openapi-parser';
22
import { Markdown } from './Markdown';
33
import { OpenAPIEmptyExample, OpenAPIExample } from './OpenAPIExample';
44
import { OpenAPIMediaTypeContent } from './OpenAPIMediaType';
@@ -42,7 +42,12 @@ export function OpenAPIResponseExample(props: {
4242
});
4343

4444
const tabs = responses
45-
.filter(([_, responseObject]) => responseObject && typeof responseObject === 'object')
45+
.filter(
46+
([_, responseObject]) =>
47+
responseObject &&
48+
typeof responseObject === 'object' &&
49+
!shouldIgnoreEntity(responseObject)
50+
)
4651
.map(([key, responseObject]) => {
4752
const description = resolveDescription(responseObject);
4853
const label = description ? (

‎packages/react-openapi/src/OpenAPIResponses.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import type{OpenAPIV3, OpenAPIV3_1 } from '@gitbook/openapi-parser';
3+
import {typeOpenAPIV3, typeOpenAPIV3_1,shouldIgnoreEntity } from '@gitbook/openapi-parser';
44
import clsx from 'clsx';
55
import { Markdown } from './Markdown';
66
import { OpenAPIDisclosureGroup } from './OpenAPIDisclosureGroup';
@@ -26,7 +26,10 @@ export function OpenAPIResponses(props: {
2626
const { responses, context } = props;
2727

2828
const groups = Object.entries(responses)
29-
.filter(([_, response]) => response && typeof response === 'object')
29+
.filter(
30+
([_, response]) =>
31+
response && typeof response === 'object' && !shouldIgnoreEntity(response)
32+
)
3033
.map(([statusCode, response]: [string, OpenAPIV3.ResponseObject]) => {
3134
const tabs = (() => {
3235
// If there is no content, but there are headers, we need to show the headers
@@ -107,6 +110,11 @@ export function OpenAPIResponses(props: {
107110

108111
const state = useResponseExamplesState(context.blockKey, groups[0]?.key);
109112

113+
// If there are no responses, don't display anything
114+
if (!groups.length) {
115+
return null;
116+
}
117+
110118
return (
111119
<StaticSection header={t(context.translation, 'responses')} className="openapi-responses">
112120
<OpenAPIDisclosureGroup

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /