Skip to content

Commit 16cc743

Browse files
committed
Merge branch 'support-schema-property-examples' into tmp-release
2 parents b4d0dbc + d29700f commit 16cc743

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

demo/examples/tests/examples.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,18 @@ paths:
347347
age: 30
348348
isStudent: true
349349

350+
/response/mediaTypeObject/noSchema:
351+
get:
352+
tags:
353+
- examples
354+
summary: no schema in response
355+
description: "description of response media type object no schema"
356+
responses:
357+
"200":
358+
description: successful response
359+
content:
360+
application/json:
361+
350362
/response/schema/example:
351363
get:
352364
tags:

packages/docusaurus-theme-openapi-docs/lib/theme/BaseSchema/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,24 @@ const BaseSchemaComponent = ({ title, body, style, schemaType }) => {
3636
MimeTabs_1.default,
3737
{ className: "openapi-tabs__mime", schemaType: schemaType },
3838
mimeTypes.map((mimeType) => {
39-
const mimeExamples = body.content[mimeType].examples;
40-
const mimeExample = body.content[mimeType].example;
41-
const schemaExamples = body.content[mimeType].schema?.examples;
42-
const schemaExample = body.content[mimeType].schema?.example;
43-
const firstBody = body.content[mimeType].schema;
39+
const mimeExamples = body.content?.[mimeType]?.examples;
40+
const mimeExample = body.content?.[mimeType]?.example;
41+
const schemaExamples = body.content?.[mimeType]?.schema?.examples;
42+
const schemaExample = body.content?.[mimeType]?.schema?.example;
43+
const firstBody = body.content?.[mimeType]?.schema;
4444
if (
4545
firstBody === undefined ||
4646
(firstBody.properties &&
4747
Object.keys(firstBody.properties).length === 0)
4848
) {
49-
return null;
49+
return (
50+
// @ts-ignore
51+
react_1.default.createElement(
52+
TabItem_1.default,
53+
{ key: mimeType, label: mimeType, value: mimeType },
54+
react_1.default.createElement("div", null, "No schema")
55+
)
56+
);
5057
}
5158
if (firstBody) {
5259
const tabTitle = "Schema";

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,23 @@ const BaseSchemaComponent: React.FC<Props> = ({
5757
return (
5858
<MimeTabs className="openapi-tabs__mime" schemaType={schemaType}>
5959
{mimeTypes.map((mimeType: any) => {
60-
const mimeExamples = body.content![mimeType].examples;
61-
const mimeExample = body.content![mimeType].example;
62-
const schemaExamples = body.content![mimeType].schema?.examples;
63-
const schemaExample = body.content![mimeType].schema?.example;
64-
const firstBody = body.content![mimeType].schema;
60+
const mimeExamples = body.content?.[mimeType]?.examples;
61+
const mimeExample = body.content?.[mimeType]?.example;
62+
const schemaExamples = body.content?.[mimeType]?.schema?.examples;
63+
const schemaExample = body.content?.[mimeType]?.schema?.example;
64+
const firstBody = body.content?.[mimeType]?.schema;
6565

6666
if (
6767
firstBody === undefined ||
6868
(firstBody.properties &&
6969
Object.keys(firstBody.properties).length === 0)
7070
) {
71-
return null;
71+
return (
72+
// @ts-ignore
73+
<TabItem key={mimeType} label={mimeType} value={mimeType}>
74+
<div>No schema</div>
75+
</TabItem>
76+
);
7277
}
7378

7479
if (firstBody) {

0 commit comments

Comments
 (0)