Skip to content

Commit a098d85

Browse files
authored
feat(resolver): collect errors in SchemaElement visitor hook (#2807)
This change is specific to OpenAPI 3.1.0 resolution strategy. Errors are now collected, instead of thrown and visitor traversal is not interrupted. Refs #2806
1 parent fba4bbc commit a098d85

File tree

16 files changed

+781
-318
lines changed

16 files changed

+781
-318
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import createError from '../../../../../../../specmap/lib/create-error.js';
2+
3+
// eslint-disable-next-line import/prefer-default-export
4+
export const SchemaRefError = createError('SchemaRefError', function cb(message, extra, oriError) {
5+
this.originalError = oriError;
6+
Object.assign(this, extra || {});
7+
});

src/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js

+176-153
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[
2+
{
3+
"openapi": "3.1.0",
4+
"components": {
5+
"schemas": {
6+
"User": {
7+
"type": "object",
8+
"properties": {
9+
"login": {
10+
"type": "string"
11+
},
12+
"password": {
13+
"type": "string"
14+
},
15+
"profile": {
16+
"$ref": "#user-profile"
17+
}
18+
}
19+
}
20+
}
21+
}
22+
}
23+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[
2+
{
3+
"openapi": "3.1.0",
4+
"components": {
5+
"schemas": {
6+
"User": {
7+
"$id": "./schemas/",
8+
"type": "object",
9+
"properties": {
10+
"login": {
11+
"type": "string"
12+
},
13+
"password": {
14+
"type": "string"
15+
},
16+
"profile": {
17+
"$id": "./nested/",
18+
"$ref": "./ex.json"
19+
}
20+
}
21+
}
22+
}
23+
}
24+
}
25+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[
2+
{
3+
"openapi": "3.1.0",
4+
"components": {
5+
"schemas": {
6+
"User": {
7+
"type": "object",
8+
"properties": {
9+
"login": {
10+
"type": "string"
11+
},
12+
"password": {
13+
"type": "string"
14+
},
15+
"profile": {
16+
"$ref": "./ex.json"
17+
}
18+
}
19+
}
20+
}
21+
}
22+
}
23+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[
2+
{
3+
"openapi": "3.1.0",
4+
"components": {
5+
"schemas": {
6+
"User": {
7+
"type": "object",
8+
"properties": {
9+
"login": {
10+
"type": "string"
11+
},
12+
"password": {
13+
"type": "string"
14+
},
15+
"profile": {
16+
"$ref": "urn:uuid:3"
17+
}
18+
}
19+
}
20+
}
21+
}
22+
}
23+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"openapi": "3.1.0",
4+
"components": {
5+
"schemas": {
6+
"User": {}
7+
}
8+
}
9+
}
10+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"openapi": "3.1.0",
4+
"components": {
5+
"schemas": {
6+
"User": {
7+
"$ref": "#/components/schemas/User"
8+
}
9+
}
10+
}
11+
}
12+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"openapi": "3.1.0",
4+
"components": {
5+
"schemas": {
6+
"User": {}
7+
}
8+
}
9+
}
10+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"openapi": "3.1.0",
4+
"components": {
5+
"schemas": {
6+
"User": {},
7+
"Indirection1": {},
8+
"Indirection2": {},
9+
"Indirection3": {}
10+
}
11+
}
12+
}
13+
]

test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/schema-object/__fixtures__/indirect-internal-circular/root.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"Indirection1": {
99
"$ref": "#/components/schemas/Indirection2"
1010
},
11-
"Indirection3": {
11+
"Indirection2": {
1212
"$ref": "#/components/schemas/Indirection3"
1313
},
14-
"Indirection4": {
14+
"Indirection3": {
1515
"$ref": "#/components/schemas/User"
1616
}
1717
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"openapi": "3.1.0",
4+
"components": {
5+
"schemas": {
6+
"User": {
7+
"type": "object"
8+
},
9+
"UserProfile": {
10+
"type": "object"
11+
}
12+
}
13+
}
14+
}
15+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"openapi": "3.1.0",
4+
"components": {
5+
"schemas": {
6+
"User": {
7+
"type": "object",
8+
"$ref": "#/components/schemas/invalid-pointer"
9+
}
10+
}
11+
}
12+
}
13+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"openapi": "3.1.0",
4+
"components": {
5+
"schemas": {
6+
"User": {
7+
"type": "object"
8+
}
9+
}
10+
}
11+
}
12+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"openapi": "3.1.0",
4+
"components": {
5+
"schemas": {
6+
"User": {
7+
"properties": {
8+
"profile": {
9+
"$ref": "#/components/schemas/UserProfile"
10+
}
11+
}
12+
}
13+
}
14+
}
15+
}
16+
]

0 commit comments

Comments
 (0)