From 72023e696c0fc188cfa52a5e5323daab1f75a029 Mon Sep 17 00:00:00 2001 From: Roger Peppe Date: Tue, 15 Oct 2024 15:23:41 +0100 Subject: [PATCH] encoding/jsonschema: add if/then/else test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows us to see the schema that results from an "if" keyword, so we can see the improvement in the next CL. Signed-off-by: Roger Peppe Change-Id: I23ace058b944ab6362ee0c119a7c476bb9e5f10a Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202608 TryBot-Result: CUEcueckoo Unity-Result: CUE porcuepine Reviewed-by: Daniel Martí --- .../testdata/txtar/ifthenelse.txtar | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 encoding/jsonschema/testdata/txtar/ifthenelse.txtar diff --git a/encoding/jsonschema/testdata/txtar/ifthenelse.txtar b/encoding/jsonschema/testdata/txtar/ifthenelse.txtar new file mode 100644 index 00000000000..e30fcf08796 --- /dev/null +++ b/encoding/jsonschema/testdata/txtar/ifthenelse.txtar @@ -0,0 +1,36 @@ +-- schema.json -- +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "properties": { + "a": { + "type": "number" + } + }, + "required": [ + "a" + ] + }, + "then": { + "properties": { + "b": { + "type": "number" + } + }, + "required": [ + "b" + ] + }, + "type": "object" +} +-- out/decode/extract -- +@jsonschema(schema="https://json-schema.org/draft/2019-09/schema") +matchIf(null | bool | number | string | [...] | { + a!: number + ... +}, null | bool | number | string | [...] | { + b!: number + ... +}, _) & { + ... +}