Skip to content

Commit

Permalink
Merge pull request #5098 from mermaid-js/4578-generic-class-in-namespace
Browse files Browse the repository at this point in the history
Fix issue with generic class not rendering
  • Loading branch information
sidharthv96 authored Dec 4, 2023
2 parents f81e4d4 + 761fa27 commit 886405b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/mermaid/src/diagrams/class/classDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,13 @@ const getNamespaces = function (): NamespaceMap {
* @public
*/
export const addClassesToNamespace = function (id: string, classNames: string[]) {
if (namespaces[id] !== undefined) {
classNames.map((className) => {
classes[className].parent = id;
namespaces[id].classes[className] = classes[className];
});
if (namespaces[id] === undefined) {
return;
}
for (const name of classNames) {
const { className } = splitClassNameAndType(name);
classes[className].parent = id;
namespaces[id].classes[className] = classes[className];
}
};

Expand Down
13 changes: 13 additions & 0 deletions packages/mermaid/src/diagrams/class/classDiagram.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,19 @@ foo()
`;
parser.parse(str);
});

it('should handle namespace with generic types', () => {
parser.parse(`classDiagram
namespace space {
class Square~Shape~{
int id
List~int~ position
setPoints(List~int~ points)
getPoints() List~int~
}
}`);
});
});
});

Expand Down

0 comments on commit 886405b

Please sign in to comment.