Skip to content

Commit ee902e1

Browse files
committed
Add suppression propagation for circular references.
1 parent 5a71764 commit ee902e1

File tree

5 files changed

+144
-0
lines changed

5 files changed

+144
-0
lines changed

src/definitions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ export class DefinitionRegistry {
144144
for (const [key, value] of toSorted(Object.entries(itemCopy))) {
145145
matchCopy[key] = value;
146146
}
147+
this.client?.suppressions?.propagateSuppression(
148+
refResult,
149+
this.currentPath
150+
);
147151
return this.#expand(matchCopy, refResult.name);
148152
}
149153
} else {

test/files/suppressions3.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- path: definitions/Foo/properties/value/format
2+
reason: Because a really good reason.

test/files/suppressions3a.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"title": "(title)",
5+
"version": "0000-00-00",
6+
"x-typespec-generated": [
7+
{
8+
"emitter": "@azure-tools/typespec-autorest"
9+
}
10+
]
11+
},
12+
"schemes": ["https"],
13+
"produces": ["application/json"],
14+
"consumes": ["application/json"],
15+
"tags": [],
16+
"paths": {
17+
"/": {
18+
"put": {
19+
"operationId": "Create",
20+
"parameters": [
21+
{
22+
"name": "body",
23+
"in": "body",
24+
"required": true,
25+
"schema": {
26+
"$ref": "#/definitions/Foo"
27+
}
28+
}
29+
],
30+
"responses": {
31+
"200": {
32+
"description": "The request has succeeded.",
33+
"schema": {
34+
"$ref": "#/definitions/Foo"
35+
}
36+
}
37+
}
38+
}
39+
}
40+
},
41+
"definitions": {
42+
"Foo": {
43+
"type": "object",
44+
"properties": {
45+
"inner": {
46+
"$ref": "#/definitions/Foo"
47+
},
48+
"value": {
49+
"type": "integer",
50+
"format": "int16"
51+
}
52+
},
53+
"required": ["value"]
54+
}
55+
},
56+
"parameters": {}
57+
}

test/files/suppressions3b.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"title": "(title)",
5+
"version": "0000-00-00",
6+
"x-typespec-generated": [
7+
{
8+
"emitter": "@azure-tools/typespec-autorest"
9+
}
10+
]
11+
},
12+
"schemes": ["https"],
13+
"produces": ["application/json"],
14+
"consumes": ["application/json"],
15+
"tags": [],
16+
"paths": {
17+
"/": {
18+
"put": {
19+
"operationId": "Create",
20+
"parameters": [
21+
{
22+
"name": "body",
23+
"in": "body",
24+
"required": true,
25+
"schema": {
26+
"$ref": "#/definitions/Foo"
27+
}
28+
}
29+
],
30+
"responses": {
31+
"200": {
32+
"description": "The request has succeeded.",
33+
"schema": {
34+
"$ref": "#/definitions/Foo"
35+
}
36+
}
37+
}
38+
}
39+
}
40+
},
41+
"definitions": {
42+
"Foo": {
43+
"type": "object",
44+
"properties": {
45+
"inner": {
46+
"$ref": "#/definitions/Foo"
47+
},
48+
"value": {
49+
"type": "integer",
50+
"format": "int32"
51+
}
52+
},
53+
"required": ["value"]
54+
}
55+
},
56+
"parameters": {}
57+
}

test/rest-api-diff.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,27 @@ it("should sort arrays of strings for stable comparison", async () => {
334334
expect(client.diffResults?.noViolations.length).toBe(2);
335335
expect(client.diffResults?.assumedViolations.length).toBe(0);
336336
});
337+
338+
it("should propagate suppressions for circular references", async () => {
339+
const config: DiffClientConfig = {
340+
lhs: ["test/files/suppressions3a.json"],
341+
rhs: ["test/files/suppressions3b.json"],
342+
args: {
343+
suppressions: "test/files/suppressions3.yaml",
344+
},
345+
rules: getApplicableRules({}),
346+
};
347+
const client = await TestableDiffClient.create(config);
348+
client.parse();
349+
client.processDiff();
350+
client.buildOutput();
351+
const [lhsParser, rhsParser] = client.getParsers();
352+
expect(lhsParser.getUnresolvedReferences().length).toBe(0);
353+
expect(lhsParser.getUnreferencedTotal()).toBe(0);
354+
expect(rhsParser.getUnresolvedReferences().length).toBe(0);
355+
expect(rhsParser.getUnreferencedTotal()).toBe(0);
356+
expect(client.diffResults?.assumedViolations.length).toBe(0);
357+
expect(client.diffResults?.flaggedViolations.length).toBe(0);
358+
expect(client.diffResults?.suppressedViolations.length).toBe(2);
359+
expect(client.diffResults?.noViolations.length).toBe(1);
360+
});

0 commit comments

Comments
 (0)