Skip to content

Commit df9e8b2

Browse files
committed
Readded composition test for oneOf inside an object as its own unit test
1 parent ce292e7 commit df9e8b2

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

packages/openapi-typescript/test/transform/schema-object/composition.test.ts

+53
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,59 @@ describe("composition", () => {
299299
},
300300
},
301301
],
302+
[
303+
// this is actually invalid syntax for oneOfs, but we support it anyways for better compatibility with bad schemas
304+
"discriminator > oneOf inside object",
305+
{
306+
given: {
307+
type: "object",
308+
required: ["name"],
309+
properties: {
310+
name: { type: "string" },
311+
},
312+
oneOf: [
313+
{ $ref: "#/components/schemas/Cat" },
314+
{ $ref: "#/components/schemas/Dog" },
315+
],
316+
},
317+
want: `{
318+
name: string;
319+
} & (components["schemas"]["Cat"] | components["schemas"]["Dog"])`,
320+
options: {
321+
path: "#/components/schemas/Pet",
322+
ctx: {
323+
...DEFAULT_OPTIONS.ctx,
324+
discriminators: {
325+
objects: {
326+
"#/components/schemas/Pet": {
327+
propertyName: "petType",
328+
},
329+
"#/components/schemas/Cat": {
330+
propertyName: "petType",
331+
},
332+
"#/components/schemas/Dog": {
333+
propertyName: "petType",
334+
},
335+
},
336+
refsHandled: [],
337+
},
338+
resolve($ref) {
339+
switch ($ref) {
340+
case "#/components/schemas/Pet": {
341+
return {
342+
propertyName: "petType",
343+
oneOf: ["#/components/schemas/Cat"],
344+
};
345+
}
346+
default: {
347+
return undefined as any;
348+
}
349+
}
350+
},
351+
},
352+
},
353+
},
354+
],
302355
[
303356
"discriminator > oneOf + null + implicit mapping",
304357
{

0 commit comments

Comments
 (0)