Skip to content

Commit bc71cb9

Browse files
authored
Handle missing params/header schema (#446)
* Default to any if no header schema/type exists * Default to any if no param schema/type exists * Switch to test spec
1 parent 77a882c commit bc71cb9

File tree

3 files changed

+44
-40
lines changed

3 files changed

+44
-40
lines changed

demo/docusaurus.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ const config = {
223223
},
224224
},
225225
petstore: {
226-
specPath: "examples/petstore.yaml",
226+
specPath:
227+
"https://raw.githubusercontent.com/benlei/docusaurus-openapi-docs-failed-to-gen/master/examples/petstore.yaml",
227228
proxy: "https://cors.pan.dev",
228229
outputDir: "docs/petstore",
229230
sidebarOptions: {

packages/docusaurus-plugin-openapi-docs/src/markdown/createStatusCodes.ts

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -62,46 +62,45 @@ function createResponseHeaders(responseHeaders: any) {
6262
create("ul", {
6363
style: { marginLeft: "1rem" },
6464
children: [
65-
Object.entries(responseHeaders).map(([headerName, headerObj]) => {
66-
const {
67-
description,
68-
schema: { type },
69-
example,
70-
}: any = headerObj;
65+
Object.entries(responseHeaders).map(
66+
([headerName, headerObj]: [any, any]) => {
67+
const { description, example }: any = headerObj;
68+
const type = headerObj.schema?.type ?? "any";
7169

72-
return create("li", {
73-
className: "schemaItem",
74-
children: [
75-
createDetailsSummary({
76-
children: [
77-
create("strong", { children: headerName }),
78-
guard(type, () => [
79-
create("span", {
80-
style: { opacity: "0.6" },
81-
children: ` ${type}`,
82-
}),
83-
]),
84-
],
85-
}),
86-
create("div", {
87-
children: [
88-
guard(description, (description) =>
89-
create("div", {
90-
style: {
91-
marginTop: ".5rem",
92-
marginBottom: ".5rem",
93-
},
94-
children: [
95-
guard(example, () => `Example: ${example}`),
96-
createDescription(description),
97-
],
98-
})
99-
),
100-
],
101-
}),
102-
],
103-
});
104-
}),
70+
return create("li", {
71+
className: "schemaItem",
72+
children: [
73+
createDetailsSummary({
74+
children: [
75+
create("strong", { children: headerName }),
76+
guard(type, () => [
77+
create("span", {
78+
style: { opacity: "0.6" },
79+
children: ` ${type}`,
80+
}),
81+
]),
82+
],
83+
}),
84+
create("div", {
85+
children: [
86+
guard(description, (description) =>
87+
create("div", {
88+
style: {
89+
marginTop: ".5rem",
90+
marginBottom: ".5rem",
91+
},
92+
children: [
93+
guard(example, () => `Example: ${example}`),
94+
createDescription(description),
95+
],
96+
})
97+
),
98+
],
99+
}),
100+
],
101+
});
102+
}
103+
),
105104
],
106105
})
107106
);

packages/docusaurus-theme-openapi-docs/src/theme/ParamsItem/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ import styles from "./styles.module.css";
3030
function ParamsItem({
3131
param: { description, example, examples, name, required, schema },
3232
}) {
33+
if (!schema || !schema?.type) {
34+
schema = { type: "any" };
35+
}
36+
3337
const renderSchemaName = guard(schema, (schema) => (
3438
<span className={styles.schemaName}> {getSchemaName(schema)}</span>
3539
));

0 commit comments

Comments
 (0)