This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support plantUML classDiagram syntax (#13)
* feat: support plantUML syntax * chore: update readme * refactor: change if to switch statement * docs: extend jsdoc with available options * refactor: switch statement * chore: extend jsodc
- Loading branch information
1 parent
a81009b
commit 0abf06e
Showing
3 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Generates plantUML class diagram from default output syntax | ||
* | ||
* @param {Object} metrics Relations between AsyncAPI docs in default output syntax | ||
* @returns {String} class diagram following plantUML syntax | ||
*/ | ||
function getPlantUMLDiagram(metrics) { | ||
let i=1; | ||
let plantUMLSyntax = ''; | ||
metrics.forEach((relations,server) => { | ||
const [url, protocol] = server.split(','); | ||
plantUMLSyntax+= `\nclass server${i} { \n url: ${url} \n protocol: ${protocol}\n}`; | ||
|
||
relations.forEach((operations, channel) => { | ||
operations.sub.forEach((metadata,subscriber) => { | ||
const service = subscriber.replace(/\s/g,''); | ||
plantUMLSyntax+=`\n${service} --|> server${i}:${channel}`; | ||
}); | ||
|
||
operations.pub.forEach((metadata,publisher) => { | ||
const service = publisher.replace(/\s/g,''); | ||
plantUMLSyntax+=`\nserver${i} --|> ${service}:${channel}`; | ||
}); | ||
}); | ||
i++; | ||
}); | ||
return `@startuml\ntitle Classes - Class Diagram\n${plantUMLSyntax}\n@enduml`; | ||
} | ||
|
||
module.exports = getPlantUMLDiagram; |