Skip to content

Commit 8f3f511

Browse files
authored
Only create list of 2xx content types for request samples (#365)
* Only create list of 2xx content types for request samples * fix linting * change status code check to use regex
1 parent 45a60f4 commit 8f3f511

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

demo/examples/petstore.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ paths:
206206
application/xml:
207207
schema:
208208
$ref: "#/components/schemas/Pet"
209+
209210
"400":
210211
description: Invalid ID supplied
211212
"404":

demo/sidebars.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ const sidebars = {
101101
],
102102
},
103103
],
104-
105104
"petstore-2.0.0": [
106105
{
107106
type: "html",

packages/docusaurus-theme-openapi-docs/src/theme/ApiItem/index.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ export default function ApiItem(props: Props): JSX.Element {
5353
const options = themeConfig.api;
5454
const isBrowser = useIsBrowser();
5555

56+
// Regex for 2XX status
57+
const statusRegex = new RegExp("(20[0-9]|2[1-9][0-9])");
58+
5659
// Define store2
5760
let store2: any = {};
5861
const persistanceMiddleware = createPersistanceMiddleware(options);
@@ -64,13 +67,15 @@ export default function ApiItem(props: Props): JSX.Element {
6467

6568
// Init store for CSR to hydrate components
6669
if (isBrowser) {
67-
const acceptArray = Array.from(
68-
new Set(
69-
Object.values(api?.responses ?? {})
70-
.map((response: any) => Object.keys(response.content ?? {}))
71-
.flat()
72-
)
73-
);
70+
// Create list of only 2XX response content types to create request samples from
71+
let acceptArray: any = [];
72+
for (const [code, content] of Object.entries(api?.responses ?? [])) {
73+
if (statusRegex.test(code)) {
74+
acceptArray.push(Object.keys(content.content ?? {}));
75+
}
76+
}
77+
acceptArray = acceptArray.flat();
78+
7479
const content = api?.requestBody?.content ?? {};
7580
const contentTypeArray = Object.keys(content);
7681
const servers = api?.servers ?? [];

0 commit comments

Comments
 (0)