Skip to content
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
9 changes: 8 additions & 1 deletion demo/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ const config: Config = {
groupPathsBy: "tag",
categoryLinkSource: "tag",
},
markdownGenerators: {
createInfoPageMD: true,
}, // customize MDX with markdown generator
template: "templates/api.mustache", // Customize API MDX with mustache template
infoTemplate: "templates/info.mustache",
tagTemplate: "templates/tag.mustache",
Expand All @@ -318,7 +321,11 @@ const config: Config = {
downloadUrl: "/petstore-3.1.yaml",
hideSendButton: false,
showSchemas: true,
markdownGenerators: { createApiPageMD: myCustomApiMdGenerator }, // customize MDX with markdown generator
markdownGenerators: {
createApiPageMD: myCustomApiMdGenerator,
// Explicitly disable info page generation for testing
createInfoPageMD: false,
}, // customize MDX with markdown generator
} satisfies OpenApiPlugin.Options,
cos: {
specPath: "examples/openapi-cos.json",
Expand Down
12 changes: 6 additions & 6 deletions packages/docusaurus-plugin-openapi-docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following

`markdownGenerators` can be configured with the following options:

| Name | Type | Default | Description |
| -------------------- | ---------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `createApiPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for API pages.<br/><br/>**Function type:** `(pageData: ApiPageMetadata) => string` |
| `createInfoPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for info pages.<br/><br/>**Function type:** `(pageData: InfoPageMetadata) => string` |
| `createTagPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for tag pages.<br/><br/>**Function type:** `(pageData: TagPageMetadata) => string` |
| `createSchemaPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for schema pages.<br/><br/>**Function type:** `(pageData: SchemaPageMetadata) => string` |
| Name | Type | Default | Description |
| -------------------- | --------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `createApiPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for API pages.<br/><br/>**Function type:** `(pageData: ApiPageMetadata) => string` |
| `createInfoPageMD` | `function \| boolean` | `null` | _Optional:_ Returns a string of the raw markdown body for info pages. Set to `false` to explicitly disable info page generation. Set to `true` to explicitly enable with default generator.<br/><br/>**Function type:** `(pageData: InfoPageMetadata) => string` |
| `createTagPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for tag pages.<br/><br/>**Function type:** `(pageData: TagPageMetadata) => string` |
| `createSchemaPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for schema pages.<br/><br/>**Function type:** `(pageData: SchemaPageMetadata) => string` |

### sidebarGenerators

Expand Down
8 changes: 7 additions & 1 deletion packages/docusaurus-plugin-openapi-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,14 @@ custom_edit_url: null

const apiPageGenerator =
markdownGenerators?.createApiPageMD ?? createApiPageMD;

// Handle boolean values for createInfoPageMD
// true or undefined = use default, false = disabled (won't be called), function = use custom
const infoPageGenerator =
markdownGenerators?.createInfoPageMD ?? createInfoPageMD;
typeof markdownGenerators?.createInfoPageMD === "function"
? markdownGenerators.createInfoPageMD
: createInfoPageMD;

const tagPageGenerator =
markdownGenerators?.createTagPageMD ?? createTagPageMD;
const schemaPageGenerator =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ function createItems(
const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
const infoId = kebabCase(infoIdSpaces);

if (openapiData.info.description || openapiData.info.title) {
// Only create an info page if we have a description.
// Only create an info page if we have a description/title AND createInfoPageMD is not explicitly false
if (
(openapiData.info.description || openapiData.info.title) &&
options.markdownGenerators?.createInfoPageMD !== false
) {
const infoDescription = openapiData.info?.description;
let splitDescription: any;
if (infoDescription) {
Expand Down
3 changes: 2 additions & 1 deletion packages/docusaurus-plugin-openapi-docs/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const sidebarOptions = Joi.object({

const markdownGenerators = Joi.object({
createApiPageMD: Joi.function(),
createInfoPageMD: Joi.function(),
// Allow createInfoPageMD to be a function, true (use default), or false (disable)
createInfoPageMD: Joi.alternatives().try(Joi.function(), Joi.boolean()),
createTagPageMD: Joi.function(),
createSchemaPageMD: Joi.function(),
});
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-openapi-docs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface APIOptions {

export interface MarkdownGenerator {
createApiPageMD?: (pageData: ApiPageMetadata) => string;
createInfoPageMD?: (pageData: InfoPageMetadata) => string;
createInfoPageMD?: ((pageData: InfoPageMetadata) => string) | boolean;
createTagPageMD?: (pageData: TagPageMetadata) => string;
createSchemaPageMD?: (pageData: SchemaPageMetadata) => string;
}
Expand Down