diff --git a/.github/workflows/evict_caches.yml b/.github/workflows/evict_caches.yml index ce41960a742..a4feeb463e1 100644 --- a/.github/workflows/evict_caches.yml +++ b/.github/workflows/evict_caches.yml @@ -21,8 +21,8 @@ jobs: run: touch -t 202211302355 $(find * -type d) - name: Restore git file modification times uses: chetan/git-restore-mtime-action@075f9bc9d159805603419d50f794bd9f33252ebe - - id: DispatchTrailer - name: Try to extract Dispatch-Trailer + - name: Try to extract Dispatch-Trailer + id: DispatchTrailer run: |- x="$(git log -1 --pretty='%(trailers:key=Dispatch-Trailer,valueonly)')" if [[ "$x" == "" ]] @@ -38,11 +38,11 @@ jobs: echo "value<> $GITHUB_OUTPUT echo "$x" >> $GITHUB_OUTPUT echo "EOD" >> $GITHUB_OUTPUT - - if: |- + - name: Check we don't have Dispatch-Trailer on a protected branch + if: |- ((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, ' Dispatch-Trailer: {"type":"')))) && (contains(github.event.head_commit.message, ' Dispatch-Trailer: {"type":"')) - name: Check we don't have Dispatch-Trailer on a protected branch run: |- echo "github.event.head_commit.message contains Dispatch-Trailer but we are on a protected branch" false diff --git a/.github/workflows/push_tip_to_trybot.yml b/.github/workflows/push_tip_to_trybot.yml index 454c234b555..84e22fff724 100644 --- a/.github/workflows/push_tip_to_trybot.yml +++ b/.github/workflows/push_tip_to_trybot.yml @@ -10,10 +10,6 @@ concurrency: push_tip_to_trybot jobs: push: runs-on: ubuntu-22.04 - defaults: - run: - shell: bash - if: ${{github.repository == 'cue-lang/cue'}} steps: - name: Write netrc file for cueckoo Gerrithub run: |- @@ -49,3 +45,7 @@ jobs: echo "Giving up" exit 1 fi + defaults: + run: + shell: bash + if: ${{github.repository == 'cue-lang/cue'}} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 401380c89ea..1e135d1cdc5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,10 +14,10 @@ concurrency: release jobs: goreleaser: runs-on: ubuntu-22.04 + if: ${{github.repository == 'cue-lang/cue'}} defaults: run: shell: bash - if: ${{github.repository == 'cue-lang/cue'}} steps: - name: Checkout code uses: actions/checkout@v4 @@ -28,8 +28,8 @@ jobs: run: touch -t 202211302355 $(find * -type d) - name: Restore git file modification times uses: chetan/git-restore-mtime-action@075f9bc9d159805603419d50f794bd9f33252ebe - - id: DispatchTrailer - name: Try to extract Dispatch-Trailer + - name: Try to extract Dispatch-Trailer + id: DispatchTrailer run: |- x="$(git log -1 --pretty='%(trailers:key=Dispatch-Trailer,valueonly)')" if [[ "$x" == "" ]] @@ -45,11 +45,11 @@ jobs: echo "value<> $GITHUB_OUTPUT echo "$x" >> $GITHUB_OUTPUT echo "EOD" >> $GITHUB_OUTPUT - - if: |- + - name: Check we don't have Dispatch-Trailer on a protected branch + if: |- ((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, ' Dispatch-Trailer: {"type":"')))) && (contains(github.event.head_commit.message, ' Dispatch-Trailer: {"type":"')) - name: Check we don't have Dispatch-Trailer on a protected branch run: |- echo "github.event.head_commit.message contains Dispatch-Trailer but we are on a protected branch" false @@ -76,13 +76,13 @@ jobs: install-only: true version: v2.2.0 - name: Run GoReleaser with CUE - run: cue cmd release - working-directory: ./internal/ci/goreleaser env: GITHUB_TOKEN: ${{ secrets.CUECKOO_GITHUB_PAT }} - - if: startsWith(github.ref, 'refs/tags/v') - name: Re-test cuelang.org + run: cue cmd release + working-directory: ./internal/ci/goreleaser + - name: Re-test cuelang.org + if: startsWith(github.ref, 'refs/tags/v') run: 'curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.CUECKOO_GITHUB_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" --fail --request POST --data-binary "{\"event_type\":\"Re-test post release of ${GITHUB_REF##refs/tags/}\"}" https://api.github.com/repos/cue-lang/cuelang.org/dispatches' - - if: startsWith(github.ref, 'refs/tags/v') - name: Trigger unity build + - name: Trigger unity build + if: startsWith(github.ref, 'refs/tags/v') run: 'curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.PORCUEPINE_GITHUB_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" --fail --request POST --data-binary "{\"event_type\":\"Check against CUE ${GITHUB_REF##refs/tags/}\",\"client_payload\":{\"type\":\"unity\",\"payload\":{\"versions\":\"\\\"${GITHUB_REF##refs/tags/}\\\"\"}}}" https://api.github.com/repos/cue-unity/unity-private/dispatches' diff --git a/.github/workflows/tip_triggers.yml b/.github/workflows/tip_triggers.yml index f898e84dbb6..7b5e723e002 100644 --- a/.github/workflows/tip_triggers.yml +++ b/.github/workflows/tip_triggers.yml @@ -8,10 +8,10 @@ name: Triggers on push to tip jobs: push: runs-on: ubuntu-22.04 + if: ${{github.repository == 'cue-lang/cue'}} defaults: run: shell: bash - if: ${{github.repository == 'cue-lang/cue'}} steps: - name: Trigger unity build run: 'curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.PORCUEPINE_GITHUB_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" --fail --request POST --data-binary "{\"event_type\":\"Check against ${GITHUB_SHA}\",\"client_payload\":{\"type\":\"unity\",\"payload\":{\"versions\":\"\\\"commit:${GITHUB_SHA}\\\"\"}}}" https://api.github.com/repos/cue-unity/unity-private/dispatches' diff --git a/.github/workflows/trybot.yml b/.github/workflows/trybot.yml index 2bc0a365331..e6881ae642d 100644 --- a/.github/workflows/trybot.yml +++ b/.github/workflows/trybot.yml @@ -9,8 +9,8 @@ name: TryBot - release-branch.* tags-ignore: - v* - pull_request: {} workflow_dispatch: {} + pull_request: {} jobs: test: strategy: @@ -24,13 +24,13 @@ jobs: - macos-14 - windows-2022 runs-on: ${{ matrix.runner }} - defaults: - run: - shell: bash if: |- (contains(github.event.head_commit.message, ' Dispatch-Trailer: {"type":"trybot"')) || ! (contains(github.event.head_commit.message, ' Dispatch-Trailer: {"type":"')) + defaults: + run: + shell: bash steps: - name: Checkout code uses: actions/checkout@v4 @@ -41,8 +41,8 @@ jobs: run: touch -t 202211302355 $(find * -type d) - name: Restore git file modification times uses: chetan/git-restore-mtime-action@075f9bc9d159805603419d50f794bd9f33252ebe - - id: DispatchTrailer - name: Try to extract Dispatch-Trailer + - name: Try to extract Dispatch-Trailer + id: DispatchTrailer run: |- x="$(git log -1 --pretty='%(trailers:key=Dispatch-Trailer,valueonly)')" if [[ "$x" == "" ]] @@ -58,11 +58,11 @@ jobs: echo "value<> $GITHUB_OUTPUT echo "$x" >> $GITHUB_OUTPUT echo "EOD" >> $GITHUB_OUTPUT - - if: |- + - name: Check we don't have Dispatch-Trailer on a protected branch + if: |- ((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, ' Dispatch-Trailer: {"type":"')))) && (contains(github.event.head_commit.message, ' Dispatch-Trailer: {"type":"')) - name: Check we don't have Dispatch-Trailer on a protected branch run: |- echo "github.event.head_commit.message contains Dispatch-Trailer but we are on a protected branch" false @@ -71,73 +71,73 @@ jobs: with: cache: false go-version: ${{ matrix.go-version }} - - id: go-mod-cache-dir - name: Get go mod cache directory + - name: Get go mod cache directory + id: go-mod-cache-dir run: echo "dir=$(go env GOMODCACHE)" >> ${GITHUB_OUTPUT} - - id: go-cache-dir - name: Get go build/test cache directory + - name: Get go build/test cache directory + id: go-cache-dir run: echo "dir=$(go env GOCACHE)" >> ${GITHUB_OUTPUT} - - if: |- - (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, ' - Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) - uses: actions/cache@v4 - with: + - with: path: |- ${{ steps.go-mod-cache-dir.outputs.dir }}/cache/download ${{ steps.go-cache-dir.outputs.dir }} key: ${{ runner.os }}-${{ matrix.go-version }}-${{ github.run_id }} restore-keys: ${{ runner.os }}-${{ matrix.go-version }} - - if: |- - ! (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, ' + if: |- + (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, ' Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) - uses: actions/cache/restore@v4 - with: + uses: actions/cache@v4 + - with: path: |- ${{ steps.go-mod-cache-dir.outputs.dir }}/cache/download ${{ steps.go-cache-dir.outputs.dir }} key: ${{ runner.os }}-${{ matrix.go-version }}-${{ github.run_id }} restore-keys: ${{ runner.os }}-${{ matrix.go-version }} + uses: actions/cache/restore@v4 + if: |- + ! (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, ' + Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) - if: |- github.repository == 'cue-lang/cue' && (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, ' Dispatch-Trailer: {"type":"')))) || github.ref == 'refs/heads/ci/test') run: go clean -testcache - - if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04') - name: Early git and code sanity checks + - name: Early git and code sanity checks + if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04') run: go run ./internal/ci/checks - - if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04') - name: Generate + - name: Generate run: go generate ./... - - if: |- + if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04') + - name: Test + if: |- ((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, ' Dispatch-Trailer: {"type":"')))) || !(matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04') - name: Test run: go test ./... - - if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04') - name: Test with -race - run: go test -race ./... + - name: Test with -race env: GORACE: atexit_sleep_ms=10 + if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04') + run: go test -race ./... - name: Test with -tags=cuewasm run: go test -tags cuewasm ./cmd/cue/cmd ./cue/interpreter/wasm - name: gcloud auth for end-to-end tests id: auth + uses: google-github-actions/auth@v2 if: |- github.repository == 'cue-lang/cue' && (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, ' Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) && (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04') - uses: google-github-actions/auth@v2 with: credentials_json: ${{ secrets.E2E_GCLOUD_KEY }} - - if: |- + - name: gcloud setup for end-to-end tests + if: |- github.repository == 'cue-lang/cue' && (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, ' Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) && (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04') - name: gcloud setup for end-to-end tests uses: google-github-actions/setup-gcloud@v2 - - if: |- - github.repository == 'cue-lang/cue' && (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, ' - Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) && (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04') - name: End-to-end test + - name: End-to-end test env: CUE_TEST_LOGINS: ${{ secrets.E2E_CUE_LOGINS }} + if: |- + github.repository == 'cue-lang/cue' && (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, ' + Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) && (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04') run: |- cd internal/_e2e go test -race @@ -147,6 +147,6 @@ jobs: go vet ./... go mod tidy (cd internal/_e2e && go test -run=-) - - if: always() - name: Check that git is clean at the end of the job + - name: Check that git is clean at the end of the job + if: always() run: test -z "$(git status --porcelain)" || (git status; git diff; false) diff --git a/.github/workflows/trybot_dispatch.yml b/.github/workflows/trybot_dispatch.yml index 2adf1a1645d..18ee5e06d5c 100644 --- a/.github/workflows/trybot_dispatch.yml +++ b/.github/workflows/trybot_dispatch.yml @@ -9,10 +9,10 @@ name: Dispatch trybot jobs: trybot: runs-on: ubuntu-22.04 + if: ${{ ((github.ref == 'refs/heads/ci/test') && false) || github.event.client_payload.type == 'trybot' }} defaults: run: shell: bash - if: ${{ ((github.ref == 'refs/heads/ci/test') && false) || github.event.client_payload.type == 'trybot' }} steps: - name: Write netrc file for cueckoo Gerrithub run: |- @@ -22,17 +22,17 @@ jobs: password ${{ secrets.CUECKOO_GERRITHUB_PASSWORD }} EOD chmod 600 ~/.netrc - - id: payload + - name: Write fake payload + id: payload if: github.repository == 'cue-lang/cue' && (github.ref == 'refs/heads/ci/test') - name: Write fake payload run: |- cat <> $GITHUB_OUTPUT value<=1, [string, "bash" | "pwsh" | "python" | "sh" | "cmd" | "powershell"]) #types: [_, ...] #: "working-directory": string - #jobNeeds: [...#name] & [_, ...] | #name + #jobNeeds: matchN(1, [[...#name] & [_, ...], #name]) - #matrix: { - {[=~"^(in|ex)clude$" & !~"^()$"]: #expressionSyntax | [...{ + #matrix: matchN(1, [{ + {[=~"^(in|ex)clude$" & !~"^()$"]: matchN(1, [#expressionSyntax, [...{ [string]: #configuration - }] & [_, ...]} - {[!~"^(in|ex)clude$" & !~"^()$"]: [...#configuration] & [_, ...] | #expressionSyntax} - } | #expressionSyntax + }] & [_, ...]]) + } + {[!~"^(in|ex)clude$" & !~"^()$"]: matchN(1, [[...#configuration] & [_, ...], #expressionSyntax])} + }, #expressionSyntax]) #reusableWorkflowCallJob: { // The name of the job displayed on GitHub. @@ -683,7 +684,7 @@ import "strings" // 'secrets' to provide a map of secrets that are passed to the // called workflow. Any secrets that you pass must match the // names defined in the called workflow. - secrets?: #env | "inherit" + secrets?: matchN(1, [#env, "inherit"]) // A strategy creates a build matrix for your jobs. You can define // different variations of an environment to run each job in. @@ -713,7 +714,7 @@ import "strings" // will be canceled. To also cancel any currently running job or // workflow in the same concurrency group, specify // cancel-in-progress: true. - concurrency?: string | #concurrency + concurrency?: matchN(1, [string, #concurrency]) } #normalJob: { @@ -724,14 +725,14 @@ import "strings" // The type of machine to run the job on. The machine can be // either a GitHub-hosted runner, or a self-hosted runner. - "runs-on"!: string | [string] & [_, ...] | { + "runs-on"!: matchN(>=1, [string, matchN(>=1, [[string] & [_, ...]]), { group?: string - labels?: string | [...string] + labels?: matchN(1, [string, [...string]]) ... - } | #stringContainingExpressionSyntax | #expressionSyntax + }, #stringContainingExpressionSyntax, #expressionSyntax]) // The environment that the job references. - environment?: string | #environment + environment?: matchN(1, [string, #environment]) // A map of outputs for a job. Job outputs are available to all // downstream jobs that depend on this job. @@ -765,13 +766,13 @@ import "strings" // environment variables are not preserved between steps. GitHub // provides built-in steps to set up and complete a job. // Must contain either `uses` or `run` - steps?: [...({ + steps?: [...matchN(2, [matchN(1, [{ uses!: string ... - } | { + }, { run!: string ... - }) & { + }]), { // A unique identifier for the step. You can use the id to // reference the step in contexts. For more information, see // https://help.github.com/en/articles/contexts-and-expression-syntax-for-github-actions. @@ -847,16 +848,16 @@ import "strings" // Prevents a job from failing when a step fails. Set to true to // allow a job to pass when this step fails. - "continue-on-error"?: bool | #expressionSyntax | *false + "continue-on-error"?: matchN(1, [bool, #expressionSyntax]) | *false // The maximum number of minutes to run the step before killing // the process. - "timeout-minutes"?: number | #expressionSyntax - }] & [_, ...] + "timeout-minutes"?: matchN(1, [number, #expressionSyntax]) + }])] & [_, ...] // The maximum number of minutes to let a workflow run before // GitHub automatically cancels it. Default: 360 - "timeout-minutes"?: number | #expressionSyntax | *360 + "timeout-minutes"?: matchN(1, [number, #expressionSyntax]) | *360 // A strategy creates a build matrix for your jobs. You can define // different variations of an environment to run each job in. @@ -876,7 +877,7 @@ import "strings" // Prevents a workflow run from failing when a job fails. Set to // true to allow a workflow run to pass when this job fails. - "continue-on-error"?: bool | #expressionSyntax + "continue-on-error"?: matchN(1, [bool, #expressionSyntax]) // A container to run any steps in a job that don't already // specify a container. If you have steps that use both script @@ -886,7 +887,7 @@ import "strings" // If you do not set a container, all steps will run directly on // the host specified by runs-on unless a step refers to an // action configured to run in a container. - container?: string | #container + container?: matchN(1, [string, #container]) // Additional containers to host services for a job in a workflow. // These are useful for creating databases or cache services like @@ -918,6 +919,6 @@ import "strings" // will be canceled. To also cancel any currently running job or // workflow in the same concurrency group, specify // cancel-in-progress: true. - concurrency?: string | #concurrency + concurrency?: matchN(1, [string, #concurrency]) } } diff --git a/cue.mod/usr/github.com/SchemaStore/schemastore/src/schemas/json/workflow.cue b/cue.mod/usr/github.com/SchemaStore/schemastore/src/schemas/json/workflow.cue index 7b0e3c81ffa..d4330b2230d 100644 --- a/cue.mod/usr/github.com/SchemaStore/schemastore/src/schemas/json/workflow.cue +++ b/cue.mod/usr/github.com/SchemaStore/schemastore/src/schemas/json/workflow.cue @@ -2,14 +2,3 @@ package json #job: ((#Workflow & {jobs: _}).jobs & {x: _}).x #step: ((#job & {steps: _}).steps & [_])[0] - -// CUE does not properly encode a JSON Schema oneOf; see -// https://cuelang.org/issue/3165. For now, apply a temporary workaround which -// forces the other option to bottom. -#Workflow: jobs?: [string]: steps?: [...( - { - uses?: _|_ - } | { - run?: _|_ - }), -] diff --git a/encoding/jsonschema/constraints.go b/encoding/jsonschema/constraints.go index b5446b71afe..ab7c14730d4 100644 --- a/encoding/jsonschema/constraints.go +++ b/encoding/jsonschema/constraints.go @@ -49,7 +49,7 @@ func init() { } // Note: the following table is ordered lexically by keyword name. -// The various implementations are grouped by kind in the constaint-*.go files. +// The various implementations are grouped by kind in the constraint-*.go files. const numPhases = 5 diff --git a/encoding/jsonschema/constraints_combinator.go b/encoding/jsonschema/constraints_combinator.go index 3e042cb04ee..4b50000fa35 100644 --- a/encoding/jsonschema/constraints_combinator.go +++ b/encoding/jsonschema/constraints_combinator.go @@ -15,6 +15,8 @@ package jsonschema import ( + "strconv" + "cuelang.org/go/cue" "cuelang.org/go/cue/ast" "cuelang.org/go/cue/token" @@ -23,9 +25,14 @@ import ( // Constraint combinators. func constraintAllOf(key string, n cue.Value, s *state) { - var a []ast.Expr var knownTypes cue.Kind - for _, v := range s.listItems("allOf", n, false) { + items := s.listItems("allOf", n, false) + if len(items) == 0 { + s.errf(n, "allOf requires at least one subschema") + return + } + a := make([]ast.Expr, 0, len(items)) + for _, v := range items { x, sub := s.schemaState(v, s.allowedTypes, nil, true) s.allowedTypes &= sub.allowedTypes if sub.hasConstraints() { @@ -44,33 +51,60 @@ func constraintAllOf(key string, n cue.Value, s *state) { // as that's a known-impossible assertion? if len(a) > 0 { s.knownTypes &= knownTypes - s.all.add(n, ast.NewBinExpr(token.AND, a...)) + s.all.add(n, ast.NewCall( + ast.NewIdent("matchN"), + // TODO it would be nice to be able to use a special sentinel "all" value + // here rather than redundantly encoding the length of the list. + &ast.BasicLit{ + Kind: token.INT, + Value: strconv.Itoa(len(items)), + }, + ast.NewList(a...), + )) } } func constraintAnyOf(key string, n cue.Value, s *state) { var types cue.Kind - var a []ast.Expr var knownTypes cue.Kind - for _, v := range s.listItems("anyOf", n, false) { + items := s.listItems("anyOf", n, false) + if len(items) == 0 { + s.errf(n, "anyOf requires at least one subschema") + return + } + a := make([]ast.Expr, 0, len(items)) + for _, v := range items { x, sub := s.schemaState(v, s.allowedTypes, nil, true) types |= sub.allowedTypes knownTypes |= sub.knownTypes a = append(a, x) } s.allowedTypes &= types - if len(a) > 0 { - s.knownTypes &= knownTypes - s.all.add(n, ast.NewBinExpr(token.OR, a...)) - } + s.knownTypes &= knownTypes + s.all.add(n, ast.NewCall( + ast.NewIdent("matchN"), + &ast.UnaryExpr{ + Op: token.GEQ, + X: &ast.BasicLit{ + Kind: token.INT, + Value: "1", + }, + }, + ast.NewList(a...), + )) } func constraintOneOf(key string, n cue.Value, s *state) { var types cue.Kind var knownTypes cue.Kind - var a []ast.Expr hasSome := false - for _, v := range s.listItems("oneOf", n, false) { + items := s.listItems("oneOf", n, false) + if len(items) == 0 { + s.errf(n, "oneOf requires at least one subschema") + return + } + a := make([]ast.Expr, 0, len(items)) + for _, v := range items { x, sub := s.schemaState(v, s.allowedTypes, nil, true) types |= sub.allowedTypes @@ -89,7 +123,14 @@ func constraintOneOf(key string, n cue.Value, s *state) { s.allowedTypes &= types if len(a) > 0 && hasSome { s.knownTypes &= knownTypes - s.all.add(n, ast.NewBinExpr(token.OR, a...)) + s.all.add(n, ast.NewCall( + ast.NewIdent("matchN"), + &ast.BasicLit{ + Kind: token.INT, + Value: "1", + }, + ast.NewList(a...), + )) } // TODO: oneOf({a:x}, {b:y}, ..., not(anyOf({a:x}, {b:y}, ...))), diff --git a/encoding/jsonschema/decode_test.go b/encoding/jsonschema/decode_test.go index 30788ed59ed..e0c641526ea 100644 --- a/encoding/jsonschema/decode_test.go +++ b/encoding/jsonschema/decode_test.go @@ -68,6 +68,10 @@ func TestDecode(t *testing.T) { test.Run(t, func(t *cuetxtar.Test) { cfg := &jsonschema.Config{} + if t.HasTag("brokenInV2") && t.M.Name() == "v2" { + t.Skip("skipping because test is broken under the v2 evaluator") + } + if t.HasTag("openapi") { cfg.Root = "#/components/schemas/" cfg.Map = func(p token.Pos, a []string) ([]ast.Label, error) { @@ -119,7 +123,7 @@ func TestDecode(t *testing.T) { // Verify that the generated CUE compiles. schemav := ctx.CompileBytes(b, cue.Filename("generated.cue")) if err := schemav.Err(); err != nil { - t.Fatal(errors.Details(err, nil)) + t.Fatal(errors.Details(err, nil), qt.Commentf("generated code: %q", b)) } testEntries, err := fs.ReadDir(fsys, "test") if err != nil { @@ -168,7 +172,7 @@ func TestDecode(t *testing.T) { } } else { if err := rv.Err(); err != nil { - t.Fatalf("test %v unexpectedly fails", file) + t.Fatalf("test %v unexpectedly fails: %v", file, errors.Details(err, nil)) } } } diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/additionalItems.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/additionalItems.json index 7778e046340..23b27d9e296 100644 --- a/encoding/jsonschema/testdata/external/tests/draft2019-09/additionalItems.json +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/additionalItems.json @@ -230,8 +230,8 @@ ], "valid": true, "skip": { - "v2": "5 errors in empty disjunction:\nconflicting values [1,null] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,null] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,null] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,null] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,null] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n", - "v3": "conflicting values [1,null] and {...} (mismatched types list and struct):\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,null] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,null] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,null] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,null] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\nincompatible list lengths (1 and 2):\n instance.json:1:1\n" + "v2": "invalid value [1,null] (does not satisfy matchN(1, [null | bool | number | string | [int] | {}])): 0 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n", + "v3": "invalid value [1,null] (does not satisfy matchN(1, [null | bool | number | string | [int] | {}])): 0 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n" } } ] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/allOf.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/allOf.json index 963335588d3..fe4c995b78e 100644 --- a/encoding/jsonschema/testdata/external/tests/draft2019-09/allOf.json +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/allOf.json @@ -40,14 +40,20 @@ "data": { "foo": "baz" }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "mismatch first", "data": { "bar": 2 }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "wrong type", @@ -118,7 +124,10 @@ "bar": 2, "baz": null }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "mismatch second allOf", @@ -126,14 +135,20 @@ "foo": "quux", "bar": 2 }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "mismatch both", "data": { "bar": 2 }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } } ] }, @@ -369,7 +384,10 @@ { "description": "allOf: false, anyOf: true, oneOf: true", "data": 15, - "valid": false + "valid": false, + "skip": { + "v2": "unexpected success" + } }, { "description": "allOf: true, anyOf: false, oneOf: false", diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/anyOf.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/anyOf.json index a3c6b724eb8..7ff57eb68e9 100644 --- a/encoding/jsonschema/testdata/external/tests/draft2019-09/anyOf.json +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/anyOf.json @@ -93,11 +93,17 @@ false ] }, + "skip": { + "v3": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:17\n" + }, "tests": [ { "description": "any value is valid", "data": "foo", - "valid": true + "valid": true, + "skip": { + "v3": "could not compile schema" + } } ] }, @@ -111,8 +117,7 @@ ] }, "skip": { - "v2": "extract error: cannot compile resulting schema: 2 errors in empty disjunction:\nexplicit error (_|_ literal) in source:\n generated.cue:2:1\nexplicit error (_|_ literal) in source:\n generated.cue:2:7\n", - "v3": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:1\nexplicit error (_|_ literal) in source:\n generated.cue:2:7\n" + "v3": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:14\n" }, "tests": [ { @@ -120,7 +125,6 @@ "data": "foo", "valid": false, "skip": { - "v2": "could not compile schema", "v3": "could not compile schema" } } @@ -159,22 +163,14 @@ "data": { "bar": 2 }, - "valid": true, - "skip": { - "v2": "incomplete value {bar:2} | {bar:2,foo!:string}\n", - "v3": "incomplete value {bar:2} | {bar:2,foo!:string}\n" - } + "valid": true }, { "description": "second anyOf valid (complex)", "data": { "foo": "baz" }, - "valid": true, - "skip": { - "v2": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n", - "v3": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n" - } + "valid": true }, { "description": "both anyOf valid (complex)", diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/oneOf.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/oneOf.json index 642adb01ac5..3ef71969727 100644 --- a/encoding/jsonschema/testdata/external/tests/draft2019-09/oneOf.json +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/oneOf.json @@ -26,11 +26,7 @@ { "description": "both oneOf valid", "data": 3, - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false }, { "description": "neither oneOf valid", @@ -67,11 +63,7 @@ { "description": "both oneOf valid", "data": "foo", - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false } ] }, @@ -194,8 +186,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {bar:2} | {bar:2,foo!:string}\n", - "v3": "incomplete value {bar:2} | {bar:2,foo!:string}\n" + "v3": "invalid value {bar:2} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { @@ -205,8 +196,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n", - "v3": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n" + "v3": "invalid value {foo:\"baz\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { @@ -215,11 +205,7 @@ "foo": "baz", "bar": 2 }, - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false }, { "description": "neither oneOf valid (complex)", @@ -293,11 +279,7 @@ "foo": 1, "bar": 2 }, - "valid": true, - "skip": { - "v2": "incomplete value {foo:1,bar:2} | {foo:1,bar:2,baz!:_}\n", - "v3": "incomplete value {foo:1,bar:2} | {foo:1,bar:2,baz!:_}\n" - } + "valid": true }, { "description": "second valid - valid", @@ -305,11 +287,7 @@ "foo": 1, "baz": 3 }, - "valid": true, - "skip": { - "v2": "incomplete value {foo:1,baz:3,bar!:_} | {foo:1,baz:3}\n", - "v3": "incomplete value {foo:1,baz:3,bar!:_} | {foo:1,baz:3}\n" - } + "valid": true }, { "description": "both valid - invalid", @@ -318,11 +296,7 @@ "bar": 2, "baz": 3 }, - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false } ] }, @@ -358,8 +332,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {bar:8,baz?:_} | {bar:8,foo!:_}\n", - "v3": "incomplete value {bar:8,baz?:_} | {bar:8,foo!:_}\n" + "v3": "invalid value {bar:8} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { @@ -369,8 +342,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {foo:\"foo\",bar!:_,baz?:_} | {foo:\"foo\"}\n", - "v3": "incomplete value {foo:\"foo\",bar!:_,baz?:_} | {foo:\"foo\"}\n" + "v3": "invalid value {foo:\"foo\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/allOf.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/allOf.json index 78bf421f90b..fcdc1ba7620 100644 --- a/encoding/jsonschema/testdata/external/tests/draft2020-12/allOf.json +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/allOf.json @@ -40,14 +40,20 @@ "data": { "foo": "baz" }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "mismatch first", "data": { "bar": 2 }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "wrong type", @@ -118,7 +124,10 @@ "bar": 2, "baz": null }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "mismatch second allOf", @@ -126,14 +135,20 @@ "foo": "quux", "bar": 2 }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "mismatch both", "data": { "bar": 2 }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } } ] }, @@ -369,7 +384,10 @@ { "description": "allOf: false, anyOf: true, oneOf: true", "data": 15, - "valid": false + "valid": false, + "skip": { + "v2": "unexpected success" + } }, { "description": "allOf: true, anyOf: false, oneOf: false", diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/anyOf.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/anyOf.json index d6d22394dea..2119f14250d 100644 --- a/encoding/jsonschema/testdata/external/tests/draft2020-12/anyOf.json +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/anyOf.json @@ -93,11 +93,17 @@ false ] }, + "skip": { + "v3": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:17\n" + }, "tests": [ { "description": "any value is valid", "data": "foo", - "valid": true + "valid": true, + "skip": { + "v3": "could not compile schema" + } } ] }, @@ -111,8 +117,7 @@ ] }, "skip": { - "v2": "extract error: cannot compile resulting schema: 2 errors in empty disjunction:\nexplicit error (_|_ literal) in source:\n generated.cue:2:1\nexplicit error (_|_ literal) in source:\n generated.cue:2:7\n", - "v3": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:1\nexplicit error (_|_ literal) in source:\n generated.cue:2:7\n" + "v3": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:14\n" }, "tests": [ { @@ -120,7 +125,6 @@ "data": "foo", "valid": false, "skip": { - "v2": "could not compile schema", "v3": "could not compile schema" } } @@ -159,22 +163,14 @@ "data": { "bar": 2 }, - "valid": true, - "skip": { - "v2": "incomplete value {bar:2} | {bar:2,foo!:string}\n", - "v3": "incomplete value {bar:2} | {bar:2,foo!:string}\n" - } + "valid": true }, { "description": "second anyOf valid (complex)", "data": { "foo": "baz" }, - "valid": true, - "skip": { - "v2": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n", - "v3": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n" - } + "valid": true }, { "description": "both anyOf valid (complex)", diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/oneOf.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/oneOf.json index 9b0d8f5c101..eda13ac3875 100644 --- a/encoding/jsonschema/testdata/external/tests/draft2020-12/oneOf.json +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/oneOf.json @@ -26,11 +26,7 @@ { "description": "both oneOf valid", "data": 3, - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false }, { "description": "neither oneOf valid", @@ -67,11 +63,7 @@ { "description": "both oneOf valid", "data": "foo", - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false } ] }, @@ -194,8 +186,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {bar:2} | {bar:2,foo!:string}\n", - "v3": "incomplete value {bar:2} | {bar:2,foo!:string}\n" + "v3": "invalid value {bar:2} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { @@ -205,8 +196,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n", - "v3": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n" + "v3": "invalid value {foo:\"baz\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { @@ -215,11 +205,7 @@ "foo": "baz", "bar": 2 }, - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false }, { "description": "neither oneOf valid (complex)", @@ -293,11 +279,7 @@ "foo": 1, "bar": 2 }, - "valid": true, - "skip": { - "v2": "incomplete value {foo:1,bar:2} | {foo:1,bar:2,baz!:_}\n", - "v3": "incomplete value {foo:1,bar:2} | {foo:1,bar:2,baz!:_}\n" - } + "valid": true }, { "description": "second valid - valid", @@ -305,11 +287,7 @@ "foo": 1, "baz": 3 }, - "valid": true, - "skip": { - "v2": "incomplete value {foo:1,baz:3,bar!:_} | {foo:1,baz:3}\n", - "v3": "incomplete value {foo:1,baz:3,bar!:_} | {foo:1,baz:3}\n" - } + "valid": true }, { "description": "both valid - invalid", @@ -318,11 +296,7 @@ "bar": 2, "baz": 3 }, - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false } ] }, @@ -358,8 +332,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {bar:8,baz?:_} | {bar:8,foo!:_}\n", - "v3": "incomplete value {bar:8,baz?:_} | {bar:8,foo!:_}\n" + "v3": "invalid value {bar:8} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { @@ -369,8 +342,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {foo:\"foo\",bar!:_,baz?:_} | {foo:\"foo\"}\n", - "v3": "incomplete value {foo:\"foo\",bar!:_,baz?:_} | {foo:\"foo\"}\n" + "v3": "invalid value {foo:\"foo\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { diff --git a/encoding/jsonschema/testdata/external/tests/draft4/additionalItems.json b/encoding/jsonschema/testdata/external/tests/draft4/additionalItems.json index 361d9685173..dedd6fbba29 100644 --- a/encoding/jsonschema/testdata/external/tests/draft4/additionalItems.json +++ b/encoding/jsonschema/testdata/external/tests/draft4/additionalItems.json @@ -192,8 +192,8 @@ ], "valid": true, "skip": { - "v2": "5 errors in empty disjunction:\nconflicting values [1,null] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,null] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,null] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,null] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,null] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n", - "v3": "conflicting values [1,null] and {...} (mismatched types list and struct):\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,null] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,null] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,null] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,null] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\nincompatible list lengths (1 and 2):\n instance.json:1:1\n" + "v2": "invalid value [1,null] (does not satisfy matchN(1, [null | bool | number | string | [int] | {}])): 0 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n", + "v3": "invalid value [1,null] (does not satisfy matchN(1, [null | bool | number | string | [int] | {}])): 0 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n" } } ] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/allOf.json b/encoding/jsonschema/testdata/external/tests/draft4/allOf.json index 3c65acb8f71..4bdeb0a478b 100644 --- a/encoding/jsonschema/testdata/external/tests/draft4/allOf.json +++ b/encoding/jsonschema/testdata/external/tests/draft4/allOf.json @@ -39,14 +39,20 @@ "data": { "foo": "baz" }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "mismatch first", "data": { "bar": 2 }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "wrong type", @@ -116,7 +122,10 @@ "bar": 2, "baz": null }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "mismatch second allOf", @@ -124,14 +133,20 @@ "foo": "quux", "bar": 2 }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "mismatch both", "data": { "bar": 2 }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } } ] }, @@ -301,7 +316,10 @@ { "description": "allOf: false, anyOf: true, oneOf: true", "data": 15, - "valid": false + "valid": false, + "skip": { + "v2": "unexpected success" + } }, { "description": "allOf: true, anyOf: false, oneOf: false", diff --git a/encoding/jsonschema/testdata/external/tests/draft4/anyOf.json b/encoding/jsonschema/testdata/external/tests/draft4/anyOf.json index 39347b1f79c..7c157961c4b 100644 --- a/encoding/jsonschema/testdata/external/tests/draft4/anyOf.json +++ b/encoding/jsonschema/testdata/external/tests/draft4/anyOf.json @@ -97,22 +97,14 @@ "data": { "bar": 2 }, - "valid": true, - "skip": { - "v2": "incomplete value {bar:2} | {bar:2,foo!:string}\n", - "v3": "incomplete value {bar:2} | {bar:2,foo!:string}\n" - } + "valid": true }, { "description": "second anyOf valid (complex)", "data": { "foo": "baz" }, - "valid": true, - "skip": { - "v2": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n", - "v3": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n" - } + "valid": true }, { "description": "both anyOf valid (complex)", diff --git a/encoding/jsonschema/testdata/external/tests/draft4/oneOf.json b/encoding/jsonschema/testdata/external/tests/draft4/oneOf.json index a337e2aafcb..9531b105b73 100644 --- a/encoding/jsonschema/testdata/external/tests/draft4/oneOf.json +++ b/encoding/jsonschema/testdata/external/tests/draft4/oneOf.json @@ -25,11 +25,7 @@ { "description": "both oneOf valid", "data": 3, - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false }, { "description": "neither oneOf valid", @@ -65,11 +61,7 @@ { "description": "both oneOf valid", "data": "foo", - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false } ] }, @@ -107,8 +99,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {bar:2} | {bar:2,foo!:string}\n", - "v3": "incomplete value {bar:2} | {bar:2,foo!:string}\n" + "v3": "invalid value {bar:2} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { @@ -118,8 +109,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n", - "v3": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n" + "v3": "invalid value {foo:\"baz\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { @@ -128,11 +118,7 @@ "foo": "baz", "bar": 2 }, - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false }, { "description": "neither oneOf valid (complex)", @@ -204,11 +190,7 @@ "foo": 1, "bar": 2 }, - "valid": true, - "skip": { - "v2": "incomplete value {foo:1,bar:2} | {foo:1,bar:2,baz!:_}\n", - "v3": "incomplete value {foo:1,bar:2} | {foo:1,bar:2,baz!:_}\n" - } + "valid": true }, { "description": "second valid - valid", @@ -216,11 +198,7 @@ "foo": 1, "baz": 3 }, - "valid": true, - "skip": { - "v2": "incomplete value {foo:1,baz:3,bar!:_} | {foo:1,baz:3}\n", - "v3": "incomplete value {foo:1,baz:3,bar!:_} | {foo:1,baz:3}\n" - } + "valid": true }, { "description": "both valid - invalid", @@ -229,11 +207,7 @@ "bar": 2, "baz": 3 }, - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false } ] }, @@ -268,8 +242,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {bar:8,baz?:_} | {bar:8,foo!:_}\n", - "v3": "incomplete value {bar:8,baz?:_} | {bar:8,foo!:_}\n" + "v3": "invalid value {bar:8} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { @@ -279,8 +252,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {foo:\"foo\",bar!:_,baz?:_} | {foo:\"foo\"}\n", - "v3": "incomplete value {foo:\"foo\",bar!:_,baz?:_} | {foo:\"foo\"}\n" + "v3": "invalid value {foo:\"foo\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { diff --git a/encoding/jsonschema/testdata/external/tests/draft6/additionalItems.json b/encoding/jsonschema/testdata/external/tests/draft6/additionalItems.json index 3943c2ba5cb..b6442fbcd88 100644 --- a/encoding/jsonschema/testdata/external/tests/draft6/additionalItems.json +++ b/encoding/jsonschema/testdata/external/tests/draft6/additionalItems.json @@ -223,8 +223,8 @@ ], "valid": true, "skip": { - "v2": "5 errors in empty disjunction:\nconflicting values [1,null] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,null] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,null] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,null] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,null] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n", - "v3": "conflicting values [1,null] and {...} (mismatched types list and struct):\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,null] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,null] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,null] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,null] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\nincompatible list lengths (1 and 2):\n instance.json:1:1\n" + "v2": "invalid value [1,null] (does not satisfy matchN(1, [null | bool | number | string | [int] | {}])): 0 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n", + "v3": "invalid value [1,null] (does not satisfy matchN(1, [null | bool | number | string | [int] | {}])): 0 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n" } } ] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/allOf.json b/encoding/jsonschema/testdata/external/tests/draft6/allOf.json index 16c231de071..209a5b98a26 100644 --- a/encoding/jsonschema/testdata/external/tests/draft6/allOf.json +++ b/encoding/jsonschema/testdata/external/tests/draft6/allOf.json @@ -39,14 +39,20 @@ "data": { "foo": "baz" }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "mismatch first", "data": { "bar": 2 }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "wrong type", @@ -116,7 +122,10 @@ "bar": 2, "baz": null }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "mismatch second allOf", @@ -124,14 +133,20 @@ "foo": "quux", "bar": 2 }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "mismatch both", "data": { "bar": 2 }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } } ] }, @@ -357,7 +372,10 @@ { "description": "allOf: false, anyOf: true, oneOf: true", "data": 15, - "valid": false + "valid": false, + "skip": { + "v2": "unexpected success" + } }, { "description": "allOf: true, anyOf: false, oneOf: false", diff --git a/encoding/jsonschema/testdata/external/tests/draft6/anyOf.json b/encoding/jsonschema/testdata/external/tests/draft6/anyOf.json index e64af7e590a..3fc55e10678 100644 --- a/encoding/jsonschema/testdata/external/tests/draft6/anyOf.json +++ b/encoding/jsonschema/testdata/external/tests/draft6/anyOf.json @@ -89,11 +89,17 @@ false ] }, + "skip": { + "v3": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:17\n" + }, "tests": [ { "description": "any value is valid", "data": "foo", - "valid": true + "valid": true, + "skip": { + "v3": "could not compile schema" + } } ] }, @@ -106,8 +112,7 @@ ] }, "skip": { - "v2": "extract error: cannot compile resulting schema: 2 errors in empty disjunction:\nexplicit error (_|_ literal) in source:\n generated.cue:2:1\nexplicit error (_|_ literal) in source:\n generated.cue:2:7\n", - "v3": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:1\nexplicit error (_|_ literal) in source:\n generated.cue:2:7\n" + "v3": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:14\n" }, "tests": [ { @@ -115,7 +120,6 @@ "data": "foo", "valid": false, "skip": { - "v2": "could not compile schema", "v3": "could not compile schema" } } @@ -153,22 +157,14 @@ "data": { "bar": 2 }, - "valid": true, - "skip": { - "v2": "incomplete value {bar:2} | {bar:2,foo!:string}\n", - "v3": "incomplete value {bar:2} | {bar:2,foo!:string}\n" - } + "valid": true }, { "description": "second anyOf valid (complex)", "data": { "foo": "baz" }, - "valid": true, - "skip": { - "v2": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n", - "v3": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n" - } + "valid": true }, { "description": "both anyOf valid (complex)", diff --git a/encoding/jsonschema/testdata/external/tests/draft6/oneOf.json b/encoding/jsonschema/testdata/external/tests/draft6/oneOf.json index 9a599a1de38..73f96da2a3e 100644 --- a/encoding/jsonschema/testdata/external/tests/draft6/oneOf.json +++ b/encoding/jsonschema/testdata/external/tests/draft6/oneOf.json @@ -25,11 +25,7 @@ { "description": "both oneOf valid", "data": 3, - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false }, { "description": "neither oneOf valid", @@ -65,11 +61,7 @@ { "description": "both oneOf valid", "data": "foo", - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false } ] }, @@ -187,8 +179,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {bar:2} | {bar:2,foo!:string}\n", - "v3": "incomplete value {bar:2} | {bar:2,foo!:string}\n" + "v3": "invalid value {bar:2} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { @@ -198,8 +189,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n", - "v3": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n" + "v3": "invalid value {foo:\"baz\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { @@ -208,11 +198,7 @@ "foo": "baz", "bar": 2 }, - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false }, { "description": "neither oneOf valid (complex)", @@ -284,11 +270,7 @@ "foo": 1, "bar": 2 }, - "valid": true, - "skip": { - "v2": "incomplete value {foo:1,bar:2} | {foo:1,bar:2,baz!:_}\n", - "v3": "incomplete value {foo:1,bar:2} | {foo:1,bar:2,baz!:_}\n" - } + "valid": true }, { "description": "second valid - valid", @@ -296,11 +278,7 @@ "foo": 1, "baz": 3 }, - "valid": true, - "skip": { - "v2": "incomplete value {foo:1,baz:3,bar!:_} | {foo:1,baz:3}\n", - "v3": "incomplete value {foo:1,baz:3,bar!:_} | {foo:1,baz:3}\n" - } + "valid": true }, { "description": "both valid - invalid", @@ -309,11 +287,7 @@ "bar": 2, "baz": 3 }, - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false } ] }, @@ -348,8 +322,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {bar:8,baz?:_} | {bar:8,foo!:_}\n", - "v3": "incomplete value {bar:8,baz?:_} | {bar:8,foo!:_}\n" + "v3": "invalid value {bar:8} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { @@ -359,8 +332,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {foo:\"foo\",bar!:_,baz?:_} | {foo:\"foo\"}\n", - "v3": "incomplete value {foo:\"foo\",bar!:_,baz?:_} | {foo:\"foo\"}\n" + "v3": "invalid value {foo:\"foo\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { diff --git a/encoding/jsonschema/testdata/external/tests/draft7/additionalItems.json b/encoding/jsonschema/testdata/external/tests/draft7/additionalItems.json index 3943c2ba5cb..b6442fbcd88 100644 --- a/encoding/jsonschema/testdata/external/tests/draft7/additionalItems.json +++ b/encoding/jsonschema/testdata/external/tests/draft7/additionalItems.json @@ -223,8 +223,8 @@ ], "valid": true, "skip": { - "v2": "5 errors in empty disjunction:\nconflicting values [1,null] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,null] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,null] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,null] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,null] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n", - "v3": "conflicting values [1,null] and {...} (mismatched types list and struct):\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,null] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,null] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,null] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,null] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\nincompatible list lengths (1 and 2):\n instance.json:1:1\n" + "v2": "invalid value [1,null] (does not satisfy matchN(1, [null | bool | number | string | [int] | {}])): 0 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n", + "v3": "invalid value [1,null] (does not satisfy matchN(1, [null | bool | number | string | [int] | {}])): 0 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n" } } ] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/allOf.json b/encoding/jsonschema/testdata/external/tests/draft7/allOf.json index 16c231de071..209a5b98a26 100644 --- a/encoding/jsonschema/testdata/external/tests/draft7/allOf.json +++ b/encoding/jsonschema/testdata/external/tests/draft7/allOf.json @@ -39,14 +39,20 @@ "data": { "foo": "baz" }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "mismatch first", "data": { "bar": 2 }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "wrong type", @@ -116,7 +122,10 @@ "bar": 2, "baz": null }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "mismatch second allOf", @@ -124,14 +133,20 @@ "foo": "quux", "bar": 2 }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } }, { "description": "mismatch both", "data": { "bar": 2 }, - "valid": false + "valid": false, + "skip": { + "v3": "unexpected success" + } } ] }, @@ -357,7 +372,10 @@ { "description": "allOf: false, anyOf: true, oneOf: true", "data": 15, - "valid": false + "valid": false, + "skip": { + "v2": "unexpected success" + } }, { "description": "allOf: true, anyOf: false, oneOf: false", diff --git a/encoding/jsonschema/testdata/external/tests/draft7/anyOf.json b/encoding/jsonschema/testdata/external/tests/draft7/anyOf.json index e64af7e590a..3fc55e10678 100644 --- a/encoding/jsonschema/testdata/external/tests/draft7/anyOf.json +++ b/encoding/jsonschema/testdata/external/tests/draft7/anyOf.json @@ -89,11 +89,17 @@ false ] }, + "skip": { + "v3": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:17\n" + }, "tests": [ { "description": "any value is valid", "data": "foo", - "valid": true + "valid": true, + "skip": { + "v3": "could not compile schema" + } } ] }, @@ -106,8 +112,7 @@ ] }, "skip": { - "v2": "extract error: cannot compile resulting schema: 2 errors in empty disjunction:\nexplicit error (_|_ literal) in source:\n generated.cue:2:1\nexplicit error (_|_ literal) in source:\n generated.cue:2:7\n", - "v3": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:1\nexplicit error (_|_ literal) in source:\n generated.cue:2:7\n" + "v3": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:14\n" }, "tests": [ { @@ -115,7 +120,6 @@ "data": "foo", "valid": false, "skip": { - "v2": "could not compile schema", "v3": "could not compile schema" } } @@ -153,22 +157,14 @@ "data": { "bar": 2 }, - "valid": true, - "skip": { - "v2": "incomplete value {bar:2} | {bar:2,foo!:string}\n", - "v3": "incomplete value {bar:2} | {bar:2,foo!:string}\n" - } + "valid": true }, { "description": "second anyOf valid (complex)", "data": { "foo": "baz" }, - "valid": true, - "skip": { - "v2": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n", - "v3": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n" - } + "valid": true }, { "description": "both anyOf valid (complex)", diff --git a/encoding/jsonschema/testdata/external/tests/draft7/oneOf.json b/encoding/jsonschema/testdata/external/tests/draft7/oneOf.json index 9a599a1de38..73f96da2a3e 100644 --- a/encoding/jsonschema/testdata/external/tests/draft7/oneOf.json +++ b/encoding/jsonschema/testdata/external/tests/draft7/oneOf.json @@ -25,11 +25,7 @@ { "description": "both oneOf valid", "data": 3, - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false }, { "description": "neither oneOf valid", @@ -65,11 +61,7 @@ { "description": "both oneOf valid", "data": "foo", - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false } ] }, @@ -187,8 +179,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {bar:2} | {bar:2,foo!:string}\n", - "v3": "incomplete value {bar:2} | {bar:2,foo!:string}\n" + "v3": "invalid value {bar:2} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { @@ -198,8 +189,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n", - "v3": "incomplete value {foo:\"baz\",bar!:int} | {foo:\"baz\"}\n" + "v3": "invalid value {foo:\"baz\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { @@ -208,11 +198,7 @@ "foo": "baz", "bar": 2 }, - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false }, { "description": "neither oneOf valid (complex)", @@ -284,11 +270,7 @@ "foo": 1, "bar": 2 }, - "valid": true, - "skip": { - "v2": "incomplete value {foo:1,bar:2} | {foo:1,bar:2,baz!:_}\n", - "v3": "incomplete value {foo:1,bar:2} | {foo:1,bar:2,baz!:_}\n" - } + "valid": true }, { "description": "second valid - valid", @@ -296,11 +278,7 @@ "foo": 1, "baz": 3 }, - "valid": true, - "skip": { - "v2": "incomplete value {foo:1,baz:3,bar!:_} | {foo:1,baz:3}\n", - "v3": "incomplete value {foo:1,baz:3,bar!:_} | {foo:1,baz:3}\n" - } + "valid": true }, { "description": "both valid - invalid", @@ -309,11 +287,7 @@ "bar": 2, "baz": 3 }, - "valid": false, - "skip": { - "v2": "unexpected success", - "v3": "unexpected success" - } + "valid": false } ] }, @@ -348,8 +322,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {bar:8,baz?:_} | {bar:8,foo!:_}\n", - "v3": "incomplete value {bar:8,baz?:_} | {bar:8,foo!:_}\n" + "v3": "invalid value {bar:8} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { @@ -359,8 +332,7 @@ }, "valid": true, "skip": { - "v2": "incomplete value {foo:\"foo\",bar!:_,baz?:_} | {foo:\"foo\"}\n", - "v3": "incomplete value {foo:\"foo\",bar!:_,baz?:_} | {foo:\"foo\"}\n" + "v3": "invalid value {foo:\"foo\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n" } }, { diff --git a/encoding/jsonschema/testdata/txtar/boolschema.txtar b/encoding/jsonschema/testdata/txtar/boolschema.txtar index 6deb8daa9e7..1b48028bb34 100644 --- a/encoding/jsonschema/testdata/txtar/boolschema.txtar +++ b/encoding/jsonschema/testdata/txtar/boolschema.txtar @@ -1,3 +1,4 @@ +#noverify -- schema.json -- { "anyOf": [ @@ -7,4 +8,4 @@ } -- out/decode/extract -- -_ | _|_ +matchN(>=1, [_, _|_]) diff --git a/encoding/jsonschema/testdata/txtar/emptyobjinanyof.txtar b/encoding/jsonschema/testdata/txtar/emptyobjinanyof.txtar index fb566f4e9a0..0290c9454a2 100644 --- a/encoding/jsonschema/testdata/txtar/emptyobjinanyof.txtar +++ b/encoding/jsonschema/testdata/txtar/emptyobjinanyof.txtar @@ -23,4 +23,4 @@ -- out/decode/extract -- _ -#shell: string | ("bash" | "sh" | "cmd" | "powershell") +#shell: matchN(>=1, [string, "bash" | "sh" | "cmd" | "powershell"]) diff --git a/encoding/jsonschema/testdata/txtar/id_in_oneOf.txtar b/encoding/jsonschema/testdata/txtar/id_in_oneOf.txtar index e9be88abf50..5a2848adb54 100644 --- a/encoding/jsonschema/testdata/txtar/id_in_oneOf.txtar +++ b/encoding/jsonschema/testdata/txtar/id_in_oneOf.txtar @@ -19,10 +19,10 @@ -- out/decode/extract -- @jsonschema(schema="http://json-schema.org/draft-07/schema#") @jsonschema(id="https://test.example/foo") -{ +matchN(1, [{ @jsonschema(id="https://1.test.example/string") string -} | { +}, { @jsonschema(id="https://2.test.example/object") ... -} +}]) diff --git a/encoding/jsonschema/testdata/txtar/issue3176.txtar b/encoding/jsonschema/testdata/txtar/issue3176.txtar index b9d8348c991..232755e0b34 100644 --- a/encoding/jsonschema/testdata/txtar/issue3176.txtar +++ b/encoding/jsonschema/testdata/txtar/issue3176.txtar @@ -18,9 +18,9 @@ -- out/decode/extract -- import "strings" -({ +matchN(1, [{ ... -} | strings.MaxRunes(3)) & (string | { +}, strings.MaxRunes(3)]) & (string | { {[=~"^x-" & !~"^()$"]: string} ... }) diff --git a/encoding/jsonschema/testdata/txtar/issue3351.txtar b/encoding/jsonschema/testdata/txtar/issue3351.txtar index 73b3e9c79e9..b3ef078733a 100644 --- a/encoding/jsonschema/testdata/txtar/issue3351.txtar +++ b/encoding/jsonschema/testdata/txtar/issue3351.txtar @@ -1,3 +1,5 @@ +#noverify +#brokenInV2 -- schema.json -- { "$schema": "https://json-schema.org/draft/2019-09/schema", @@ -62,6 +64,78 @@ "title": "JSON-e templates", "type": "object" } +-- out/decode-v3/extract -- +_schema +_schema: { + // JSON-e templates + @jsonschema(schema="https://json-schema.org/draft/2019-09/schema") + @jsonschema(id="https://www.sourcemeta.com/schemas/vendor/json-e@1.json") + $else?: #["jsone-value"] + $let?: [string]: null | bool | number | string | [...] | { + [string]: _schema + } + $sort?: matchN(>=1, [_schema, [...number]]) + {[!~"^($else|$let|$sort)$"]: #["jsone-value"]} + + #: "jsone-value": matchN(1, [_schema, [..._schema]]) + + #: "jsone-array": [...#["jsone-value"]] + + #: "jsone-object-array": [..._schema] +} +-- diff/-out/decode-v3/extract<==>+out/decode/extract -- +diff old new +--- old ++++ new +@@ -7,10 +7,10 @@ + $let?: [string]: null | bool | number | string | [...] | { + [string]: _schema + } +- $sort?: _schema | [...number] ++ $sort?: matchN(>=1, [_schema, [...number]]) + {[!~"^($else|$let|$sort)$"]: #["jsone-value"]} + +- #: "jsone-value": _schema | [..._schema] ++ #: "jsone-value": matchN(1, [_schema, [..._schema]]) + + #: "jsone-array": [...#["jsone-value"]] + +-- out/decode-v3-noshare/extract -- +_schema +_schema: { + // JSON-e templates + @jsonschema(schema="https://json-schema.org/draft/2019-09/schema") + @jsonschema(id="https://www.sourcemeta.com/schemas/vendor/json-e@1.json") + $else?: #["jsone-value"] + $let?: [string]: null | bool | number | string | [...] | { + [string]: _schema + } + $sort?: matchN(>=1, [_schema, [...number]]) + {[!~"^($else|$let|$sort)$"]: #["jsone-value"]} + + #: "jsone-value": matchN(1, [_schema, [..._schema]]) + + #: "jsone-array": [...#["jsone-value"]] + + #: "jsone-object-array": [..._schema] +} +-- diff/-out/decode-v3-noshare/extract<==>+out/decode/extract -- +diff old new +--- old ++++ new +@@ -7,10 +7,10 @@ + $let?: [string]: null | bool | number | string | [...] | { + [string]: _schema + } +- $sort?: _schema | [...number] ++ $sort?: matchN(>=1, [_schema, [...number]]) + {[!~"^($else|$let|$sort)$"]: #["jsone-value"]} + +- #: "jsone-value": _schema | [..._schema] ++ #: "jsone-value": matchN(1, [_schema, [..._schema]]) + + #: "jsone-array": [...#["jsone-value"]] + -- out/decode/extract -- _schema _schema: { diff --git a/encoding/jsonschema/testdata/txtar/oneOfWithMatchNField.txtar b/encoding/jsonschema/testdata/txtar/oneOfWithMatchNField.txtar new file mode 100644 index 00000000000..b8ab8a57930 --- /dev/null +++ b/encoding/jsonschema/testdata/txtar/oneOfWithMatchNField.txtar @@ -0,0 +1,33 @@ +Check that fields are quoted correctly if they are named after +the matchN builtin. + +-- schema.json -- +{ + "type": "object", + "properties": { + "matchN": { + "oneOf": [ + { + "const": 1 + }, + { + "const": 2 + } + ] + } + } +} +-- out/decode/extract -- +"matchN"?: matchN(1, [1, 2]) +... +-- test/ok1.json -- +{"matchN": 1} +-- test/ok2.json -- +{"matchN": 2} +-- test/err-nomatch.json -- +{"matchN": 3} +-- out/decode/testerr/err-nomatch -- +matchN: invalid value 3 (does not satisfy matchN(1, [1,2])): 0 matched, expected 1: + generated.cue:1:12 + generated.cue:1:19 + test/err-nomatch.json:1:12 diff --git a/encoding/jsonschema/testdata/txtar/type.txtar b/encoding/jsonschema/testdata/txtar/type.txtar index d9384c4ea76..491ab7c0e71 100644 --- a/encoding/jsonschema/testdata/txtar/type.txtar +++ b/encoding/jsonschema/testdata/txtar/type.txtar @@ -39,4 +39,4 @@ object?: { baz: 1.3 ... } -numOrList?: number | [...number] | *[1, 2, 3] +numOrList?: matchN(1, [number, [...number]]) | *[1, 2, 3] diff --git a/encoding/jsonschema/testdata/txtar/typedis.txtar b/encoding/jsonschema/testdata/txtar/typedis.txtar index b276f08c403..82d328f7718 100644 --- a/encoding/jsonschema/testdata/txtar/typedis.txtar +++ b/encoding/jsonschema/testdata/txtar/typedis.txtar @@ -39,7 +39,7 @@ -- out/decode/extract -- // Main schema intOrString1?: int | string -intOrString2?: int | string -intOrString3?: int | string -disjunction?: int | string | int & >=3 +intOrString2?: matchN(1, [int, string]) +intOrString3?: matchN(>=1, [int, string]) +disjunction?: matchN(1, [matchN(>=1, [int, string]), int & >=3]) ... diff --git a/encoding/jsonschema/testdata/txtar/typeexcluded.txtar b/encoding/jsonschema/testdata/txtar/typeexcluded.txtar index a2092b05dad..ffbcea41945 100644 --- a/encoding/jsonschema/testdata/txtar/typeexcluded.txtar +++ b/encoding/jsonschema/testdata/txtar/typeexcluded.txtar @@ -120,11 +120,11 @@ e3?: list.UniqueItems() & [_, ...] & [...strings.MinRunes(1)] e4?: [...string] e5?: int & >=0 e6?: [...=~"^[A-Za-z0-9 _.-]+$"] -e7?: true | { +e7?: matchN(>=1, [true, matchN(1, [{ disableFix?: bool ... -} & { +}]) & { ignoreMediaFeatureNames?: list.UniqueItems() & [_, ...] & [...string] ... -} +}]) ... diff --git a/encoding/jsonschema/testdata/txtar/used.txtar b/encoding/jsonschema/testdata/txtar/used.txtar index 6ddc5e2291b..69554ec1409 100644 --- a/encoding/jsonschema/testdata/txtar/used.txtar +++ b/encoding/jsonschema/testdata/txtar/used.txtar @@ -45,4 +45,4 @@ _ #enum: "a" | "b" | "c" -#lists: "a" | "b" | "c" | (["X"] | ["X", "a" | "b" | "c"] | ["X", "d" | "e" | "f"]) +#lists: matchN(1, ["a" | "b" | "c", matchN(1, [["X"], ["X", "a" | "b" | "c"], ["X", "d" | "e" | "f"]])])