Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion nodejs/test/python-codegen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe("python session event codegen", () => {
'action = from_union([from_none, lambda x: parse_enum(SessionSyntheticDataAction, x)], obj.get("action", "store"))'
);
expect(code).toContain(
'summary = from_union([from_none, lambda x: from_str(x)], obj.get("summary", ""))'
'summary = from_union([from_none, from_str], obj.get("summary", ""))'
);
expect(code).toContain("uri: str");
expect(code).toContain("pattern: str");
Expand All @@ -83,6 +83,53 @@ describe("python session event codegen", () => {
expect(code).toContain("count: int");
});

it("collapses redundant callable wrapper lambdas", () => {
const schema: JSONSchema7 = {
definitions: {
SessionEvent: {
anyOf: [
{
type: "object",
required: ["type", "data"],
properties: {
type: { const: "session.synthetic" },
data: {
type: "object",
properties: {
summary: { type: "string" },
tags: {
type: "array",
items: { type: "string" },
},
context: {
type: "object",
properties: {
gitRoot: { type: "string" },
},
},
},
},
},
},
],
},
},
};

const code = generatePythonSessionEventsCode(schema);

expect(code).toContain('summary = from_union([from_none, from_str], obj.get("summary"))');
expect(code).toContain(
'tags = from_union([from_none, lambda x: from_list(from_str, x)], obj.get("tags"))'
);
expect(code).toContain(
'context = from_union([from_none, SessionSyntheticDataContext.from_dict], obj.get("context"))'
);
expect(code).not.toContain("lambda x: from_str(x)");
expect(code).not.toContain("lambda x: SessionSyntheticDataContext.from_dict(x)");
expect(code).not.toContain("from_list(lambda x: from_str(x), x)");
});

it("preserves key shortened nested type names", () => {
const schema: JSONSchema7 = {
definitions: {
Expand Down
Loading
Loading