File tree Expand file tree Collapse file tree 5 files changed +53
-2
lines changed Expand file tree Collapse file tree 5 files changed +53
-2
lines changed Original file line number Diff line number Diff line change @@ -1454,3 +1454,20 @@ components:
1454
1454
_ , errs := doc .BuildV3Model ()
1455
1455
assert .Len (t , errs , 0 )
1456
1456
}
1457
+
1458
+ func TestDocument_Issue418 (t * testing.T ) {
1459
+
1460
+ spec , _ := os .ReadFile ("test_specs/nested_files/openapi-issue-418.yaml" )
1461
+
1462
+ doc , err := NewDocumentWithConfiguration (spec , & datamodel.DocumentConfiguration {
1463
+ AllowFileReferences : true ,
1464
+ BasePath : "test_specs/nested_files" ,
1465
+ SpecFilePath : "test_specs/nested_files/openapi-issue-418.yaml" ,
1466
+ })
1467
+ if err != nil {
1468
+ panic (err )
1469
+ }
1470
+ m , errs := doc .BuildV3Model ()
1471
+ assert .Len (t , errs , 0 )
1472
+ assert .Len (t , m .Model .Index .GetResolver ().GetResolvingErrors (), 0 )
1473
+ }
Original file line number Diff line number Diff line change @@ -143,7 +143,12 @@ func (index *SpecIndex) SearchIndexForReferenceByReferenceWithContext(ctx contex
143
143
abp := index .GetSpecAbsolutePath ()
144
144
145
145
if b == sfn && roloLookup == abp {
146
- return nil , index , ctx
146
+ // if the reference is the same as the spec file name, we should look through the index for the component
147
+ var r * Reference
148
+ if len (uri ) == 2 {
149
+ r = index .FindComponentInRoot (fmt .Sprintf ("#/%s" , uri [1 ]))
150
+ }
151
+ return r , index , ctx
147
152
}
148
153
rFile , err := index .rolodex .Open (roloLookup )
149
154
if err != nil {
@@ -169,7 +174,7 @@ func (index *SpecIndex) SearchIndexForReferenceByReferenceWithContext(ctx contex
169
174
}
170
175
}
171
176
172
- if strings .HasSuffix (refParsed , n ) {
177
+ if strings .HasSuffix (n , refParsed ) {
173
178
node , _ := rFile .GetContentAsYAMLNode ()
174
179
if node != nil {
175
180
r := & Reference {
Original file line number Diff line number Diff line change
1
+ # https://github.com/pb33f/libopenapi/issues/418
2
+ get :
3
+ parameters :
4
+ - name : id
5
+ in : path
6
+ description : user id
7
+ required : true
8
+ schema :
9
+ type : string
10
+ responses :
11
+ ' 200 ' :
12
+ $ref : ' ../openapi-issue-418.yaml#/components/responses/successResponse'
Original file line number Diff line number Diff line change
1
+ openapi : ' 3.0.3'
2
+ paths :
3
+ ' /foo ' :
4
+ $ref : ' ./components/foo.yaml'
5
+ components :
6
+ responses :
7
+ successResponse :
8
+ description : " success"
9
+ content :
10
+ application/json :
11
+ schema :
12
+ properties :
13
+ message :
14
+ type : string
Original file line number Diff line number Diff line change @@ -50,6 +50,9 @@ type SchemaChanges struct {
50
50
}
51
51
52
52
func (s * SchemaChanges ) GetPropertyChanges () []* Change {
53
+ if s == nil {
54
+ return nil
55
+ }
53
56
changes := s .Changes
54
57
if s .SchemaPropertyChanges != nil {
55
58
for n := range s .SchemaPropertyChanges {
You can’t perform that action at this time.
0 commit comments