11// @ts -ignore
22import { createRule } from 'eslint-plugin-yml/lib/utils' ;
33
4- import { isPairWithKey , isScalar } from '../utils.js' ;
4+ import { isPairWithKey , isPairWithValue , isScalar } from '../utils.js' ;
55
66const ACLs = [
77 'search' ,
@@ -23,12 +23,13 @@ const ACLs = [
2323export const validACL = createRule ( 'validACL' , {
2424 meta : {
2525 docs : {
26- description : 'x-acl enum must contains valid Algolia ACLs' ,
26+ description : 'x-acl enum must be set and contain valid Algolia ACLs' ,
2727 categories : null ,
2828 extensionRule : false ,
2929 layout : false ,
3030 } ,
3131 messages : {
32+ missingACL : 'x-acl is missing' ,
3233 validString : 'is not a string' ,
3334 validACL : `{{entry}} is not a valid Algolia ACL, must be one of: ${ ACLs . join ( ', ' ) } .` ,
3435 validArray : 'is not an array of string' ,
@@ -43,6 +44,41 @@ export const validACL = createRule('validACL', {
4344
4445 return {
4546 YAMLPair ( node ) : void {
47+ const spec = context . getFilename ( ) . match ( / s p e c s \/ ( [ a - z - ] + ?) \/ / ) ?. [ 1 ] ;
48+ if ( ! spec ) {
49+ return ;
50+ }
51+ if ( spec === 'monitoring' ) {
52+ // monitoring uses a special API key and doesn't need ACLs
53+ return ;
54+ }
55+
56+ if ( spec === 'crawler' ) {
57+ // no clients are generated for the crawler API
58+ return ;
59+ }
60+
61+ // if we find then prop operationId, there must be x-acl on the same level
62+ if ( isPairWithKey ( node , 'operationId' ) ) {
63+ const hasACL = node . parent . pairs . some ( ( item : any ) => isPairWithKey ( item , 'x-acl' ) ) ;
64+
65+ // ignore custom helpers
66+ if ( isPairWithValue ( node , 'customGet' ) || isPairWithValue ( node , 'customPost' ) || isPairWithValue ( node , 'customPut' ) || isPairWithValue ( node , 'customDelete' ) ) {
67+ return ;
68+ }
69+
70+
71+ if ( ! hasACL ) {
72+ context . report ( {
73+ node : node as any ,
74+ messageId : 'missingACL' ,
75+ } ) ;
76+ }
77+
78+ return ;
79+ }
80+
81+ // check the validity of x-acl
4682 if ( ! isPairWithKey ( node , 'x-acl' ) ) {
4783 return ;
4884 }
0 commit comments