fix: Uniqueness of group ID when special characters exist in tags

This commit is contained in:
xiang.gao 2025-02-25 10:50:18 +08:00
parent 1243095926
commit da57b154bb
2 changed files with 6 additions and 1 deletions

View File

@ -148,6 +148,7 @@
"mark.js": "^8.11.1",
"marked": "^4.3.0",
"mobx-react": "^9.1.1",
"nanoid": "^5.1.2",
"openapi-sampler": "^1.5.0",
"path-browserify": "^1.0.1",
"perfect-scrollbar": "^1.5.5",

View File

@ -1,4 +1,5 @@
import { action, observable, makeObservable } from 'mobx';
import { nanoid } from 'nanoid';
import type { OpenAPIExternalDocumentation, OpenAPITag } from '../../types';
import { safeSlugify } from '../../utils';
@ -37,8 +38,11 @@ export class GroupModel implements IMenuItem {
) {
makeObservable(this);
const safeGroupName = safeSlugify(tagOrGroup.name);
const groupId = [type, '/', safeGroupName, `_${nanoid(8)}`].join('');
// markdown headings already have ids calculated as they are needed for heading anchors
this.id = (tagOrGroup as MarkdownHeading).id || type + '/' + safeSlugify(tagOrGroup.name);
this.id = (tagOrGroup as MarkdownHeading).id || groupId;
this.type = type;
this.name = tagOrGroup['x-displayName'] || tagOrGroup.name;
this.level = (tagOrGroup as MarkdownHeading).level || 1;