Plugin Configuration
Overview
The EventCatalog OpenAPI plugin is configured in the eventcatalog.config.js
file inside the generators
array.
Required Configuration Options
Option | Type | Required | Description |
---|---|---|---|
services | Service[] | Yes | List of OpenAPI files to add to your catalog |
licenseKey | string | Yes* | License key for the plugin. Get a 14-day trial at EventCatalog Cloud. Can also be set via EVENTCATALOG_LICENSE_KEY_OPENAPI environment variable. |
Service Configuration
Each service in the services
array requires the following properties:
Property | Type | Required | Description |
---|---|---|---|
id | string | Yes | EventCatalog ID for the service. |
path | string or string[] | Yes | Path/s to your OpenAPI file or remote URL to the OpenAPI file. v6.0.0 introduced the ability to map multiple OpenAPI files to a single service. |
owners | string[] | No | Owners of the service. You can assign EventCatalog users or teams to services. |
setMessageOwnersToServiceOwners | boolean | No | If true, the owners of the service will be set to the owners of the messages in the OpenAPI file (default is true). |
generateMarkdown | function | - | Function to override the default markdown generation for the service. See Markdown templates for more information. |
draft | boolean | No | If true, the service will be drafted in EventCatalog with all it's endpoints / messages. (Added in v7.3.0) |
Optional Configuration Options
Option | Type | Default | Description |
---|---|---|---|
domain | object | - | Domain to associate all configured services with |
domain.id | string | - | Domain identifier |
domain.name | string | - | Domain display name |
domain.version | string | - | Domain version |
domain.draft | boolean | No | If true, the domain will be drafted in EventCatalog with all it's services / messages. (Added in v7.3.0) |
domain.generateMarkdown | function | - | Function to override the default markdown generation for the domain. See Markdown templates for more information. |
messages.generateMarkdown | function | - | Function to override the default markdown generation for the message. See Markdown templates for more information. |
writeFilesToRoot | boolean | false | Write OpenAPI messages to root instead of service folder. By default all domains, services and messages will be grouped in the folder directory structure. |
saveParsedSpecFile | boolean | false | Parse and save expanded OpenAPI spec (helpful for files with $refs) |
sidebarBadgeType | string | HTTP_METHOD | (Added in v5.0.1) Decides what badges are shown in the documentation sidebar. HTTP_METHOD shows HTTP methods as badges, MESSAGE_TYPE shows QUERY , COMMAND or EVENT as badges. |
httpMethodsToMessages | object | - | (Added in v5.0.2) Gives you the ability to map HTTP methods (GET , POST , PUT , DELETE , PATCH , etc.) to message types (command , query , event ). By default OpenAPI will map your requests to queries, you can use this property to change this behavior or use the x-eventcatalog-message-type extension to set the message type for each request. If you use the x-eventcatalog-message-type extension in your spec file, this will be used. |
preserveExistingMessages | boolean | true | (Added in v5.0.5) If true, the existing message markdown is preserved on new generation (default is true). Setting to false will always write the message markdown from the OpenAPI spec file. |
Example Configuration
import path from "path";
import url from "url";
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
/** @type {import('@eventcatalog/core/bin/eventcatalog.config').Config} */
export default {
cId: "10b46030-5736-4600-8254-421c3ed56e47",
title: "MetaRetail Inc",
tagline: "Fake Retail Company for EventCatalog Demo",
organizationName: "MetaRetail Inc",
homepageLink: "https://eventcatalog.dev/",
editUrl: "https://github.com/boyney123/eventcatalog-demo/edit/master",
// By default set to false, add true to get urls ending in /
trailingSlash: false,
// Change to make the base url of the site different, by default https://{website}.com/docs,
// changing to /company would be https://{website}.com/company/docs,
base: "/",
// Customize the logo, add your logo to public/ folder
logo: {
alt: "EventCatalog Logo",
src: "/logo.png",
text: "MetaRetail Inc",
},
docs: {
sidebar: {
// Should the sub heading be rendered in the docs sidebar?
showPageHeadings: true,
},
},
generators: [
// Add single OpenAPI file to a domain
[
'@eventcatalog/generator-openapi',
{
services: [
{
path: path.join(__dirname, 'openapi-files', 'orders-service.yml'),
id: 'orders-service'
}
],
domain: { id: 'orders', name: 'Orders', version: '0.0.1' },
// Will render POST, GET, PUT, DELETE as badges in the sidebar
sidebarBadgeType: 'HTTP_METHOD',
// or set the license key via the environment variable as EVENTCATALOG_LICENSE_KEY_OPENAPI
licenseKey: 'YOUR_LICENSE_KEY'
},
],
// Add multiple OpenAPI files to a domain
[
'@eventcatalog/generator-openapi',
{
services: [
{
path: path.join(__dirname, 'openapi-files', 'payment-service.yml'),
id: 'payment-service'
},
{
path: path.join(__dirname, 'openapi-files', 'fraud-detection-service.yml'),
id: 'fraud-detection-service'
}
],
domain: { id: 'payment', name: 'Payment', version: '0.0.1' },
// Will render QUERY, COMMAND, EVENT as badges in the sidebar
sidebarBadgeType: 'MESSAGE_TYPE',
// Here we map the HTTP methods to the message types for EventCatalog (optional)
// e.g All post requests are mapped to commands, all get requests are mapped to queries
httpMethodsToMessages: {
GET: 'query',
POST: 'command',
PUT: 'command',
DELETE: 'command',
}
// or set the license key via the environment variable as EVENTCATALOG_LICENSE_KEY_OPENAPI
licenseKey: 'YOUR_LICENSE_KEY'
},
],
],
};
You can view an example configuration in the EventCatalog OpenAPI plugin GitHub repository.
Markdown templates
The EventCatalog OpenAPI plugin will generate default markdown for each domain, service and message.
If you want more control, you can override these using your own markdown templates.
To use your own markdown templates you need to provide a function that returns the markdown for the domain, service or message.
Below you can see examples of how to override the default markdown for the domain, service and message.
- Domain Markdown Template
- Service Markdown Template
- Message Markdown Template
Domain
In this example we will override the default markdown for the domain using our custom function. We will also preserve the default markdown for the domain.
// function to generate the markdown for the domain
// You can include this in your config file or in a separate file and import it
const generateMarkdownForDomain = ({ domain, markdown }) => {
return `# ${domain.name}
This is the default markdown for the domain
You can add anything you want here, including components, tables, etc.
## Architecture Diagram
<NodeGraph />
// Add the default markdown for the domain if you want to preserve it
${markdown}
`;
}
// Your configuration
export default {
generators: [
[
'@eventcatalog/generator-openapi',
{
// ...rest of generator config
domain: {
id: 'orders',
name: 'Orders',
version: '0.0.1',
generateMarkdown: generateMarkdownForDomain
}
}
]
]
}
Function Arguments:
Argument | Type | Properties | Description |
---|---|---|---|
domain | object | id , name , version | The domain object you provided in the config |
markdown | string | - | The default markdown for the domain. Incase you want to preserve the default markdown you can use this argument to add to your own markdown. |
Service
In this example we will override the default markdown for the service using our custom function. We will also preserve the default markdown for the service.
// function to generate the markdown for the service
// You can include this in your config file or in a separate file and import it
const generateMarkdownForService = ({ service, markdown, document }) => {
return `# ${service.name}
This is the default markdown for the service
## Description
${document.info.description ? `${document.info.description}` : ''}
`;
}
// Your configuration
export default {
generators: [
[
'@eventcatalog/generator-openapi',
{
// ...rest of generator config
service: {
id: 'orders-service',
name: 'Orders Service',
version: '0.0.1',
generateMarkdown: generateMarkdownForService
}
}
]
]
}
Function Arguments:
Argument | Type | Properties | Description |
---|---|---|---|
service | object | id , name , version | The service object you provided in the config |
markdown | string | - | The default markdown for the service. Incase you want to preserve the default markdown you can use this argument to add to your own markdown. |
document | object | OpenAPI.Document | The OpenAPI document object. |
Message
In this example we will override the default markdown for the message using our custom function. We will also preserve the default markdown for the message.
// function to generate the markdown for the message
// You can include this in your config file or in a separate file and import it
const generateMarkdownForMessage = ({ message, markdown, document }) => {
return `# ${message.name}
This is the default markdown for the message
`;
}
// Your configuration
export default {
generators: [
[
'@eventcatalog/generator-openapi',
{
// ...rest of generator config
messages: {
generateMarkdown: generateMarkdownForMessage
}
}
]
]
}
Function Arguments:
Argument | Type | Properties | Description |
---|---|---|---|
operation | object | OpenAPI.Operation | The operation object from the OpenAPI document. |
markdown | string | - | The default markdown for the message. Incase you want to preserve the default markdown you can use this argument to add to your own markdown. |
Need help?
If you have questions or need help, you can join our Discord community or refer to the OpenAPI examples on GitHub.