Skip to content

Commit 1ae6132

Browse files
authored
Fix formatter passing (#603)
1 parent 84fe190 commit 1ae6132

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/transform/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export function transformSchemaObj(node: any, options: Options): string {
116116
immutableTypes: options.immutableTypes,
117117
required: node.required,
118118
version: options.version,
119+
formatter: options.formatter,
119120
});
120121

121122
// if additional properties, add an intersection with a generic map type

tests/formatter.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,60 @@ export interface components {
3636
};
3737
}
3838
39+
export interface operations {}
40+
`);
41+
});
42+
43+
it("hasObject", () => {
44+
const schemaHasObject = {
45+
openapi: "3.0.1",
46+
components: {
47+
schemas: {
48+
calendar: {
49+
type: "object",
50+
properties: {
51+
dates: {
52+
type: "object",
53+
properties: {
54+
start: {
55+
type: "string",
56+
format: "date-time",
57+
},
58+
},
59+
},
60+
},
61+
},
62+
},
63+
},
64+
};
65+
66+
expect(
67+
openapiTS(schemaHasObject, {
68+
formatter(schemaObj) {
69+
if (schemaObj.format === "date-time") {
70+
return "Date";
71+
}
72+
return;
73+
},
74+
version: 3,
75+
})
76+
).toBe(`/**
77+
* This file was auto-generated by openapi-typescript.
78+
* Do not make direct changes to the file.
79+
*/
80+
81+
export interface paths {}
82+
83+
export interface components {
84+
schemas: {
85+
calendar: {
86+
dates?: {
87+
start?: Date;
88+
} & { [key: string]: any };
89+
} & { [key: string]: any };
90+
};
91+
}
92+
3993
export interface operations {}
4094
`);
4195
});

0 commit comments

Comments
 (0)