Skip to content

Commit 83a01b7

Browse files
committed
Tuned line in schema validation.
Signed-off-by: Dave Shanley <[email protected]>
1 parent bd126cb commit 83a01b7

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

schema_validation/validate_schema.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,17 @@ func validateSchema(schema *base.Schema, payload []byte, decodedObject interface
143143
}
144144
// if we have a location within the schema, add it to the error
145145
if located != nil {
146+
line := located.Line
147+
// if the located node is a map or an array, then the actual human interpretable
148+
// line on which the violation occurred is the line of the key, not the value.
149+
if located.Kind == yaml.MappingNode || located.Kind == yaml.SequenceNode {
150+
if line > 0 {
151+
line--
152+
}
153+
}
154+
146155
// location of the violation within the rendered schema.
147-
violation.Line = located.Line
156+
violation.Line = line
148157
violation.Column = located.Column
149158
}
150159
schemaValidationErrors = append(schemaValidationErrors, violation)

schema_validation/validate_schema_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ paths:
486486

487487
// create a schema validator
488488
v := NewSchemaValidator()
489-
489+
490490
sch := m.Model.Paths.PathItems["/burgers/createBurger"].Post.RequestBody.Content["application/json"].Schema
491491

492492
// validate!

0 commit comments

Comments
 (0)