Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 922af4a

Browse files
committed
fix(oas2): skip $ref validation errors in oneOf
The main one of branch will be a more accurate error message
1 parent 19909e6 commit 922af4a

File tree

2 files changed

+10
-164
lines changed

2 files changed

+10
-164
lines changed

packages/openapi2-parser/lib/parser.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,16 @@ class Parser {
15671567
return;
15681568
}
15691569

1570+
if (error.code === 'ONE_OF_MISSING'
1571+
&& error.inner.length === 2
1572+
&& error.inner[1].code === 'OBJECT_MISSING_REQUIRED_PROPERTY'
1573+
&& error.inner[1].params.length === 1 && error.inner[1].params[0] === '$ref') {
1574+
// one of validation error containing $ref, let's skip the ref part of message
1575+
// and only show the "main" branch. The $ref is rarely important aspect of validation.
1576+
this.createValidationAnnotation(error.inner[0]);
1577+
return;
1578+
}
1579+
15701580
if (error.code === 'ENUM_MISMATCH') {
15711581
const enumerations = error[ZSchema.schemaSymbol].enum.map((item, index, items) => {
15721582
if (index === items.length - 1) {

packages/openapi2-parser/test/fixtures/schema-error-parameter.json

Lines changed: 0 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -83,88 +83,6 @@
8383
},
8484
"content": "Data does not match any schemas from 'oneOf'"
8585
},
86-
{
87-
"element": "annotation",
88-
"meta": {
89-
"classes": {
90-
"element": "array",
91-
"content": [
92-
{
93-
"element": "string",
94-
"content": "error"
95-
}
96-
]
97-
},
98-
"links": {
99-
"element": "array",
100-
"content": [
101-
{
102-
"element": "link",
103-
"attributes": {
104-
"relation": {
105-
"element": "string",
106-
"content": "origin"
107-
},
108-
"href": {
109-
"element": "string",
110-
"content": "http://docs.apiary.io/validations/swagger#swagger-validation"
111-
}
112-
}
113-
}
114-
]
115-
}
116-
},
117-
"attributes": {
118-
"code": {
119-
"element": "number",
120-
"content": 4
121-
},
122-
"sourceMap": {
123-
"element": "array",
124-
"content": [
125-
{
126-
"element": "sourceMap",
127-
"content": [
128-
{
129-
"element": "array",
130-
"content": [
131-
{
132-
"element": "number",
133-
"attributes": {
134-
"line": {
135-
"element": "number",
136-
"content": 7
137-
},
138-
"column": {
139-
"element": "number",
140-
"content": 8
141-
}
142-
},
143-
"content": 97
144-
},
145-
{
146-
"element": "number",
147-
"attributes": {
148-
"line": {
149-
"element": "number",
150-
"content": 9
151-
},
152-
"column": {
153-
"element": "number",
154-
"content": 0
155-
}
156-
},
157-
"content": 28
158-
}
159-
]
160-
}
161-
]
162-
}
163-
]
164-
}
165-
},
166-
"content": "Data does not match any schemas from 'oneOf'"
167-
},
16886
{
16987
"element": "annotation",
17088
"meta": {
@@ -242,88 +160,6 @@
242160
}
243161
},
244162
"content": "Missing required property: type"
245-
},
246-
{
247-
"element": "annotation",
248-
"meta": {
249-
"classes": {
250-
"element": "array",
251-
"content": [
252-
{
253-
"element": "string",
254-
"content": "error"
255-
}
256-
]
257-
},
258-
"links": {
259-
"element": "array",
260-
"content": [
261-
{
262-
"element": "link",
263-
"attributes": {
264-
"relation": {
265-
"element": "string",
266-
"content": "origin"
267-
},
268-
"href": {
269-
"element": "string",
270-
"content": "http://docs.apiary.io/validations/swagger#swagger-validation"
271-
}
272-
}
273-
}
274-
]
275-
}
276-
},
277-
"attributes": {
278-
"code": {
279-
"element": "number",
280-
"content": 4
281-
},
282-
"sourceMap": {
283-
"element": "array",
284-
"content": [
285-
{
286-
"element": "sourceMap",
287-
"content": [
288-
{
289-
"element": "array",
290-
"content": [
291-
{
292-
"element": "number",
293-
"attributes": {
294-
"line": {
295-
"element": "number",
296-
"content": 7
297-
},
298-
"column": {
299-
"element": "number",
300-
"content": 8
301-
}
302-
},
303-
"content": 97
304-
},
305-
{
306-
"element": "number",
307-
"attributes": {
308-
"line": {
309-
"element": "number",
310-
"content": 9
311-
},
312-
"column": {
313-
"element": "number",
314-
"content": 0
315-
}
316-
},
317-
"content": 28
318-
}
319-
]
320-
}
321-
]
322-
}
323-
]
324-
}
325-
},
326-
"content": "Missing required property: $ref"
327163
}
328164
]
329165
}

0 commit comments

Comments
 (0)