@@ -14,27 +14,25 @@ export default (input, { propertyNameToLookFor, cloudProviderEnumValues }, { pat
1414 const propertyObject = resolveObject ( oas , path ) ;
1515 const fieldType = path [ path . length - 2 ] ;
1616
17- if ( fieldType === 'parameters' && ! propertyObject . schema ) {
18- return ;
19- }
20-
2117 if ( hasException ( propertyObject , RULE_NAME ) ) {
2218 collectException ( propertyObject , RULE_NAME , path ) ;
2319 return ;
2420 }
2521
26- const errors = checkViolationsAndReturnErrors (
22+ const result = checkViolationsAndReturnErrors (
2723 input ,
2824 propertyObject ,
2925 path ,
3026 propertyNameToLookFor ,
3127 fieldType ,
3228 cloudProviderEnumValues
3329 ) ;
34- if ( errors . length !== 0 ) {
35- return collectAndReturnViolation ( path , RULE_NAME , errors ) ;
30+ if ( result . errors . length !== 0 ) {
31+ return collectAndReturnViolation ( path , RULE_NAME , result . errors ) ;
32+ }
33+ if ( result . isCloudProviderField ) {
34+ collectAdoption ( path , RULE_NAME ) ;
3635 }
37- collectAdoption ( path , RULE_NAME ) ;
3836} ;
3937
4038function checkViolationsAndReturnErrors (
@@ -46,38 +44,49 @@ function checkViolationsAndReturnErrors(
4644 cloudProviderEnumValues
4745) {
4846 try {
47+ const result = {
48+ errors : [ ] ,
49+ isCloudProviderField : false ,
50+ } ;
51+
4952 if ( fieldType === 'properties' ) {
50- if ( propertyName === propertyNameToLookFor && propertyObject . default !== undefined ) {
51- return [
52- {
53+ if ( propertyName === propertyNameToLookFor ) {
54+ result . isCloudProviderField = true ;
55+ if ( propertyObject . default !== undefined ) {
56+ result . errors . push ( {
5357 path,
5458 message : ERROR_MESSAGE ,
55- } ,
56- ] ;
59+ } ) ;
60+ return result ;
61+ }
5762 }
5863
5964 if ( Array . isArray ( propertyObject . enum ) && propertyObject . enum . length > 0 ) {
6065 const enumValues = propertyObject . enum ;
6166 const hasCloudProviderEnumValue = cloudProviderEnumValues . every ( ( cloudProviderValue ) =>
6267 enumValues . includes ( cloudProviderValue )
6368 ) ;
64- if ( hasCloudProviderEnumValue && propertyObject . default !== undefined ) {
65- return [
66- {
69+ if ( hasCloudProviderEnumValue ) {
70+ result . isCloudProviderField = true ;
71+ if ( propertyObject . default !== undefined ) {
72+ result . errors . push ( {
6773 path,
6874 message : ERROR_MESSAGE ,
69- } ,
70- ] ;
75+ } ) ;
76+ return result ;
77+ }
7178 }
7279 }
7380 } else if ( fieldType === 'parameters' ) {
74- if ( propertyObject . name === propertyNameToLookFor && propertyObject . schema . default !== undefined ) {
75- return [
76- {
81+ if ( propertyObject . name === propertyNameToLookFor ) {
82+ result . isCloudProviderField = true ;
83+ if ( propertyObject . schema . default !== undefined ) {
84+ result . errors . push ( {
7785 path,
7886 message : ERROR_MESSAGE ,
79- } ,
80- ] ;
87+ } ) ;
88+ return result ;
89+ }
8190 }
8291
8392 if ( Array . isArray ( propertyObject . schema . enum ) && propertyObject . schema . enum . length > 0 ) {
@@ -86,18 +95,20 @@ function checkViolationsAndReturnErrors(
8695 enumValues . includes ( cloudProviderValue )
8796 ) ;
8897
89- if ( hasCloudProviderEnumValue && propertyObject . schema . default !== undefined ) {
90- return [
91- {
98+ if ( hasCloudProviderEnumValue ) {
99+ result . isCloudProviderField = true ;
100+ if ( propertyObject . schema . default !== undefined ) {
101+ result . errors . push ( {
92102 path,
93103 message : ERROR_MESSAGE ,
94- } ,
95- ] ;
104+ } ) ;
105+ return result ;
106+ }
96107 }
97108 }
98109 }
99110
100- return [ ] ;
111+ return result ;
101112 } catch ( e ) {
102113 handleInternalError ( RULE_NAME , path , e ) ;
103114 }
0 commit comments