Skip to content

Commit

Permalink
Merge pull request #11 from XaaXaaX/main
Browse files Browse the repository at this point in the history
add services instead of path in generator options
  • Loading branch information
boyney123 authored Sep 21, 2024
2 parents 15fad8e + a7dd194 commit afba2b1
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 155 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-shoes-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eventcatalog/generator-openapi": major
---

feat(plugin): plugin now accepts services, path, id and folderName
140 changes: 70 additions & 70 deletions .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
name: Bug Report 🐞
description: Create a bug report
labels: ["🐛 bug"]
labels: ['🐛 bug']
body:
- type: markdown
attributes:
value: |
:pray: Thanks for taking the time to fill out this bug report! Feel free to ping us on [EventCatalog Discord](https://discord.com/invite/3rjaZMmrAm) if you have any questions or need help.
- type: markdown
attributes:
value: |
:pray: Thanks for taking the time to fill out this bug report! Feel free to ping us on [EventCatalog Discord](https://discord.com/invite/3rjaZMmrAm) if you have any questions or need help.
- type: markdown
attributes:
value: |
## Bug Report
- type: markdown
attributes:
value: |
## Bug Report
- type: textarea
id: i-tried-this
attributes:
label: "I tried this:"
placeholder: "What did you try to do? A code snippet or example helps."
validations:
required: true
- type: textarea
id: i-tried-this
attributes:
label: 'I tried this:'
placeholder: 'What did you try to do? A code snippet or example helps.'
validations:
required: true

- type: textarea
id: instead-what-happened
attributes:
label: "This happened:"
placeholder: "What happened instead of what you've expected?"
validations:
required: true
- type: textarea
id: instead-what-happened
attributes:
label: 'This happened:'
placeholder: "What happened instead of what you've expected?"
validations:
required: true

- type: textarea
id: what-did-you-expect
attributes:
label: "I expected this:"
placeholder: "What did you expect to happen? Describe the output or behavior you expected to see (unless it's obvious)."
- type: textarea
id: what-did-you-expect
attributes:
label: 'I expected this:'
placeholder: "What did you expect to happen? Describe the output or behavior you expected to see (unless it's obvious)."

- type: textarea
id: workaround
attributes:
label: "Is there a workaround?"
placeholder: "What's the workaround to avoid this issue?"
- type: textarea
id: workaround
attributes:
label: 'Is there a workaround?'
placeholder: "What's the workaround to avoid this issue?"

- type: textarea
attributes:
label: Anything else?
placeholder: |
Links? References? Logs? Anything that will give us more context about the issue you are encountering.
Tip: You can attach images or log files by dragging files in.
- type: textarea
attributes:
label: Anything else?
placeholder: |
Links? References? Logs? Anything that will give us more context about the issue you are encountering.
Tip: You can attach images or log files by dragging files in.
- type: markdown
attributes:
value: |
## Environment
- type: markdown
attributes:
value: |
## Environment
- type: input
id: eventcatalog-version
attributes:
label: "EventCatalog Version"
placeholder: "@eventcatalog/core@{version}"
- type: input
id: eventcatalog-version
attributes:
label: 'EventCatalog Version'
placeholder: '@eventcatalog/core@{version}'

- type: input
id: node
attributes:
label: "Node.js Version"
placeholder: "node --version"
- type: input
id: node
attributes:
label: 'Node.js Version'
placeholder: 'node --version'

- type: dropdown
id: platform
attributes:
label: "Platform(s)"
multiple: true
options:
- MacOS
- Linux
- Windows
- Other
- type: dropdown
id: platform
attributes:
label: 'Platform(s)'
multiple: true
options:
- MacOS
- Linux
- Windows
- Other

- type: textarea
attributes:
label: Community Notes
value: |
<!-- Please keep this note for the community -->
* Please vote by adding a 👍 reaction to the issue to help us prioritize.
* If you are interested to work on this issue, please leave a comment.
- type: textarea
attributes:
label: Community Notes
value: |
<!-- Please keep this note for the community -->
* Please vote by adding a 👍 reaction to the issue to help us prioritize.
* If you are interested to work on this issue, please leave a comment.
80 changes: 40 additions & 40 deletions .github/ISSUE_TEMPLATE/feature.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
name: Enhancement 🚀
description: Suggest a new feature or other improvement
labels: ["✨ enhancement","needs-discussion"]
labels: ['✨ enhancement', 'needs-discussion']
body:
- type: markdown
attributes:
value: |
:pray: Thanks for taking the time to fill out this enhancement request! Feel free to ping us on [EventCatalog Discord](https://discord.com/invite/3rjaZMmrAm) if you have any questions or need help.
- type: markdown
attributes:
value: |
:pray: Thanks for taking the time to fill out this enhancement request! Feel free to ping us on [EventCatalog Discord](https://discord.com/invite/3rjaZMmrAm) if you have any questions or need help.
- type: markdown
attributes:
value: |
## Enhancement Request
- type: markdown
attributes:
value: |
## Enhancement Request
- type: textarea
id: use-cases
attributes:
label: Use Case
placeholder: What problem are you trying to solve? Describe a *concrete* example of something you are trying to do and as many details as possible about your motivation, the environment, etc.
validations:
required: true
- type: textarea
id: use-cases
attributes:
label: Use Case
placeholder: What problem are you trying to solve? Describe a *concrete* example of something you are trying to do and as many details as possible about your motivation, the environment, etc.
validations:
required: true

- type: textarea
id: proposal
attributes:
label: Proposed Solution
description:
placeholder: |
Optionally, describe how you would have ideally wanted EventCatalog to support this use case.
This can be a hypothetical "user story".
The purpose of this section is not to design a complete solution but rather to inspire the designer on what a user would have intuitively expected the solution to look like.
- type: textarea
id: proposal
attributes:
label: Proposed Solution
description:
placeholder: |
Optionally, describe how you would have ideally wanted EventCatalog to support this use case.
This can be a hypothetical "user story".
The purpose of this section is not to design a complete solution but rather to inspire the designer on what a user would have intuitively expected the solution to look like.
- type: textarea
id: implementation-notes
attributes:
label: Implementation Notes
description:
placeholder: |
Any thoughts regarding how this should be implemented?
- type: textarea
id: implementation-notes
attributes:
label: Implementation Notes
description:
placeholder: |
Any thoughts regarding how this should be implemented?
- type: textarea
attributes:
label: Community Notes
value: |
<!-- Please keep this note for the community -->
* Please vote by adding a 👍 reaction to the issue to help us prioritize.
* If you are interested to work on this issue, please leave a comment.
* If this issue is labeled **needs-discussion**, it means the spec has not been finalized yet. Please reach out in the [EventCatalog Discord](https://discord.com/invite/3rjaZMmrAm).
- type: textarea
attributes:
label: Community Notes
value: |
<!-- Please keep this note for the community -->
* Please vote by adding a 👍 reaction to the issue to help us prioritize.
* If you are interested to work on this issue, please leave a comment.
* If this issue is labeled **needs-discussion**, it means the spec has not been finalized yet. Please reach out in the [EventCatalog Discord](https://discord.com/invite/3rjaZMmrAm).
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ generators: [
[
'@eventcatalogtest/generator-openapi',
{
path: [path.join(__dirname, 'openapi-files', 'petstore.yml'),
services: [
{ path: [path.join(__dirname, 'openapi-files', 'petstore.yml') },
{ path: [path.join(__dirname, 'openapi-files', 'account-service.yml'), id: 'account-service', folderName: 'Account Service' },
],
domain: { id: 'orders', name: 'Orders', version: '0.0.1' },
},
],
Expand Down
25 changes: 12 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { defaultMarkdown as generateMarkdownForDomain } from './utils/domains';
import { buildService } from './utils/services';
import { buildMessage } from './utils/messages';
import { getOperationsByType } from './utils/openapi';
import { Domain } from './types';
import { Domain, Service } from './types';
import { getMessageTypeUtils } from './utils/catalog-shorthand';
import { OpenAPI } from 'openapi-types';
import checkLicense from './utils/checkLicense';

type Props = {
path: string | string[];
services: Service[];
domain?: Domain;
debug?: boolean;
};
Expand All @@ -35,24 +35,23 @@ export default async (_: any, options: Props) => {
addFileToService,
} = utils(process.env.PROJECT_DIR);

const openAPIFiles = Array.isArray(options.path) ? options.path : [options.path];

for (const path of openAPIFiles) {
console.log(chalk.green(`Processing ${path}`));
const services = options.services ?? [];
for (const serviceSpec of services) {
console.log(chalk.green(`Processing ${serviceSpec.path}`));

try {
await SwaggerParser.validate(path);
await SwaggerParser.validate(serviceSpec.path);
} catch (error) {
console.error(chalk.red(`Failed to parse OpenAPI file: ${path}`));
console.error(chalk.red(`Failed to parse OpenAPI file: ${serviceSpec.path}`));
console.error(chalk.red(error));
continue;
}

const openAPIFile = await readFile(path, 'utf-8');
const document = await SwaggerParser.parse(path);
const openAPIFile = await readFile(serviceSpec.path, 'utf-8');
const document = await SwaggerParser.parse(serviceSpec.path);
const version = document.info.version;

const service = buildService(path, document);
const service = buildService(serviceSpec, document);
let serviceMarkdown = service.markdown;
let serviceSpecifications = service.specifications;

Expand Down Expand Up @@ -91,7 +90,7 @@ export default async (_: any, options: Props) => {
}

// Process all messages for the OpenAPI spec
let { sends, receives } = await processMessagesForOpenAPISpec(path, document);
let { sends, receives } = await processMessagesForOpenAPISpec(serviceSpec.path, document);

// Check if service is already defined... if the versions do not match then create service.
const latestServiceInCatalog = await getService(service.id, 'latest');
Expand Down Expand Up @@ -127,7 +126,7 @@ export default async (_: any, options: Props) => {
sends,
receives,
},
{ path: service.name }
{ path: serviceSpec.folderName || service.name }
);

await addFileToService(
Expand Down
Loading

0 comments on commit afba2b1

Please sign in to comment.