@@ -198,6 +198,7 @@ export function checkSparseKernelOpenApi({ openapiText, daemonSource, clientSour
198198 const clientPaths = collectClientPaths ( clientSource ) ;
199199 const clientRouteKeys = collectClientRouteKeys ( clientSource ) ;
200200 const openapiRouteKeys = collectOpenApiRouteKeys ( paths ) ;
201+ checkClientSchemaMappingUniqueness ( errors , CLIENT_SCHEMA_MAPPINGS ) ;
201202
202203 pushSetDiff (
203204 errors ,
@@ -574,6 +575,48 @@ function checkClientSchemaProperties(errors, clientSource, schemas) {
574575 }
575576}
576577
578+ function checkClientSchemaMappingUniqueness ( errors , mappings ) {
579+ const { duplicateClientTypes, duplicateSchemaNames } =
580+ collectClientSchemaMappingProblems ( mappings ) ;
581+ if ( duplicateClientTypes . length > 0 ) {
582+ errors . push (
583+ formatList (
584+ "SparseKernel client parity mappings duplicate client types" ,
585+ duplicateClientTypes ,
586+ ) ,
587+ ) ;
588+ }
589+ if ( duplicateSchemaNames . length > 0 ) {
590+ errors . push (
591+ formatList (
592+ "SparseKernel client parity mappings duplicate schema names" ,
593+ duplicateSchemaNames ,
594+ ) ,
595+ ) ;
596+ }
597+ }
598+
599+ export function collectClientSchemaMappingProblems ( mappings ) {
600+ return {
601+ duplicateClientTypes : collectDuplicateMappingValues ( mappings , "clientType" ) ,
602+ duplicateSchemaNames : collectDuplicateMappingValues ( mappings , "schemaName" ) ,
603+ } ;
604+ }
605+
606+ function collectDuplicateMappingValues ( mappings , key ) {
607+ const firstSeen = new Set ( ) ;
608+ const duplicates = new Set ( ) ;
609+ for ( const item of mappings ) {
610+ const value = item [ key ] ;
611+ if ( firstSeen . has ( value ) ) {
612+ duplicates . add ( value ) ;
613+ continue ;
614+ }
615+ firstSeen . add ( value ) ;
616+ }
617+ return [ ...duplicates ] . toSorted ( compareStrings ) ;
618+ }
619+
577620function schemaPropertiesFor ( schemas , schemaName ) {
578621 const properties = schemas ?. [ schemaName ] ?. properties ;
579622 if ( ! properties || typeof properties !== "object" || Array . isArray ( properties ) ) {
0 commit comments