@@ -22,40 +22,106 @@ import (
2222
2323const (
2424 xgenSoaMigration = "x-xgen-soa-migration"
25+ allowDocsDiff = "allowDocsDiff"
2526)
2627
27- // allMethodsHaveExtension checks if all the operations in the base pat have the given extension name.
28+ // allOperationsHaveExtension checks if all the operations in the base pat have the given extension name.
2829func allOperationsHaveExtension (basePath * openapi3.PathItem , basePathName , extensionName string ) bool {
2930 if basePath .Get != nil {
30- if basePath . Get . Extensions == nil || basePath .Get . Extensions [ extensionName ] == nil {
31+ if result := getOperationExtensionWithName ( basePath .Get , extensionName ); result == nil {
3132 return false
3233 }
3334 }
3435
3536 if basePath .Put != nil {
36- if basePath . Put . Extensions == nil || basePath .Put . Extensions [ extensionName ] == nil {
37+ if result := getOperationExtensionWithName ( basePath .Put , extensionName ); result == nil {
3738 return false
3839 }
3940 }
4041
4142 if basePath .Post != nil {
42- if basePath . Post . Extensions == nil || basePath .Post . Extensions [ extensionName ] == nil {
43+ if result := getOperationExtensionWithName ( basePath .Post , extensionName ); result == nil {
4344 return false
4445 }
4546 }
4647
4748 if basePath .Patch != nil {
48- if basePath . Patch . Extensions == nil || basePath .Patch . Extensions [ extensionName ] == nil {
49+ if result := getOperationExtensionWithName ( basePath .Patch , extensionName ); result == nil {
4950 return false
5051 }
5152 }
5253
5354 if basePath .Delete != nil {
54- if basePath . Delete . Extensions == nil || basePath .Delete . Extensions [ extensionName ] == nil {
55+ if result := getOperationExtensionWithName ( basePath .Delete , extensionName ); result == nil {
5556 return false
5657 }
5758 }
5859
5960 log .Println ("Detected x-xgen-soa-migration annotation in all operations for path: " , basePathName )
6061 return true
6162}
63+
64+ func getOperationExtensionWithName (operation * openapi3.Operation , extensionName string ) interface {} {
65+ if operation .Extensions == nil || operation .Extensions [extensionName ] == nil {
66+ log .Printf ("Operation %s does not have extension %q" , operation .OperationID , extensionName )
67+ return nil
68+ }
69+
70+ return operation .Extensions [extensionName ]
71+ }
72+
73+ func allOperationsAllowDocsDiff (basePath * openapi3.PathItem , basePathName string ) bool {
74+ if basePath .Get != nil {
75+ prop := getOperationExtensionProperty (basePath .Get , xgenSoaMigration , allowDocsDiff )
76+ if prop != "true" {
77+ return false
78+ }
79+ }
80+
81+ if basePath .Put != nil {
82+ prop := getOperationExtensionProperty (basePath .Put , xgenSoaMigration , allowDocsDiff )
83+ if prop != "true" {
84+ return false
85+ }
86+ }
87+
88+ if basePath .Post != nil {
89+ prop := getOperationExtensionProperty (basePath .Post , xgenSoaMigration , allowDocsDiff )
90+ if prop != "true" {
91+ return false
92+ }
93+ }
94+
95+ if basePath .Patch != nil {
96+ prop := getOperationExtensionProperty (basePath .Patch , xgenSoaMigration , allowDocsDiff )
97+ if prop != "true" {
98+ return false
99+ }
100+ }
101+
102+ if basePath .Delete != nil {
103+ prop := getOperationExtensionProperty (basePath .Delete , xgenSoaMigration , allowDocsDiff )
104+ if prop != "true" {
105+ return false
106+ }
107+ }
108+
109+ return true
110+ }
111+
112+ func getOperationExtensionProperty (operation * openapi3.Operation , extensionName , extensionProperty string ) string {
113+ if operation .Extensions == nil || operation .Extensions [extensionName ] == nil {
114+ return ""
115+ }
116+
117+ extension := operation .Extensions [extensionName ]
118+ if extension == nil {
119+ return ""
120+ }
121+
122+ value , ok := extension .(map [string ]interface {})[extensionProperty ].(string )
123+ if ok {
124+ return value
125+ }
126+ return ""
127+ }
0 commit comments