mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +00:00
test(contracts): share closed object schema fixtures (#17035)
This commit is contained in:
1 parent
9c698f2ac2
commit
c9f84f06c4
1 file changed
+35
-60
@@ -18,6 +18,16 @@ import {
|
||||
import { drafts, validatorFor } from "./advertisedSchemaValidator.fixture.js";
|
||||
import { JAVASCRIPT_APPLICATION_EVIDENCE_EXAMPLE } from "./javascript/javascriptRuntimeReconciliationExample.js";
|
||||
|
||||
const closedObjectSchema = (
|
||||
properties: Record<string, unknown>,
|
||||
required: string[],
|
||||
) => ({
|
||||
type: "object",
|
||||
properties,
|
||||
required,
|
||||
additionalProperties: false,
|
||||
});
|
||||
|
||||
const contractFrom = (family: readonly ToolContract[], name: string) => {
|
||||
const contract = family.find((entry) => entry.name === name);
|
||||
if (contract === undefined)
|
||||
@@ -301,12 +311,7 @@ describe("root input presentation", () => {
|
||||
["__proto__", { type: "string" }],
|
||||
["constructor", { type: "number" }],
|
||||
]);
|
||||
const branch = {
|
||||
type: "object",
|
||||
properties: fields,
|
||||
required: ["__proto__"],
|
||||
additionalProperties: false,
|
||||
};
|
||||
const branch = closedObjectSchema(fields, ["__proto__"]);
|
||||
const presented = presentInputJsonSchema(
|
||||
{ anyOf: [branch, branch] },
|
||||
(property) => `Parameter ${property}`,
|
||||
@@ -553,24 +558,20 @@ describe("advertised Boolean schema composition", () => {
|
||||
properties: {
|
||||
selection: {
|
||||
oneOf: [
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
closedObjectSchema(
|
||||
{
|
||||
source: { type: "string" },
|
||||
mode: { type: "boolean", const: false },
|
||||
},
|
||||
required: ["source", "mode"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
["source", "mode"],
|
||||
),
|
||||
closedObjectSchema(
|
||||
{
|
||||
target: { type: "string" },
|
||||
mode: { type: "boolean", const: true },
|
||||
},
|
||||
required: ["target", "mode"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
["target", "mode"],
|
||||
),
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -692,18 +693,8 @@ it.each(["$ref", "$dynamicRef"])(
|
||||
(keyword) => {
|
||||
const source = {
|
||||
anyOf: [
|
||||
{
|
||||
type: "object",
|
||||
properties: { end: { const: "done" } },
|
||||
required: ["end"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: { next: { [keyword]: "#" } },
|
||||
required: ["next"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
closedObjectSchema({ end: { const: "done" } }, ["end"]),
|
||||
closedObjectSchema({ next: { [keyword]: "#" } }, ["next"]),
|
||||
],
|
||||
};
|
||||
const presented = presentInputJsonSchema(source, () => undefined);
|
||||
@@ -724,25 +715,16 @@ describe("root union default presentation", () => {
|
||||
it("preserves a required prototype-named field in a group-only object", () => {
|
||||
const canonical = {
|
||||
anyOf: [
|
||||
{
|
||||
type: "object",
|
||||
properties: { text: { type: "string" } },
|
||||
required: ["text"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
config: {
|
||||
type: "object",
|
||||
properties: { ["__proto__"]: { type: "string", default: "" } },
|
||||
required: ["__proto__"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
closedObjectSchema({ text: { type: "string" } }, ["text"]),
|
||||
closedObjectSchema(
|
||||
{
|
||||
config: closedObjectSchema(
|
||||
{ ["__proto__"]: { type: "string", default: "" } },
|
||||
["__proto__"],
|
||||
),
|
||||
},
|
||||
required: ["config"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
["config"],
|
||||
),
|
||||
],
|
||||
};
|
||||
const advertised = presentInputJsonSchema(canonical, () => undefined);
|
||||
@@ -816,15 +798,9 @@ describe("root union default presentation", () => {
|
||||
? "http://json-schema.org/draft-07/schema#"
|
||||
: "https://json-schema.org/draft/2020-12/schema",
|
||||
anyOf: [
|
||||
{
|
||||
type: "object",
|
||||
properties: { text: { type: "string" } },
|
||||
required: ["text"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
closedObjectSchema({ text: { type: "string" } }, ["text"]),
|
||||
closedObjectSchema(
|
||||
{
|
||||
normalization: {
|
||||
$id: "https://example.test/normalization",
|
||||
type: "object",
|
||||
@@ -835,9 +811,8 @@ describe("root union default presentation", () => {
|
||||
default: { rules: { type: "string" } },
|
||||
},
|
||||
},
|
||||
required: ["normalization"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
["normalization"],
|
||||
),
|
||||
],
|
||||
};
|
||||
const advertised = presentInputJsonSchema(canonical, () => undefined);
|
||||
|
||||
Reference in new issue
Block a user