@@ -34,61 +34,59 @@ function assertStringArray(value: unknown, fieldName: string): string[] {
3434 * Load and parse a filter configuration YAML file.
3535 * Returns undefined if file doesn't exist.
3636 */
37+ /**
38+ * Mapping from FilterConfig field to its legacy alias (the old *Names key).
39+ * Both the Toolkit-style key and the legacy alias are accepted during parsing.
40+ */
41+ const FILTER_KEY_ALIASES : Record < keyof FilterConfig , string > = {
42+ apis : 'apiNames' ,
43+ backends : 'backendNames' ,
44+ products : 'productNames' ,
45+ namedValues : 'namedValueNames' ,
46+ loggers : 'loggerNames' ,
47+ diagnostics : 'diagnosticNames' ,
48+ tags : 'tagNames' ,
49+ policyFragments : 'policyFragmentNames' ,
50+ gateways : 'gatewayNames' ,
51+ versionSets : 'versionSetNames' ,
52+ groups : 'groupNames' ,
53+ subscriptions : 'subscriptionNames' ,
54+ schemas : 'schemaNames' ,
55+ policyRestrictions : 'policyRestrictionNames' ,
56+ documentations : 'documentationNames' ,
57+ workspaces : 'workspaceNames' ,
58+ } ;
59+
3760export async function loadFilterConfig ( filePath : string ) : Promise < FilterConfig | undefined > {
3861 try {
3962 const content = await fs . readFile ( filePath , 'utf-8' ) ;
4063 const parsed = ( yaml . load ( content ) ?? { } ) as Record < string , unknown > ;
4164
42- // Validate structure — each field must be an array of strings
65+ // Validate structure — each field must be an array of strings.
66+ // Accept both Toolkit-style keys (e.g. "apis") and legacy aliases (e.g. "apiNames").
4367 const config : FilterConfig = { } ;
4468
45- if ( parsed . apis !== undefined ) {
46- config . apis = assertStringArray ( parsed . apis , 'apis' ) ;
47- }
48- if ( parsed . backends !== undefined ) {
49- config . backends = assertStringArray ( parsed . backends , 'backends' ) ;
50- }
51- if ( parsed . products !== undefined ) {
52- config . products = assertStringArray ( parsed . products , 'products' ) ;
53- }
54- if ( parsed . namedValues !== undefined ) {
55- config . namedValues = assertStringArray ( parsed . namedValues , 'namedValues' ) ;
56- }
57- if ( parsed . loggers !== undefined ) {
58- config . loggers = assertStringArray ( parsed . loggers , 'loggers' ) ;
59- }
60- if ( parsed . diagnostics !== undefined ) {
61- config . diagnostics = assertStringArray ( parsed . diagnostics , 'diagnostics' ) ;
62- }
63- if ( parsed . tags !== undefined ) {
64- config . tags = assertStringArray ( parsed . tags , 'tags' ) ;
65- }
66- if ( parsed . policyFragments !== undefined ) {
67- config . policyFragments = assertStringArray ( parsed . policyFragments , 'policyFragments' ) ;
68- }
69- if ( parsed . gateways !== undefined ) {
70- config . gateways = assertStringArray ( parsed . gateways , 'gateways' ) ;
71- }
72- if ( parsed . versionSets !== undefined ) {
73- config . versionSets = assertStringArray ( parsed . versionSets , 'versionSets' ) ;
74- }
75- if ( parsed . groups !== undefined ) {
76- config . groups = assertStringArray ( parsed . groups , 'groups' ) ;
77- }
78- if ( parsed . subscriptions !== undefined ) {
79- config . subscriptions = assertStringArray ( parsed . subscriptions , 'subscriptions' ) ;
80- }
81- if ( parsed . schemas !== undefined ) {
82- config . schemas = assertStringArray ( parsed . schemas , 'schemas' ) ;
83- }
84- if ( parsed . policyRestrictions !== undefined ) {
85- config . policyRestrictions = assertStringArray ( parsed . policyRestrictions , 'policyRestrictions' ) ;
86- }
87- if ( parsed . documentations !== undefined ) {
88- config . documentations = assertStringArray ( parsed . documentations , 'documentations' ) ;
89- }
90- if ( parsed . workspaces !== undefined ) {
91- config . workspaces = assertStringArray ( parsed . workspaces , 'workspaces' ) ;
69+ for ( const [ field , legacyAlias ] of Object . entries ( FILTER_KEY_ALIASES ) ) {
70+ const key = field as keyof FilterConfig ;
71+ const toolkitValue = parsed [ field ] ;
72+ const legacyValue = parsed [ legacyAlias ] ;
73+
74+ if ( toolkitValue !== undefined && legacyValue !== undefined ) {
75+ throw new Error (
76+ `Filter config contains both '${ field } ' and '${ legacyAlias } '. ` +
77+ `Use '${ field } ' (the APIOps Toolkit format).`
78+ ) ;
79+ }
80+
81+ if ( toolkitValue !== undefined ) {
82+ config [ key ] = assertStringArray ( toolkitValue , field ) ;
83+ } else if ( legacyValue !== undefined ) {
84+ logger . warn (
85+ `Filter key '${ legacyAlias } ' is deprecated; use '${ field } ' instead ` +
86+ `(APIOps Toolkit format).`
87+ ) ;
88+ config [ key ] = assertStringArray ( legacyValue , legacyAlias ) ;
89+ }
9290 }
9391
9492 logger . debug ( `Loaded filter config from ${ filePath } ` ) ;
0 commit comments