Skip to content
Merged
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
3 changes: 2 additions & 1 deletion demo/customMdGenerators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export function myCustomApiMdGenerator({
`import StatusCodes from "@theme/StatusCodes";\n`,
`import OperationTabs from "@theme/OperationTabs";\n`,
`import TabItem from "@theme/TabItem";\n`,
`import Heading from "@theme/Heading";\n\n`,
`import Heading from "@theme/Heading";\n`,
`import Translate from "@docusaurus/Translate";\n\n`,
createHeading(title),
createMethodEndpoint(method, path),
createServersTable(servers),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ import { create } from "./utils";

export function createRequestHeader(header: string) {
return [
create(
"Heading",
{
children: header,
id: header.replace(" ", "-").toLowerCase(),
as: "h2",
className: "openapi-tabs__heading",
},
{ inline: true }
),
`\n\n`,
create("Heading", {
id: header.replace(" ", "-").toLowerCase(),
as: "h2",
className: "openapi-tabs__heading",
children: [
`<Translate id="theme.openapi.request.title">${header}</Translate>`,
],
}),
"\n\n",
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ function createDetailsNode(
() => [
create("span", {
className: "openapi-schema__required",
children: "required",
children:
"<Translate id='theme.openapi.schemaItem.required'>required</Translate>",
}),
]
),
Expand Down Expand Up @@ -530,7 +531,8 @@ function createPropertyDiscriminator(
guard(required, () => [
create("span", {
className: "openapi-schema__required",
children: "required",
children:
"<Translate id='theme.openapi.schemaItem.required'>required</Translate>",
}),
]),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export function createApiPageMD({
`import StatusCodes from "@theme/StatusCodes";\n`,
`import OperationTabs from "@theme/OperationTabs";\n`,
`import TabItem from "@theme/TabItem";\n`,
`import Heading from "@theme/Heading";\n\n`,
`import Heading from "@theme/Heading";\n`,
`import Translate from "@docusaurus/Translate";\n\n`,
createHeading(title),
createMethodEndpoint(method, path),
infoPath && createAuthorization(infoPath),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
* ========================================================================== */

import { translate } from "@docusaurus/Translate";
import { OPENAPI_SCHEMA_ITEM } from "../theme/translationIds";
import { SchemaObject } from "../types";

function prettyName(schema: SchemaObject, circular?: boolean) {
Expand Down Expand Up @@ -72,7 +74,10 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
return getQualifierMessage(schema.items);
}

let message = "**Possible values:** ";
let message = `**${translate({
id: OPENAPI_SCHEMA_ITEM.POSSIBLE_VALUES,
message: "Possible values:",
})}** `;

let qualifierGroups = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ function Authorization() {
return (
<div>
{optionKeys.length > 1 && (
<FormItem label="Security Scheme">
<FormItem
label={translate({
id: OPENAPI_AUTH.SECURITY_SCHEME,
message: "Security Scheme",
})}
>
<FormSelect
options={optionKeys}
value={selected}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,41 @@ function SecuritySchemes(props: any) {
}

const selectedAuth = options[selected];

const keyTranslations: Record<string, { id: string; message: string }> = {
description: {
id: OPENAPI_SECURITY_SCHEMES.DESCRIPTION,
message: "description:",
},
scheme: {
id: OPENAPI_SECURITY_SCHEMES.SCHEME,
message: "scheme:",
},
bearerFormat: {
id: OPENAPI_SECURITY_SCHEMES.BEARER_FORMAT,
message: "bearerFormat:",
},
openIdConnectUrl: {
id: OPENAPI_SECURITY_SCHEMES.OPEN_ID_CONNECT_URL,
message: "openIdConnectUrl:",
},
};

const renderRest = (rest: Record<string, any>) =>
Object.keys(rest).map((k) => {
const translation = keyTranslations[k];
const label = translation
? translate({ id: translation.id, message: translation.message })
: `${k}:`;
return (
<span key={k}>
<strong>{label} </strong>
{typeof rest[k] === "object"
? JSON.stringify(rest[k], null, 2)
: String(rest[k])}
</span>
);
});
return (
<details className="openapi-security__details" open={false}>
<summary className="openapi-security__summary-container">
Expand Down Expand Up @@ -81,16 +116,7 @@ function SecuritySchemes(props: any) {
</code>
</span>
)}
{Object.keys(rest).map((k, i) => {
return (
<span key={k}>
<strong>{k}: </strong>
{typeof rest[k] === "object"
? JSON.stringify(rest[k], null, 2)
: String(rest[k])}
</span>
);
})}
{renderRest(rest)}
</pre>
</React.Fragment>
);
Expand Down Expand Up @@ -137,16 +163,7 @@ function SecuritySchemes(props: any) {
</code>
</span>
)}
{Object.keys(rest).map((k, i) => {
return (
<span key={k}>
<strong>{k}: </strong>
{typeof rest[k] === "object"
? JSON.stringify(rest[k], null, 2)
: String(rest[k])}
</span>
);
})}
{renderRest(rest)}
</pre>
</React.Fragment>
);
Expand Down Expand Up @@ -234,16 +251,7 @@ function SecuritySchemes(props: any) {
</code>
</span>
)}
{Object.keys(rest).map((k, i) => {
return (
<span key={k}>
<strong>{k}: </strong>
{typeof rest[k] === "object"
? JSON.stringify(rest[k], null, 2)
: String(rest[k])}
</span>
);
})}
{renderRest(rest)}
</pre>
</React.Fragment>
);
Expand Down Expand Up @@ -291,16 +299,7 @@ function SecuritySchemes(props: any) {
</code>
</span>
)}
{Object.keys(rest).map((k, i) => {
return (
<span key={k}>
<strong>{k}: </strong>
{typeof rest[k] === "object"
? JSON.stringify(rest[k], null, 2)
: String(rest[k])}
</span>
);
})}
{renderRest(rest)}
{flows && (
<span>
<code>
Expand Down Expand Up @@ -361,16 +360,7 @@ function SecuritySchemes(props: any) {
</code>
</span>
)}
{Object.keys(rest).map((k, i) => {
return (
<span key={k}>
<strong>{k}: </strong>
{typeof rest[k] === "object"
? JSON.stringify(rest[k], null, 2)
: String(rest[k])}
</span>
);
})}
{renderRest(rest)}
</pre>
</React.Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ export interface Props {

const getEnumDescriptionMarkdown = (enumDescriptions?: [string, string][]) => {
if (enumDescriptions?.length) {
return `| Enum Value | Description |
const enumValue = translate({
id: OPENAPI_SCHEMA_ITEM.ENUM_VALUE,
message: "Enum Value",
});
const description = translate({
id: OPENAPI_SCHEMA_ITEM.ENUM_DESCRIPTION,
message: "Description",
});
return `| ${enumValue} | ${description} |
| ---- | ----- |
${enumDescriptions
.map((desc) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React from "react";

import { translate } from "@docusaurus/Translate";
import { OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
import { OPENAPI_REQUEST, OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";

import BrowserOnly from "@docusaurus/BrowserOnly";
import Details from "@theme/Details";
Expand Down Expand Up @@ -67,7 +67,10 @@ const RequestSchemaComponent: React.FC<Props> = ({ title, body, style }) => {
<>
<summary>
<h3 className="openapi-markdown__details-summary-header-body">
{title}
{translate({
id: OPENAPI_REQUEST.BODY_TITLE,
message: title,
})}
{body.required === true && (
<span className="openapi-schema__required">
{translate({
Expand Down Expand Up @@ -120,7 +123,10 @@ const RequestSchemaComponent: React.FC<Props> = ({ title, body, style }) => {
<>
<summary>
<h3 className="openapi-markdown__details-summary-header-body">
{title}
{translate({
id: OPENAPI_REQUEST.BODY_TITLE,
message: title,
})}
{firstBody.type === "array" && (
<span style={{ opacity: "0.6" }}> array</span>
)}
Expand Down
40 changes: 34 additions & 6 deletions packages/docusaurus-theme-openapi-docs/src/theme/Schema/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import React from "react";

import { translate } from "@docusaurus/Translate";
import { OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";

import { ClosingArrayBracket, OpeningArrayBracket } from "@theme/ArrayBrackets";
import Details from "@theme/Details";
import DiscriminatorTabs from "@theme/DiscriminatorTabs";
Expand Down Expand Up @@ -89,12 +92,29 @@ const Summary: React.FC<SummaryProps> = ({
{(isRequired || deprecated || nullable) && (
<span className="openapi-schema__divider" />
)}
{nullable && <span className="openapi-schema__nullable">nullable</span>}
{nullable && (
<span className="openapi-schema__nullable">
{translate({
id: OPENAPI_SCHEMA_ITEM.NULLABLE,
message: "nullable",
})}
</span>
)}
{isRequired && (
<span className="openapi-schema__required">required</span>
<span className="openapi-schema__required">
{translate({
id: OPENAPI_SCHEMA_ITEM.REQUIRED,
message: "required",
})}
</span>
)}
{deprecated && (
<span className="openapi-schema__deprecated">deprecated</span>
<span className="openapi-schema__deprecated">
{translate({
id: OPENAPI_SCHEMA_ITEM.DEPRECATED,
message: "deprecated",
})}
</span>
)}
</span>
</summary>
Expand All @@ -108,14 +128,17 @@ interface SchemaProps {
}

const AnyOneOf: React.FC<SchemaProps> = ({ schema, schemaType }) => {
const type = schema.oneOf ? "oneOf" : "anyOf";
const key = schema.oneOf ? "oneOf" : "anyOf";
const type = schema.oneOf
? translate({ id: OPENAPI_SCHEMA_ITEM.ONE_OF, message: "oneOf" })
: translate({ id: OPENAPI_SCHEMA_ITEM.ANY_OF, message: "anyOf" });
return (
<>
<span className="badge badge--info" style={{ marginBottom: "1rem" }}>
{type}
</span>
<SchemaTabs>
{schema[type]?.map((anyOneSchema: any, index: number) => {
{schema[key]?.map((anyOneSchema: any, index: number) => {
const label = anyOneSchema.title || anyOneSchema.type;
return (
// @ts-ignore
Expand Down Expand Up @@ -254,7 +277,12 @@ const PropertyDiscriminator: React.FC<SchemaEdgeProps> = ({
)}
{required && <span className="openapi-schema__divider"></span>}
{required && (
<span className="openapi-schema__required">required</span>
<span className="openapi-schema__required">
{translate({
id: OPENAPI_SCHEMA_ITEM.REQUIRED,
message: "required",
})}
</span>
)}
</span>
<div style={{ marginLeft: "1rem" }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ const transformEnumDescriptions = (

const getEnumDescriptionMarkdown = (enumDescriptions?: [string, string][]) => {
if (enumDescriptions?.length) {
return `| Enum Value | Description |
const enumValue = translate({
id: OPENAPI_SCHEMA_ITEM.ENUM_VALUE,
message: "Enum Value",
});
const description = translate({
id: OPENAPI_SCHEMA_ITEM.ENUM_DESCRIPTION,
message: "Description",
});
return `| ${enumValue} | ${description} |
| ---- | ----- |
${enumDescriptions
.map((desc) => {
Expand Down
Loading