@@ -74,7 +74,7 @@ describe("python session event codegen", () => {
7474 'action = from_union([from_none, lambda x: parse_enum(SessionSyntheticDataAction, x)], obj.get("action", "store"))'
7575 ) ;
7676 expect ( code ) . toContain (
77- 'summary = from_union([from_none, lambda x: from_str(x) ], obj.get("summary", ""))'
77+ 'summary = from_union([from_none, from_str], obj.get("summary", ""))'
7878 ) ;
7979 expect ( code ) . toContain ( "uri: str" ) ;
8080 expect ( code ) . toContain ( "pattern: str" ) ;
@@ -83,6 +83,53 @@ describe("python session event codegen", () => {
8383 expect ( code ) . toContain ( "count: int" ) ;
8484 } ) ;
8585
86+ it ( "collapses redundant callable wrapper lambdas" , ( ) => {
87+ const schema : JSONSchema7 = {
88+ definitions : {
89+ SessionEvent : {
90+ anyOf : [
91+ {
92+ type : "object" ,
93+ required : [ "type" , "data" ] ,
94+ properties : {
95+ type : { const : "session.synthetic" } ,
96+ data : {
97+ type : "object" ,
98+ properties : {
99+ summary : { type : "string" } ,
100+ tags : {
101+ type : "array" ,
102+ items : { type : "string" } ,
103+ } ,
104+ context : {
105+ type : "object" ,
106+ properties : {
107+ gitRoot : { type : "string" } ,
108+ } ,
109+ } ,
110+ } ,
111+ } ,
112+ } ,
113+ } ,
114+ ] ,
115+ } ,
116+ } ,
117+ } ;
118+
119+ const code = generatePythonSessionEventsCode ( schema ) ;
120+
121+ expect ( code ) . toContain ( 'summary = from_union([from_none, from_str], obj.get("summary"))' ) ;
122+ expect ( code ) . toContain (
123+ 'tags = from_union([from_none, lambda x: from_list(from_str, x)], obj.get("tags"))'
124+ ) ;
125+ expect ( code ) . toContain (
126+ 'context = from_union([from_none, SessionSyntheticDataContext.from_dict], obj.get("context"))'
127+ ) ;
128+ expect ( code ) . not . toContain ( "lambda x: from_str(x)" ) ;
129+ expect ( code ) . not . toContain ( "lambda x: SessionSyntheticDataContext.from_dict(x)" ) ;
130+ expect ( code ) . not . toContain ( "from_list(lambda x: from_str(x), x)" ) ;
131+ } ) ;
132+
86133 it ( "preserves key shortened nested type names" , ( ) => {
87134 const schema : JSONSchema7 = {
88135 definitions : {
0 commit comments