Skip to content

JSON validation regression #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JBBianchi opened this issue Mar 28, 2025 · 3 comments
Open

JSON validation regression #260

JBBianchi opened this issue Mar 28, 2025 · 3 comments
Assignees

Comments

@JBBianchi
Copy link

JBBianchi commented Mar 28, 2025

Type: Bug

Description

When opening a JSON file with the following content in VSCode, incorrect validation errors appear:

{
  "$schema": "https://raw.githubusercontent.com/serverlessworkflow/serverlessworkflow.github.io/main/public/schemas/1.0.0/workflow.json",
  "document": {
    "dsl": "1.0.0",
    "namespace": "default",
    "name": "sample-workflow",
    "version": "0.1.0"
  },
  "do": [
    {
      "step1": {
        "set": {
          "someVariable": "someValue"
        }
      }
    }
  ]
}

Expected Behavior

VSCode should validate the JSON file correctly based on the provided schema. This file is valid.

Actual Behavior

L11 will display the following validation errors:

Missing property "call".
Missing property "with".
TaskBase

An object inherited by all tasks.

L12 will display the following validation error:

Property set is not allowed.

Image

Additional Notes

I had the validation working in a web project using Monaco Editor. So I went to the Monaco Playground to make some experiments. It seems that version 0.49.0 was validating the JSON file properly, but starting at version 0.50.0, the current behavior appeared.

Image

System Info

VS Code version: Code 1.98.2 (ddc367ed5c8936efe395cffeec279b04ffd7db78, 2025-03-12T13:32:45.399Z)
OS version: Windows_NT x64 10.0.22631
Modes:

System Info
Item Value
CPUs 12th Gen Intel(R) Core(TM) i9-12900K (24 x 3187)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 63.75GB (46.55GB free)
Process Argv --folder-uri file:///c%3A/Users/JB/Desktop/test_sw --crash-reporter-id fe8b96b2-7bbd-404b-b580-3408ff2b375e
Screen Reader no
VM 0%
Extensions (1)
Extension Author (truncated) Version
gitlens eam 16.3.3
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
binariesv615:30325510
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dwnewjupytercf:31046870
nativerepl1:31139838
pythonrstrctxt:31112756
nativeloc1:31192215
iacca1:31171482
5fd0e150:31155592
dwcopilot:31170013
6074i472:31201624
dwoutputs:31242946
customenabled:31248079
hdaa2157:31222309
copilot_t_ci:31222730
850i5325:31264362
968h8231:31271074
jda6j935:31233686
pythoneinst12cf:31262606
bgtreat:31268568
fh1c7952:31258891
4gafe986:31271826
31787653:31262186
3e8i5726:31271747
80860236:31264450
49da9784:31264548

@aeschli
Copy link
Collaborator

aeschli commented Mar 31, 2025

Here is what I see with the latest VS Code and he current content of https://raw.githubusercontent.com/serverlessworkflow/serverlessworkflow.github.io/main/public/schemas/1.0.0/workflow.json

I don't think the content is valid:
do takes a array of tasks:

"oneOf": [
{
"$ref": "#/$defs/callTask"
},
{
"$ref": "#/$defs/doTask"
},
{
"$ref": "#/$defs/forkTask"
},
{
"$ref": "#/$defs/emitTask"
},
{
"$ref": "#/$defs/forTask"
},
{
"$ref": "#/$defs/listenTask"
},
{
"$ref": "#/$defs/raiseTask"
},
{
"$ref": "#/$defs/runTask"
},
{
"$ref": "#/$defs/setTask"
},
{
"$ref": "#/$defs/switchTask"
},
{
"$ref": "#/$defs/tryTask"
},
{
"$ref": "#/$defs/waitTask"
}
]

and each of these tasks has required attributes. step1 is not one of them.

The implementation picks one alternative and reports these errors as hints.

@JBBianchi
Copy link
Author

JBBianchi commented Mar 31, 2025

@aeschli thank you for your feedback.

The schema is quite complex, but if I'm not mistaken, do doesn't take an array of tasks, but rather a map<string, task>:

    "do": {
      "$ref": "#/$defs/taskList",
      "title": "Do",
      "description": "Defines the task(s) the workflow must perform."
    },

Where taskList is:

    "taskList": {
      "title": "TaskList",
      "description": "List of named tasks to perform.",
      "type": "array",
      "items": {
        "type": "object",
        "title": "TaskItem",
        "minProperties": 1,
        "maxProperties": 1,
        "additionalProperties": {
          "$ref": "#/$defs/task"
        }
      }
    },

In other words, an array of objects with only 1 property of type task.

@aeschli
Copy link
Collaborator

aeschli commented Mar 31, 2025

We do not properly support https://json-schema.org/draft/2020-12/schema

The schema does something problematic here: Besides a $ref, it adds additional properties, such as properties which also exist im the referenced object.
My understanding is that this will lead to unspecified behavior. In draft-7 this was forbidden
In newer drafts its up to the application (validator) how to handle: https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.7.7.1.1

        {
          "title": "CallAsyncAPI",
          "description": "Defines the AsyncAPI call to perform.",
          "$ref": "#/$defs/taskBase",
          "type": "object",
          "required": [
            "call",
            "with"
          ],
          "unevaluatedProperties": false,
          "properties": {
            "call": {
              "type": "string",
              "const": "asyncapi"
            },

Looks like we have a bug. I suspect we overwrite "properties": { with what's in taskBase

To avoid the unspecified behaviour I would recommend to use this notation:

  "allOf": [
    { "$ref": "#/definitions/baseSchema" },
    {
      "properties": {
        "additionalField": { "type": "string" }
      }
    }
  ]

@aeschli aeschli transferred this issue from microsoft/vscode Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants