11import type { JSONSchema7 as JSONSchema } from 'json-schema' ;
2- import find from 'lodash/find' ;
32import type { CreateFilter , KeysOfUnion } from './utils' ;
43import { getDataTypeSchema , regexEscape } from './utils' ;
54import type { FormData } from '../components/Filters/SchemaSieve' ;
@@ -8,23 +7,43 @@ import {
87 createModelFilter ,
98} from '../components/Filters/SchemaSieve' ;
109import { isJSONSchema , getRefSchema } from '../schemaOps' ;
11- import findKey from 'lodash/findKey' ;
1210import pick from 'lodash/pick' ;
1311import mapValues from 'lodash/mapValues' ;
1412
13+ const findValueByDescription = (
14+ obj : object | undefined ,
15+ description : string ,
16+ ) => {
17+ return Object . values ( obj ?? { } ) . find (
18+ ( property ) =>
19+ typeof property === 'object' &&
20+ 'description' in property &&
21+ property . description === description ,
22+ ) as JSONSchema | undefined ;
23+ } ;
24+
25+ const findKeyByDescription = ( obj : object | undefined , description : string ) => {
26+ return Object . entries ( obj ?? { } ) . find (
27+ ( [ , value ] ) =>
28+ typeof value === 'object' &&
29+ 'description' in value &&
30+ value . description === description ,
31+ ) ?. [ 0 ] ;
32+ } ;
33+
1534const getKeyLabel = ( schema : JSONSchema ) => {
16- const s = find ( schema . properties , { description : 'key' } ) as JSONSchema ;
35+ const s = findValueByDescription ( schema . properties , 'key' ) ;
1736 return s ?. title ?? 'key' ;
1837} ;
1938
2039const getValueLabel = ( schema : JSONSchema ) => {
21- const s = find ( schema . properties , { description : 'value' } ) as JSONSchema ;
40+ const s = findValueByDescription ( schema . properties , 'value' ) ;
2241 return s ?. title ?? 'value' ;
2342} ;
2443
2544export const isKeyValueObj = ( schema : JSONSchema ) =>
26- ! ! find ( schema . properties , { description : 'key' } ) ||
27- ! ! find ( schema . properties , { description : 'value' } ) ;
45+ ! ! findValueByDescription ( schema . properties , 'key' ) ||
46+ ! ! findValueByDescription ( schema . properties , 'value' ) ;
2847
2948export const operators = ( s : JSONSchema ) => {
3049 return {
@@ -94,7 +113,7 @@ const getValueForOperation = (
94113 ? 'value'
95114 : null ;
96115 const schemaProperty = schemaField
97- ? findKey ( schema . properties , { description : schemaField } )
116+ ? findKeyByDescription ( schema . properties , schemaField )
98117 : null ;
99118
100119 // Return the appropriate value format based on the operation type
@@ -191,8 +210,8 @@ export const createFilter: CreateFilter<OperatorSlug> = (
191210
192211 // TODO: this case does not cover complex objects for FULL_TEXT_SLUG
193212 if ( operator === FULL_TEXT_SLUG && schema . properties ) {
194- const schemaKey = findKey ( schema . properties , { description : 'key' } ) ;
195- const schemaValue = findKey ( schema . properties , { description : 'value' } ) ;
213+ const schemaKey = findKeyByDescription ( schema . properties , 'key' ) ;
214+ const schemaValue = findKeyByDescription ( schema . properties , 'value' ) ;
196215 const properties = [ schemaKey , schemaValue ]
197216 . map ( ( key ) =>
198217 key
0 commit comments