Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre committed Jan 13, 2023
2 parents c1fd560 + f877c7f commit fd61485
Show file tree
Hide file tree
Showing 27 changed files with 6,240 additions and 5,343 deletions.
18 changes: 18 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,24 @@
"contributions": [
"code"
]
},
{
"login": "michelgrootjans",
"name": "Michel Grootjans",
"avatar_url": "https://avatars.githubusercontent.com/u/345770?v=4",
"profile": "https://github.com/michelgrootjans",
"contributions": [
"code"
]
},
{
"login": "arturoabruzzini",
"name": "Arturo Abruzzini",
"avatar_url": "https://avatars.githubusercontent.com/u/17528406?v=4",
"profile": "https://github.com/arturoabruzzini",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
fetch-depth: 0

# If you use a version of Node other than 12, change it here.
- name: Set up Node.js 14.x
- name: Set up Node.js 16.x
uses: actions/setup-node@master
with:
node-version: 14.x
node-version: 16.x

# If you use npm instead of yarn, change this to `npm install`.
- name: Install dependencies
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- uses: actions/setup-node@v2
with:
cache: yarn
node-version: '16'
- name: Installation
run: yarn
- name: Check immutable yarn.lock
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
with:
fetch-depth: 0

- name: Use Node.js 14.x
- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
version: 14.x
version: 16.x

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: ['14', '16', '17']
node: ['16', '18']
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/verify-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- uses: actions/setup-node@v2
with:
cache: yarn
node-version: '16'
- name: Installation
run: yarn
- name: Check immutable yarn.lock
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![MIT License][license-badge]][license]
[![PRs Welcome][prs-badge]][prs]
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-17-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

[![Watch on GitHub][github-watch-badge]][github-watch]
Expand Down Expand Up @@ -144,6 +144,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="https://github.com/dytyniuk"><img src="https://avatars.githubusercontent.com/u/1890615?v=4?s=100" width="100px;" alt="Yevhenii Dytyniuk"/><br /><sub><b>Yevhenii Dytyniuk</b></sub></a><br /><a href="https://github.com/boyney123/eventcatalog/commits?author=dytyniuk" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/lcsbltm"><img src="https://avatars.githubusercontent.com/u/25868958?v=4?s=100" width="100px;" alt="lcsbltm"/><br /><sub><b>lcsbltm</b></sub></a><br /><a href="https://github.com/boyney123/eventcatalog/commits?author=lcsbltm" title="Code">💻</a></td>
<td align="center"><a href="https://matt.martz.codes"><img src="https://avatars.githubusercontent.com/u/978362?v=4?s=100" width="100px;" alt="Matt Martz"/><br /><sub><b>Matt Martz</b></sub></a><br /><a href="https://github.com/boyney123/eventcatalog/commits?author=martzcodes" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/michelgrootjans"><img src="https://avatars.githubusercontent.com/u/345770?v=4?s=100" width="100px;" alt="Michel Grootjans"/><br /><sub><b>Michel Grootjans</b></sub></a><br /><a href="https://github.com/boyney123/eventcatalog/commits?author=michelgrootjans" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/arturoabruzzini"><img src="https://avatars.githubusercontent.com/u/17528406?v=4?s=100" width="100px;" alt="Arturo Abruzzini"/><br /><sub><b>Arturo Abruzzini</b></sub></a><br /><a href="https://github.com/boyney123/eventcatalog/commits?author=arturoabruzzini" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"canary:bumpVersion": "yarn lerna version `yarn --silent canary:version` --exact --no-push --yes",
"canary:publish": "yarn lerna publish from-package --dist-tag canary --yes --no-verify-access",
"postinstall": "yarn lock:update && yarn build:packages",
"lock:update": "npx yarn-deduplicate",
"lock:update": "npx --yes yarn-deduplicate",
"start": "lerna run start --stream",
"test": "cross-env PROJECT_DIR=/ jest",
"lint": "yarn lint:js",
Expand Down Expand Up @@ -58,5 +58,8 @@
"lerna-changelog": "^2.2.0",
"prettier": "^2.1.2",
"typescript": "^4.6.2"
},
"resolutions": {
"@types/react": "^17.0.36"
}
}
2 changes: 1 addition & 1 deletion packages/create-eventcatalog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@semantic-release/github": "^7.0.4",
"@semantic-release/npm": "^7.0.6",
"@semantic-release/release-notes-generator": "^9.0.1",
"@types/async-retry": "1.4.2",
"@types/async-retry": "1.3.0",
"@types/cross-spawn": "^6.0.2",
"@types/node": "^12.6.8",
"@types/prompts": "2.0.1",
Expand Down
6 changes: 6 additions & 0 deletions packages/eventcatalog-plugin-generator-asyncapi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @eventcatalog/plugin-doc-generator-asyncapi

## 0.3.2

### Patch Changes

- [`c407f03`](https://github.com/boyney123/eventcatalog/commit/c407f03fc7695a5fabc23d147c078180ea576a56) [#335](https://github.com/boyney123/eventcatalog/pull/335) Thanks [@boyney123](https://github.com/boyney123)! - fix: asyncapi now supports services that are both producer and consumers

## 0.3.1

### Patch Changes
Expand Down
4 changes: 3 additions & 1 deletion packages/eventcatalog-plugin-generator-asyncapi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eventcatalog/plugin-doc-generator-asyncapi",
"version": "0.3.1",
"version": "0.3.2",
"description": "Documentation generator for EventCatalog using AsyncAPI",
"main": "lib/index.js",
"scripts": {
Expand All @@ -25,6 +25,7 @@
"fs-extra": "^10.0.0",
"js-yaml": "^4.1.0",
"json2md": "^1.12.0",
"lodash.merge": "^4.6.2",
"yamljs": "^0.3.0"
},
"engines": {
Expand All @@ -34,6 +35,7 @@
"@eventcatalog/types": "0.4.0",
"@types/fs-extra": "^9.0.13",
"@types/json2md": "^1.5.1",
"@types/lodash.merge": "^4.6.7",
"@types/yamljs": "^0.2.31"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
asyncapi: 2.4.0
info:
title: ResultsDataService
version: 1.0.0
description: Results API
servers:
rabbitmq:
url: localhost
protocol: amqp
defaultContentType: application/json
channels:
deliveries/deliveryevent:
subscribe:
operationId: NotifyDeliveryCreated
summary: Inform when delivery is created.
message:
$ref: '#/components/messages/deliveryEvent'
delivery-event:
publish:
operationId: DeliveryCreatedConsumer
summary: Updates deliverymapfeatures using Delivery event
message:
payload:
$ref: '#/components/schemas/deliveryEvent'
components:
schemas:
deliveryEvent:
id: deliveryEvent
type: object
additionalProperties: false
properties:
eventType:
type: string
stampTime:
type: string
format: date-time
messages:
deliveryEvent:
payload:
$ref: '#/components/schemas/deliveryEvent'
name: deliveryEvent
Original file line number Diff line number Diff line change
Expand Up @@ -470,5 +470,47 @@ describe('eventcatalog-plugin-generator-asyncapi', () => {
});
});
});

describe('asyncapi service that is both producer and consumer', () => {
it('writes the event with the same producer and consumer', async () => {
const options: AsyncAPIPluginOptions = {
pathToSpec: [path.join(__dirname, './assets/producer-and-consumer.yml')],
};

await plugin(pluginContext, options);

// just wait for files to be there in time.
await new Promise((r) => setTimeout(r, 200));

const { getEventFromCatalog, getServiceFromCatalog } = utils({ catalogDirectory: process.env.PROJECT_DIR });

const { raw: eventFile } = getEventFromCatalog('deliveryEvent');

const { raw: serviceFile } = getServiceFromCatalog('ResultsDataService');

expect(eventFile).toMatchMarkdown(`
---
name: deliveryEvent
summary: null
version: 1.0.0
producers:
- ResultsDataService
consumers:
- ResultsDataService
externalLinks: []
badges: []
---
<Mermaid />
<Schema />
`);

expect(serviceFile).toMatchMarkdown(`
---
name: ResultsDataService
summary: 'Results API'
---
<Mermaid /> `);
});
});
});
});
26 changes: 24 additions & 2 deletions packages/eventcatalog-plugin-generator-asyncapi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { parse, AsyncAPIDocument } from '@asyncapi/parser';
import fs from 'fs-extra';
import path from 'path';
import utils from '@eventcatalog/utils';
import merge from 'lodash.merge';

import type { AsyncAPIPluginOptions } from './types';

Expand All @@ -16,7 +17,8 @@ const getAllEventsFromAsyncDoc = (doc: AsyncAPIDocument, options: AsyncAPIPlugin
const { externalAsyncAPIUrl } = options;

const channels = doc.channels();
return Object.keys(channels).reduce((data: any, channelName) => {

const allMessages = Object.keys(channels).reduce((data: any, channelName) => {
const service = doc.info().title();

const channel = channels[channelName];
Expand All @@ -25,7 +27,13 @@ const getAllEventsFromAsyncDoc = (doc: AsyncAPIDocument, options: AsyncAPIPlugin
const messages = channel[operation]().messages();

const eventsFromMessages = messages.map((message) => {
const messageName = message.name() || message.extension('x-parser-message-name');
let messageName = message.name() || message.extension('x-parser-message-name');

// If no name can be found from the message, and AsyncAPI defaults to "anonymous" value, try get the name from the payload itself
if (messageName.includes('anonymous-')) {
messageName = message.payload().uid() || messageName;
}

const schema = message.originalPayload();
const externalLink = {
label: `View event in AsyncAPI`,
Expand All @@ -46,6 +54,20 @@ const getAllEventsFromAsyncDoc = (doc: AsyncAPIDocument, options: AsyncAPIPlugin

return data.concat(eventsFromMessages);
}, []);

// the same service can be the producer and consumer of events, check and merge any matchs.
const uniqueMessages = allMessages.reduce((acc: any, message: any) => {
const messageAlreadyDefined = acc.findIndex((m: any) => m.name === message.name);

if (messageAlreadyDefined > -1) {
acc[messageAlreadyDefined] = merge(acc[messageAlreadyDefined], message);
} else {
acc.push(message);
}
return acc;
}, []);

return uniqueMessages;
};

const parseAsyncAPIFile = async (pathToFile: string, options: AsyncAPIPluginOptions, copyFrontMatter: boolean) => {
Expand Down
6 changes: 6 additions & 0 deletions packages/eventcatalog-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @eventcatalog/utils

## 0.2.1

### Patch Changes

- [`0964905`](https://github.com/boyney123/eventcatalog/commit/09649058338902b4a6216697f14df1cdad6aed00) - chore: allow writeEventToCatalog to write to previous versions of an event directly

## 0.2.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/eventcatalog-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eventcatalog/utils",
"version": "0.2.0",
"version": "0.2.1",
"description": "Util functions for EventCatalog",
"main": "lib/index.js",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: OrderCreated
version: 0.0.1
version: 0.0.2
summary: |
Event represents when an order has been complete. (Delivered and finished)
producers:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: OrderCreated
version: 0.0.1
summary: |
Event represents when an order has been complete. (Delivered and finished)
producers:
- Orders Service
consumers:
- Data Lake
owners:
- dboyne
- mSmith
---

# Testing
Loading

0 comments on commit fd61485

Please sign in to comment.