Skip to content

Commit 69403c1

Browse files
authored
fix(core): pointer in overrides are applied too broadly (#2511)
1 parent 91bdc88 commit 69403c1

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

docs/guides/4d-overrides.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ JSON Pointers have a different syntax than JSON Paths used in the `given` compon
4343
In JSON Pointers, path components are prefixed with a `/` and then concatenated to form the pointer.
4444

4545
Since `/` has a special meaning in JSON pointer, it must be encoded as `~1` when it appears in a component, and `~` must be encoded as `~0`.
46+
JSON Pointer must be percent-encoded for use within a URI as specified by the [spec](https://datatracker.ietf.org/doc/html/rfc6901#section-6)
4647

4748
You can test JSON Pointer expressions in the [JSON Query online evaluator](https://www.jsonquerytool.com/) by choosing "JSONPointer" as the Transform.
49+
Bear in mind the tool above expects plain JSON Pointer, thus you need to decode any previously percent-encoded characters.
4850

4951
```yaml
5052
overrides:
5153
- files:
52-
- "legacy/**/*.oas.json#/paths/~1Pets~1{petId}/get/parameters/0"
54+
- "legacy/**/*.oas.json#/paths/~1Pets~1%7BpetId%7D/get/parameters/0"
5355
rules:
5456
some-inherited-rule: "off"
5557
```

packages/core/src/__tests__/linter.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,9 @@ responses:: !!foo
15711571
bar: {
15721572
type: 'number',
15731573
},
1574+
bars: {
1575+
type: 'number',
1576+
},
15741577
}),
15751578
Parsers.Json,
15761579
documentUri,
@@ -1583,6 +1586,11 @@ responses:: !!foo
15831586
path: ['bar', 'type'],
15841587
severity: DiagnosticSeverity.Hint,
15851588
}),
1589+
expect.objectContaining({
1590+
code: 'valid-type',
1591+
path: ['bars', 'type'],
1592+
severity: DiagnosticSeverity.Error,
1593+
}),
15861594
]);
15871595
});
15881596
});

packages/core/src/ruleset/rule.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ export class Rule implements IRule {
103103

104104
for (const relevantOverride of relevantOverrides) {
105105
for (const [overridePath, overrideSeverity] of relevantOverride.entries()) {
106-
if (overridePath.length >= closestPointer.length && pointer.startsWith(overridePath)) {
106+
if (
107+
overridePath.length >= closestPointer.length &&
108+
(pointer === overridePath || pointer.startsWith(`${overridePath}/`))
109+
) {
107110
closestPointer = overridePath;
108111
severity = overrideSeverity;
109112
}

0 commit comments

Comments
 (0)