Skip to content

Commit f312422

Browse files
feat: change function structure to validate schema
1 parent 4cea6f2 commit f312422

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

packages/core/src/rules/common/tags-duplicated-names.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,29 @@ import type { UserContext } from '../../walk.js';
88
export const TagsDuplicatedNames: Oas3Rule | Oas2Rule | Async2Rule | Async3Rule = ({
99
ignoreCase = false,
1010
}) => {
11+
const tagNames = new Set<string>();
12+
1113
return {
12-
Root(
13-
root: Oas2Definition | Oas3Definition | Oas3_1Definition,
14-
{ report, location }: UserContext
15-
) {
16-
if (!root.tags) return;
17-
const tagNames = new Set<string>();
18-
for (const [i, tag] of root.tags.entries()) {
14+
Tag: {
15+
leave(
16+
tag: { name: string },
17+
ctx: UserContext,
18+
root: Oas2Definition | Oas3Definition | Oas3_1Definition
19+
) {
20+
if (!root.tags) return;
21+
1922
const tagName = getTagName(tag, ignoreCase);
23+
const index = root.tags.findIndex((t) => t === tag);
24+
2025
if (tagNames.has(tagName)) {
21-
report({
26+
ctx.report({
2227
message: `Duplicate tag name found: '${tag.name}'`,
23-
location: location.child(['tags', i]),
28+
location: ctx.location.child(['tags', index]),
2429
});
2530
} else {
2631
tagNames.add(tagName);
2732
}
28-
}
33+
},
2934
},
3035
};
3136
};

packages/core/src/rules/oas3/__tests__/struct/struct.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,6 @@ describe('Oas3 Structural visitor basic', () => {
4848

4949
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
5050
[
51-
{
52-
"location": [
53-
{
54-
"pointer": "#/tags/1",
55-
"reportOnKey": false,
56-
"source": "foobar.yaml",
57-
},
58-
],
59-
"message": "Duplicate tag name found: 'undefined'",
60-
"ruleId": "tags-duplicated-names",
61-
"severity": "error",
62-
"suggest": [],
63-
},
6451
{
6552
"from": undefined,
6653
"location": [

0 commit comments

Comments
 (0)