Skip to content

Commit 0555148

Browse files
authored
Merge pull request #35 from Carl-Foster/fix/oneOf-ref-resolution-loss
fix: oneOf step loses compiled reference resolution
2 parents b8b9055 + 8b64771 commit 0555148

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/step.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ const stepType = {
144144

145145
const oneOfIndex = targetSchema.oneOf.findIndex((s) => s === resolvedSchema);
146146

147-
resolvedSchema = JSON.parse(JSON.stringify(resolvedSchema));
148147
resolvedSchema.variableSchema = true;
149148
resolvedSchema.oneOfIndex = oneOfIndex;
150149
resolvedSchema.oneOfSchema = targetSchema;

test/unit/step/step.oneOf.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,36 @@ describe("step.oneof", () => {
5252

5353
expect(res.oneOfIndex).to.eq(1);
5454
});
55+
56+
it("should maintain references from a remote schema when resolving oneOf with $ref", () => {
57+
core.addRemoteSchema("https://my-other-schema.com/schema.json", {
58+
type: "object",
59+
properties: {
60+
innerTitle: { $ref: "#/definitions/number" }
61+
},
62+
definitions: {
63+
number: { type: "number", title: "Zahl" }
64+
}
65+
});
66+
const schema = core.compileSchema({
67+
type: "object",
68+
properties: {
69+
title: {
70+
oneOf: [
71+
{
72+
type: "object",
73+
properties: { innerTitle: { type: "string", title: "Zeichenkette" } }
74+
},
75+
{ $ref: "https://my-other-schema.com/schema.json" }
76+
]
77+
}
78+
}
79+
});
80+
const res = step(core, "title", schema, { title: { innerTitle: 111 } });
81+
82+
expect(res.type).to.eq("object");
83+
84+
const nextRes = step(core, "innerTitle", res, { innerTitle: 111 });
85+
expect(nextRes.type).to.eq("number");
86+
});
5587
});

0 commit comments

Comments
 (0)