File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed
src/plugins/validate-semantic/validators/2and3
test/plugins/validate-semantic/2and3 Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -12,10 +12,10 @@ export const validate2And3RefHasNoSiblings = () => system => {
1212 return nodes . reduce ( ( acc , node ) => {
1313 const unresolvedValue = get ( specJson , node . parent . path ) || { }
1414 const unresolvedKeys = Object . keys ( unresolvedValue ) || [ ]
15-
15+ const isPathItem = node . parent . key === "paths" && node . path . length === 2
1616
1717 unresolvedKeys . forEach ( k => {
18- if ( k !== "$ref" && unresolvedKeys . indexOf ( "$ref" ) > - 1 ) {
18+ if ( ! isPathItem && k !== "$ref" && unresolvedKeys . indexOf ( "$ref" ) > - 1 ) {
1919 acc . push ( {
2020 message : `Sibling values are not allowed alongside $refs` ,
2121 path : [ ...node . path . slice ( 0 , - 1 ) , k ] ,
Original file line number Diff line number Diff line change @@ -97,6 +97,45 @@ describe("validation plugin - semantic - 2and3 refs", function() {
9797 return expectNoErrorsOrWarnings ( spec )
9898 } )
9999
100+ it ( "should return no warnings when a path item $ref has siblings in OpenAPI 3" , ( ) => {
101+ const spec = {
102+ openapi : "3.0.0" ,
103+ paths : {
104+ $ref : "#/components/schemas/abc" ,
105+ "/CoolPath" : {
106+ get : {
107+ $ref : "#/components/schemas/abc"
108+ }
109+ }
110+ } ,
111+ components : {
112+ schemas : {
113+ abc : { }
114+ }
115+ }
116+ }
117+
118+ return expectNoErrorsOrWarnings ( spec )
119+ } )
120+ it ( "should return no warnings when a path item $ref has siblings in Swagger 2" , ( ) => {
121+ const spec = {
122+ swagger : "2.0" ,
123+ paths : {
124+ $ref : "#/definitions/abc" ,
125+ "/CoolPath" : {
126+ get : {
127+ $ref : "#/definitions/abc"
128+ }
129+ }
130+ } ,
131+ definitions : {
132+ abc : { }
133+ }
134+ }
135+
136+ return expectNoErrorsOrWarnings ( spec )
137+ } )
138+
100139 } )
101140 describe ( "Unused definitions" , ( ) => {
102141 it ( "should return a warning when a definition is declared but not used in OpenAPI 3" , ( ) => {
You can’t perform that action at this time.
0 commit comments