Skip to content

Commit 26c42cf

Browse files
openapi3: record block end on Origin.Key (EndLine/EndColumn) (getkin#1207)
1 parent 6b0df72 commit 26c42cf

5 files changed

Lines changed: 179 additions & 102 deletions

File tree

.github/docs/openapi3.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,13 @@ type Location struct {
13731373
Line int `json:"line,omitempty" yaml:"line,omitempty"`
13741374
Column int `json:"column,omitempty" yaml:"column,omitempty"`
13751375
Name string `json:"name,omitempty" yaml:"name,omitempty"`
1376+
1377+
// EndLine and EndColumn mark the end of the block this location heads (set
1378+
// only on Origin.Key). For an operation or schema this spans the whole
1379+
// block, so a consumer can extract the entire element from its source.
1380+
// Both are zero when the underlying YAML carried no end information.
1381+
EndLine int `json:"endLine,omitempty" yaml:"endLine,omitempty"`
1382+
EndColumn int `json:"endColumn,omitempty" yaml:"endColumn,omitempty"`
13761383
}
13771384
Location is a struct that contains the location of a field.
13781385

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ go 1.25
55
require (
66
github.com/go-openapi/jsonpointer v0.22.5
77
github.com/gorilla/mux v1.8.0
8-
github.com/oasdiff/yaml v0.1.0
9-
github.com/oasdiff/yaml3 v0.0.13
8+
github.com/oasdiff/yaml v0.1.1
9+
github.com/oasdiff/yaml3 v0.0.14
1010
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2
1111
github.com/stretchr/testify v1.9.0
1212
)

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
1717
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
1818
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1919
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
20-
github.com/oasdiff/yaml v0.1.0 h1:0bqZjfKc/8S9urj4JuwepX41WX9EoA6ifhU3SV06cXg=
21-
github.com/oasdiff/yaml v0.1.0/go.mod h1:kOlRmMdL2X3vucLCEQO5u61SU22RysnfXvcttrZA1O0=
22-
github.com/oasdiff/yaml3 v0.0.13 h1:06svmvOHOVBqF81+sY2EUScvUI/iS/vl2VIeUUxZQwg=
23-
github.com/oasdiff/yaml3 v0.0.13/go.mod h1:y5+oSEHCPT/DGrS++Wc/479ERge0zTFxaF8PbGKcg2o=
20+
github.com/oasdiff/yaml v0.1.1 h1:6nHx+pn9gBRM6YpBlFZFQGCCd1nuvqOBtTD3KKTgGxY=
21+
github.com/oasdiff/yaml v0.1.1/go.mod h1:EYJNoyktvWMJ0Hmhx+6qTaqMOsalUaRGT8Sj1hNcegU=
22+
github.com/oasdiff/yaml3 v0.0.14 h1:aLJee3hxBK2H5wdXd9iPcIXb93Nty1Ge0pT171eHtkw=
23+
github.com/oasdiff/yaml3 v0.0.14/go.mod h1:csto2xfDjYccdUn/yw/bPjj/cYTdp6HtFA0J4TWG+gg=
2424
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2525
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2626
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 h1:KRzFb2m7YtdldCEkzs6KqmJw4nqEVZGK7IN2kJkjTuQ=

openapi3/origin.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ type Location struct {
2727
Line int `json:"line,omitempty" yaml:"line,omitempty"`
2828
Column int `json:"column,omitempty" yaml:"column,omitempty"`
2929
Name string `json:"name,omitempty" yaml:"name,omitempty"`
30+
31+
// EndLine and EndColumn mark the end of the block this location heads (set
32+
// only on Origin.Key). For an operation or schema this spans the whole
33+
// block, so a consumer can extract the entire element from its source.
34+
// Both are zero when the underlying YAML carried no end information.
35+
EndLine int `json:"endLine,omitempty" yaml:"endLine,omitempty"`
36+
EndColumn int `json:"endColumn,omitempty" yaml:"endColumn,omitempty"`
3037
}
3138

3239
// originFromSeq parses the compact []any sequence produced by yaml3's addOrigin.
@@ -99,6 +106,17 @@ func originFromSeq(s []any) *Origin {
99106
o.Sequences[sname] = locs
100107
}
101108
}
109+
110+
// Trailing block end (yaml3 >= the end-position release): end_delta, end_col.
111+
// Reconstruct the end of the whole block on Origin.Key so a consumer can
112+
// extract the entire element. Older origin sequences omit these, leaving
113+
// EndLine/EndColumn zero. end_col == 0 means no end information was recorded.
114+
if o.Key != nil && idx+1 < len(s) {
115+
if endCol := toInt(s[idx+1]); endCol > 0 {
116+
o.Key.EndLine = keyLine + toInt(s[idx])
117+
o.Key.EndColumn = endCol
118+
}
119+
}
102120
return o
103121
}
104122

0 commit comments

Comments
 (0)