Skip to content

Commit

Permalink
Fix support for example summaries (#898)
Browse files Browse the repository at this point in the history
* switch from markdown to div for example summary

* remove Markdown import from api page template

* add examples for testing

* add openapi-example__summary class
  • Loading branch information
sserrata authored Jul 23, 2024
1 parent a051895 commit 6c12cd7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
3 changes: 3 additions & 0 deletions demo/examples/petstore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,8 @@ paths:
type: string
examples:
response:
summary: |
This is an example of using **Docusaurus** `markdown` in a summary. Note that admonitions are not fully supported.
value: OK
application/xml:
schema:
Expand Down Expand Up @@ -1194,6 +1196,7 @@ components:
title: Pettie
- $ref: "#/components/schemas/Pet"
example:
summary: A great example!
category:
name: Great Dane
sub:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ export function createResponseExamples(
value: `${exampleName}`,
children: [
guard(exampleValue.summary, (summary) => [
create("Markdown", {
children: ` ${summary}`,
create("div", {
children: `${summary}`,
className: "openapi-example__summary",
}),
]),
create("ResponseSamples", {
Expand All @@ -143,8 +144,9 @@ export function createResponseExamples(
value: `${exampleName}`,
children: [
guard(exampleValue.summary, (summary) => [
create("Markdown", {
children: ` ${summary}`,
create("div", {
children: `${summary}`,
className: "openapi-example__summary",
}),
]),
create("ResponseSamples", {
Expand All @@ -171,8 +173,9 @@ export function createResponseExample(responseExample: any, mimeType: string) {
value: `Example`,
children: [
guard(responseExample.summary, (summary) => [
create("Markdown", {
children: ` ${summary}`,
create("div", {
children: `${summary}`,
className: "openapi-example__summary",
}),
]),
create("ResponseSamples", {
Expand All @@ -187,8 +190,9 @@ export function createResponseExample(responseExample: any, mimeType: string) {
value: `Example`,
children: [
guard(responseExample.summary, (summary) => [
create("Markdown", {
children: ` ${summary}`,
create("div", {
children: `${summary}`,
className: "openapi-example__summary",
}),
]),
create("ResponseSamples", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export function createApiPageMD({
`import ResponseSamples from "@theme/ResponseSamples";\n`,
`import SchemaItem from "@theme/SchemaItem";\n`,
`import SchemaTabs from "@theme/SchemaTabs";\n`,
`import Markdown from "@theme/Markdown";\n`,
`import Heading from "@theme/Heading";\n`,
`import OperationTabs from "@theme/OperationTabs";\n`,
`import TabItem from "@theme/TabItem";\n\n`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import FormSelect from "@theme/ApiExplorer/FormSelect";
import FormTextInput from "@theme/ApiExplorer/FormTextInput";
import LiveApp from "@theme/ApiExplorer/LiveEditor";
import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
import Markdown from "@theme/Markdown";
import SchemaTabs from "@theme/SchemaTabs";
import TabItem from "@theme/TabItem";
import { RequestBodyObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
Expand Down Expand Up @@ -304,7 +303,7 @@ function Body({
</TabItem>
{/* @ts-ignore */}
<TabItem label="Example" value="example">
{example.summary && <Markdown children={example.summary} />}
{example.summary && <div>{example.summary}</div>}
{exampleBody && (
<LiveApp
action={dispatch}
Expand Down Expand Up @@ -342,7 +341,7 @@ function Body({
value={example.label}
key={example.label}
>
{example.summary && <Markdown children={example.summary} />}
{example.summary && <div>{example.summary}</div>}
{example.body && (
<LiveApp action={dispatch} language={language}>
{example.body}
Expand Down

0 comments on commit 6c12cd7

Please sign in to comment.