Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/openapi2-parser/lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ class Parser {
annotation.attributes.set('sourceMap', [
new SourceMap([location]),
]);
} else {
// Some validation errors contain `in '/some/path'`,
// we can extract path to get source map
const matchesPath = message.match(/in '\/(.*?)'/);

if (matchesPath) {
const path = matchesPath[1].split('/');
this.createSourceMap(annotation, path, true);
}
}

return done(null, this.result);
Expand Down
87 changes: 87 additions & 0 deletions packages/openapi2-parser/test/fixtures/swagger-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"element": "parseResult",
"content": [
{
"element": "annotation",
"meta": {
"classes": {
"element": "array",
"content": [
{
"element": "string",
"content": "error"
}
]
},
"links": {
"element": "array",
"content": [
{
"element": "link",
"attributes": {
"relation": {
"element": "string",
"content": "origin"
},
"href": {
"element": "string",
"content": "http://docs.apiary.io/validations/swagger#swagger-validation"
}
}
}
]
}
},
"attributes": {
"code": {
"element": "number",
"content": 4
},
"sourceMap": {
"element": "array",
"content": [
{
"element": "sourceMap",
"content": [
{
"element": "array",
"content": [
{
"element": "number",
"attributes": {
"line": {
"element": "number",
"content": 6
},
"column": {
"element": "number",
"content": 2
}
},
"content": 98
},
{
"element": "number",
"attributes": {
"line": {
"element": "number",
"content": 9
},
"column": {
"element": "number",
"content": 0
}
},
"content": 43
}
]
}
]
}
]
}
},
"content": "Validation failed. Property 'foo' listed as required but does not exist in '/definitions/test'"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"element": "parseResult",
"content": [
{
"element": "annotation",
"meta": {
"classes": {
"element": "array",
"content": [
{
"element": "string",
"content": "error"
}
]
},
"links": {
"element": "array",
"content": [
{
"element": "link",
"attributes": {
"relation": {
"element": "string",
"content": "origin"
},
"href": {
"element": "string",
"content": "http://docs.apiary.io/validations/swagger#swagger-validation"
}
}
}
]
}
},
"attributes": {
"code": {
"element": "number",
"content": 4
},
"sourceMap": {
"element": "array",
"content": [
{
"element": "sourceMap",
"content": [
{
"element": "array",
"content": [
{
"element": "number",
"attributes": {
"line": {
"element": "number",
"content": 6
},
"column": {
"element": "number",
"content": 2
}
},
"content": 98
},
{
"element": "number",
"attributes": {
"line": {
"element": "number",
"content": 9
},
"column": {
"element": "number",
"content": 0
}
},
"content": 43
}
]
}
]
}
]
}
},
"content": "Validation failed. Property 'foo' listed as required but does not exist in '/definitions/test'"
}
]
}
9 changes: 9 additions & 0 deletions packages/openapi2-parser/test/fixtures/swagger-error.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
swagger: '2.0'
info:
title: Swagger Validation Errors
version: 1.0.0
paths: {}
definitions:
test:
type: object
required: [foo]