@@ -522,31 +522,80 @@ private static void enrichDescriptor(FunctionDescriptor desc) {
522522 desc .getId (), desc .getResource (), desc .getOperation ()
523523 ));
524524 desc .setOperationId (desc .getId ());
525- desc .setInputSchema (inputSchemaFor (desc .getResource (), desc .getOperation ()));
525+ String [] schemas = SCHEMAS .get (desc .getId ());
526+ if (schemas != null ) {
527+ desc .setInputSchema (schemas [0 ]);
528+ desc .setOutputSchema (schemas [1 ]);
529+ return ;
530+ }
531+ desc .setInputSchema ("{\" type\" :\" object\" ,\" properties\" :{}}" );
526532 desc .setOutputSchema ("{\" type\" :\" object\" ,\" properties\" :{\" status\" :{\" type\" :\" string\" },\" action\" :{\" type\" :\" string\" }}}" );
527533 }
528534
529- private static String inputSchemaFor (String resource , String operation ) {
530- String idKey = "inventory" .equals (resource ) ? "playerId" : resource + "_id" ;
531- return switch (operation ) {
532- case "create" -> String .format (
533- "{\" type\" :\" object\" ,\" properties\" :{\" %s\" :{\" type\" :\" string\" },\" data\" :{\" type\" :\" object\" }}}" ,
534- idKey
535- );
536- case "update" -> String .format (
537- "{\" type\" :\" object\" ,\" properties\" :{\" %s\" :{\" type\" :\" string\" },\" patch\" :{\" type\" :\" object\" }},\" required\" :[\" %s\" ]}" ,
538- idKey , idKey
539- );
540- case "delete" -> String .format (
541- "{\" type\" :\" object\" ,\" properties\" :{\" %s\" :{\" type\" :\" string\" }},\" required\" :[\" %s\" ]}" ,
542- idKey , idKey
543- );
544- default -> String .format (
545- "{\" type\" :\" object\" ,\" properties\" :{\" %s\" :{\" type\" :\" string\" }}}" ,
546- idKey
547- );
548- };
549- }
535+ // Schemas describe the handlers' real wire contract with camelCase JSON
536+ // keys. snake_case is only allowed inside databases, never on the wire.
537+ private static final String OBJ = "{\" type\" :\" object\" }" ;
538+ private static final String STR = "{\" type\" :\" string\" }" ;
539+ private static final String INT = "{\" type\" :\" integer\" }" ;
540+ private static final String PLAYER_FIELDS = "{\" id\" :\" + STR + \" ,\" name\" :\" + STR + \" ,\" level\" :\" + INT + \" ,\" vip\" :\" + INT + \" ,\" gold\" :\" + INT + \" ,\" status\" :\" + STR + \" ,\" server\" :\" + STR + \" ,\" profile\" :\" \" + OBJ + " \" }";
541+
542+ private static final Map <String , String []> SCHEMAS = Map .ofEntries (
543+ Map .entry ("player.create" , new String []{
544+ "{\" type\" :\" object\" ,\" properties\" :" + PLAYER_FIELDS + "}" ,
545+ "{\" type\" :\" object\" ,\" properties\" :{\" player\" :" + OBJ + "}}" }),
546+ Map .entry ("player.get" , new String []{
547+ "{\" type\" :\" object\" ,\" properties\" :{\" id\" :" + STR + "},\" required\" :[\" id\" ]}" ,
548+ "{\" type\" :\" object\" ,\" properties\" :{\" player\" :" + OBJ + "}}" }),
549+ Map .entry ("player.update" , new String []{
550+ "{\" type\" :\" object\" ,\" properties\" :" + PLAYER_FIELDS + ",\" required\" :[\" id\" ]}" ,
551+ "{\" type\" :\" object\" ,\" properties\" :{\" player\" :" + OBJ + "}}" }),
552+ Map .entry ("player.delete" , new String []{
553+ "{\" type\" :\" object\" ,\" properties\" :{\" id\" :" + STR + "},\" required\" :[\" id\" ]}" ,
554+ "{\" type\" :\" object\" ,\" properties\" :{\" playerId\" :" + STR + "}}" }),
555+ Map .entry ("player.list" , new String []{
556+ "{\" type\" :\" object\" ,\" properties\" :{\" page\" :" + INT + ",\" pageSize\" :" + INT + "}}" ,
557+ "{\" type\" :\" object\" ,\" properties\" :{\" items\" :{\" type\" :\" array\" ,\" items\" :" + OBJ + "},\" total\" :" + INT + "}}" }),
558+ Map .entry ("order.create" , new String []{
559+ "{\" type\" :\" object\" ,\" properties\" :{\" id\" :" + STR + ",\" playerId\" :" + STR + ",\" productId\" :" + STR + ",\" amount\" :" + INT + ",\" currency\" :" + STR + ",\" status\" :" + STR + ",\" channel\" :" + STR + ",\" attributes\" :" + OBJ + "}}" ,
560+ "{\" type\" :\" object\" ,\" properties\" :{\" order\" :" + OBJ + "}}" }),
561+ Map .entry ("order.get" , new String []{
562+ "{\" type\" :\" object\" ,\" properties\" :{\" id\" :" + STR + "},\" required\" :[\" id\" ]}" ,
563+ "{\" type\" :\" object\" ,\" properties\" :{\" order\" :" + OBJ + "}}" }),
564+ Map .entry ("order.update" , new String []{
565+ "{\" type\" :\" object\" ,\" properties\" :{\" id\" :" + STR + ",\" status\" :" + STR + ",\" channel\" :" + STR + ",\" amount\" :" + INT + ",\" attributes\" :" + OBJ + "},\" required\" :[\" id\" ]}" ,
566+ "{\" type\" :\" object\" ,\" properties\" :{\" order\" :" + OBJ + "}}" }),
567+ Map .entry ("order.delete" , new String []{
568+ "{\" type\" :\" object\" ,\" properties\" :{\" id\" :" + STR + "},\" required\" :[\" id\" ]}" ,
569+ "{\" type\" :\" object\" ,\" properties\" :{\" orderId\" :" + STR + "}}" }),
570+ Map .entry ("order.list" , new String []{
571+ "{\" type\" :\" object\" ,\" properties\" :{\" playerId\" :" + STR + ",\" page\" :" + INT + ",\" pageSize\" :" + INT + "}}" ,
572+ "{\" type\" :\" object\" ,\" properties\" :{\" items\" :{\" type\" :\" array\" ,\" items\" :" + OBJ + "},\" total\" :" + INT + "}}" }),
573+ Map .entry ("leaderboard.list" , new String []{
574+ "{\" type\" :\" object\" ,\" properties\" :{\" page\" :" + INT + ",\" pageSize\" :" + INT + "}}" ,
575+ "{\" type\" :\" object\" ,\" properties\" :{\" items\" :{\" type\" :\" array\" ,\" items\" :" + OBJ + "},\" total\" :" + INT + "}}" }),
576+ Map .entry ("leaderboard.upsert" , new String []{
577+ "{\" type\" :\" object\" ,\" properties\" :{\" playerId\" :" + STR + ",\" score\" :" + INT + "},\" required\" :[\" playerId\" ]}" ,
578+ "{\" type\" :\" object\" ,\" properties\" :{\" entry\" :" + OBJ + "}}" }),
579+ Map .entry ("leaderboard.reset" , new String []{"{\" type\" :\" object\" ,\" properties\" :{}}" , "{\" type\" :\" object\" ,\" properties\" :{}}" }),
580+ Map .entry ("inventory.list" , new String []{
581+ "{\" type\" :\" object\" ,\" properties\" :{\" playerId\" :" + STR + "},\" required\" :[\" playerId\" ]}" ,
582+ "{\" type\" :\" object\" ,\" properties\" :{\" items\" :{\" type\" :\" array\" ,\" items\" :" + OBJ + "}}}" }),
583+ Map .entry ("inventory.grant" , new String []{
584+ "{\" type\" :\" object\" ,\" properties\" :{\" playerId\" :" + STR + ",\" templateId\" :" + STR + ",\" quantity\" :" + INT + "},\" required\" :[\" playerId\" ,\" templateId\" ]}" ,
585+ "{\" type\" :\" object\" ,\" properties\" :{\" item\" :" + OBJ + "}}" }),
586+ Map .entry ("inventory.consume" , new String []{
587+ "{\" type\" :\" object\" ,\" properties\" :{\" playerId\" :" + STR + ",\" templateId\" :" + STR + ",\" quantity\" :" + INT + "},\" required\" :[\" playerId\" ,\" templateId\" ]}" ,
588+ "{\" type\" :\" object\" ,\" properties\" :{\" item\" :" + OBJ + "}}" }),
589+ Map .entry ("mail.send" , new String []{
590+ "{\" type\" :\" object\" ,\" properties\" :{\" playerId\" :" + STR + ",\" title\" :" + STR + ",\" content\" :" + STR + ",\" reward\" :" + OBJ + ",\" expireAt\" :" + STR + "},\" required\" :[\" playerId\" ]}" ,
591+ "{\" type\" :\" object\" ,\" properties\" :{\" mail\" :" + OBJ + "}}" }),
592+ Map .entry ("mail.list" , new String []{
593+ "{\" type\" :\" object\" ,\" properties\" :{\" playerId\" :" + STR + "},\" required\" :[\" playerId\" ]}" ,
594+ "{\" type\" :\" object\" ,\" properties\" :{\" items\" :{\" type\" :\" array\" ,\" items\" :" + OBJ + "},\" total\" :" + INT + "}}" }),
595+ Map .entry ("mail.claim" , new String []{
596+ "{\" type\" :\" object\" ,\" properties\" :{\" playerId\" :" + STR + ",\" mailId\" :" + STR + "},\" required\" :[\" playerId\" ,\" mailId\" ]}" ,
597+ "{\" type\" :\" object\" ,\" properties\" :{\" mail\" :" + OBJ + "}}" })
598+ );
550599
551600 // ==================== Main ====================
552601
0 commit comments