Skip to content

refactor: change ResponseSamples to CodeSamples #1162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.openapi-code__code-samples-container {
margin-top: 2rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@ import CodeBlock from "@theme/CodeBlock";
import { Language } from "prism-react-renderer";

export interface Props {
readonly responseExample: string;
readonly example: string;
readonly language: Language;
}

function ResponseSamples({
responseExample,
language,
}: Props): React.JSX.Element {
function CodeSamples({ example, language }: Props): React.JSX.Element {
return (
<div className="openapi-code__response-samples-container">
<CodeBlock language={language ? language : "json"}>
{responseExample}
</CodeBlock>
<div className="openapi-code__code-samples-container">
<CodeBlock language={language ? language : "json"}>{example}</CodeBlock>
</div>
);
}

export default ResponseSamples;
export default CodeSamples;
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import React from "react";

import CodeSamples from "@theme/CodeSamples";
import Markdown from "@theme/Markdown";
import ResponseSamples from "@theme/ResponseSamples";
import TabItem from "@theme/TabItem";
import { sampleResponseFromSchema } from "docusaurus-plugin-openapi-docs/lib/openapi/createResponseExample";
import format from "xml-formatter";
Expand Down Expand Up @@ -78,10 +78,7 @@ export const ResponseExamples: React.FC<ResponseExamplesProps> = ({
{exampleValue.summary}
</Markdown>
)}
<ResponseSamples
responseExample={responseExample}
language={language}
/>
<CodeSamples example={responseExample} language={language} />
</TabItem>
);
}
Expand Down Expand Up @@ -120,7 +117,7 @@ export const ResponseExample: React.FC<ResponseExampleProps> = ({
{responseExample.summary}
</Markdown>
)}
<ResponseSamples responseExample={exampleContent} language={language} />
<CodeSamples example={exampleContent} language={language} />
</TabItem>
);
};
Expand Down Expand Up @@ -167,7 +164,7 @@ export const ExampleFromSchema: React.FC<ExampleFromSchemaProps> = ({
return (
// @ts-ignore
<TabItem label="Example (auto)" value="Example (auto)">
<ResponseSamples responseExample={xmlExample} language="xml" />
<CodeSamples example={xmlExample} language="xml" />
</TabItem>
);
}
Expand All @@ -180,8 +177,8 @@ export const ExampleFromSchema: React.FC<ExampleFromSchemaProps> = ({
return (
// @ts-ignore
<TabItem label="Example (auto)" value="Example (auto)">
<ResponseSamples
responseExample={JSON.stringify(responseExample, null, 2)}
<CodeSamples
example={JSON.stringify(responseExample, null, 2)}
language="json"
/>
</TabItem>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@use "./SchemaTabs/SchemaTabs";
@use "./OperationTabs/OperationTabs";
/* Code Samples */
@use "./ResponseSamples/ResponseSamples";
@use "./CodeSamples/CodeSamples";
/* Markdown Styling */
@use "./Markdown/Details/Details";

Expand Down