Posting a review comment / draft note fails with a 400 Bad Request from the GitLab API:
{"message": {"position": ["must be a valid json schema"]}}
Environment
gitlab.nvim commit: 80edb27 / f05aee3 (latest)
- GitLab version:
17.7.1 (self-hosted)
Root Cause
In commit 80edb27 (fix: get correct location data for comments efficiently), OldLine and NewLine were added to opt.LineRange.Start and opt.LineRange.End in cmd/app/comment_helpers.go:
opt.LineRange = &gitlab.LineRangeOptions{
Start: &gitlab.LinePositionOptions{
Type: &positionData.LineRange.Start.Type,
LineCode: &startFilenameSha,
OldLine: &startOldLine,
NewLine: &startNewLine,
},
...
}
This causes the Go backend to serialize:
"line_range": {
"start": {
"line_code": "...",
"type": "new",
"old_line": 0,
"new_line": 36
}
}
GitLab's REST API validates position against app/validators/json_schemas/position.json. In GitLab $\le$ 17.7, line_range.start and line_range.end enforce "additionalProperties": false and only permit "line_code" and "type". As a result, including old_line or new_line causes schema validation to fail.
Fix
In cmd/app/comment_helpers.go, keep OldLine and NewLine nil / omitted from LinePositionOptions:
--- a/cmd/app/comment_helpers.go
+++ b/cmd/app/comment_helpers.go
@@ -83,14 +83,10 @@ func buildCommentPosition(commentWithPositionData RequestWithPosition) *gitlab.P
opt.LineRange = &gitlab.LineRangeOptions{
Start: &gitlab.LinePositionOptions{
Type: &positionData.LineRange.Start.Type,
LineCode: &startFilenameSha,
- OldLine: &startOldLine,
- NewLine: &startNewLine,
},
End: &gitlab.LinePositionOptions{
Type: &positionData.LineRange.End.Type,
LineCode: &endFilenameSha,
- OldLine: &endOldLine,
- NewLine: &endNewLine,
},
}
Posting a review comment / draft note fails with a
400 Bad Requestfrom the GitLab API:{"message": {"position": ["must be a valid json schema"]}}Environment
gitlab.nvimcommit:80edb27/f05aee3(latest)17.7.1(self-hosted)Root Cause
In commit
80edb27(fix: get correct location data for comments efficiently),OldLineandNewLinewere added toopt.LineRange.Startandopt.LineRange.Endincmd/app/comment_helpers.go:This causes the Go backend to serialize:
GitLab's REST API validates$\le$ 17.7,
positionagainstapp/validators/json_schemas/position.json. In GitLabline_range.startandline_range.endenforce"additionalProperties": falseand only permit"line_code"and"type". As a result, includingold_lineornew_linecauses schema validation to fail.Fix
In
cmd/app/comment_helpers.go, keepOldLineandNewLinenil / omitted fromLinePositionOptions: