@@ -1406,42 +1406,78 @@ const createActionAttempts = (
14061406 return [ ]
14071407 }
14081408
1409- const processedActionTypes = new Set < string > ( )
1409+ const schemasByActionType = new Map < string , OpenapiSchema [ ] > ( )
14101410
1411- return actionAttemptSchema . oneOf
1412- . map ( ( schema ) => {
1413- if (
1414- typeof schema !== 'object' ||
1415- schema . properties ?. [ 'action_type' ] ?. enum ?. [ 0 ] == null
1416- ) {
1417- return null
1411+ for ( const schema of actionAttemptSchema . oneOf ) {
1412+ if (
1413+ typeof schema !== 'object' ||
1414+ schema . properties ?. [ 'action_type' ] ?. enum ?. [ 0 ] == null
1415+ ) {
1416+ continue
1417+ }
1418+
1419+ const actionType = schema . properties [ 'action_type' ] . enum [ 0 ]
1420+ const currentSchemas = schemasByActionType . get ( actionType )
1421+
1422+ if ( currentSchemas == null ) {
1423+ schemasByActionType . set ( actionType , [ schema ] )
1424+ } else {
1425+ currentSchemas . push ( schema )
1426+ }
1427+ }
1428+
1429+ return Array . from ( schemasByActionType . entries ( ) ) . map (
1430+ ( [ actionType , schemas ] ) => {
1431+ const mergedProperties : Record < string , OpenapiSchema > = { }
1432+
1433+ const allPropertyKeys = new Set < string > ( )
1434+ for ( const schema of schemas ) {
1435+ if ( schema . properties != null ) {
1436+ Object . keys ( schema . properties ) . forEach ( ( key ) =>
1437+ allPropertyKeys . add ( key ) ,
1438+ )
1439+ }
14181440 }
14191441
1420- const actionType = schema . properties [ 'action_type' ] . enum [ 0 ]
1442+ for ( const propKey of allPropertyKeys ) {
1443+ const propDefinitions = schemas
1444+ . filter ( ( schema ) => schema . properties ?. [ propKey ] != null )
1445+ . map ( ( schema ) => schema . properties ?. [ propKey ] )
14211446
1422- if ( processedActionTypes . has ( actionType ) ) {
1423- return null
1447+ if ( propDefinitions . length === 0 ) continue
1448+
1449+ const nonNullableDefinition = propDefinitions . find ( ( prop ) => {
1450+ if ( prop == null ) return false
1451+
1452+ return ! (
1453+ 'nullable' in prop &&
1454+ prop . nullable === true &&
1455+ Object . keys ( prop ) . length <= 1
1456+ )
1457+ } )
1458+
1459+ mergedProperties [ propKey ] =
1460+ nonNullableDefinition ?? propDefinitions [ 0 ] ?? { }
14241461 }
1425- processedActionTypes . add ( actionType )
14261462
1427- const schemaWithStandardStatus : OpenapiSchema = {
1428- ...( actionAttemptSchema [ 'x-route-path' ] !== null && {
1463+ // Ensure standard status field
1464+ mergedProperties [ 'status' ] = {
1465+ ...mergedProperties [ 'status' ] ,
1466+ type : 'string' ,
1467+ enum : [ 'success' , 'pending' , 'error' ] ,
1468+ }
1469+
1470+ const schemaWithMergedProperties : OpenapiSchema = {
1471+ ...( actionAttemptSchema [ 'x-route-path' ] != null && {
14291472 'x-route-path' : actionAttemptSchema [ 'x-route-path' ] ,
14301473 } ) ,
1431- ...schema ,
1432- properties : {
1433- ...schema . properties ,
1434- status : {
1435- ...schema . properties [ 'status' ] ,
1436- type : 'string' ,
1437- enum : [ 'success' , 'pending' , 'error' ] ,
1438- } ,
1439- } ,
1474+ ...schemas [ 0 ] ,
1475+ properties : mergedProperties ,
14401476 }
14411477
14421478 const resource = createResource (
14431479 'action_attempt' ,
1444- schemaWithStandardStatus ,
1480+ schemaWithMergedProperties ,
14451481 routes ,
14461482 )
14471483
@@ -1450,6 +1486,6 @@ const createActionAttempts = (
14501486 resourceType : 'action_attempt' ,
14511487 actionAttemptType : actionType ,
14521488 }
1453- } )
1454- . filter ( ( attempt ) : attempt is ActionAttempt => attempt !== null )
1489+ } ,
1490+ )
14551491}
0 commit comments