Skip to content
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

Serialize trait on ValidationState does not produce the expected output #88

Closed
bcheidemann opened this issue Feb 4, 2023 · 0 comments · Fixed by #89
Closed

Serialize trait on ValidationState does not produce the expected output #88

bcheidemann opened this issue Feb 4, 2023 · 0 comments · Fixed by #89

Comments

@bcheidemann
Copy link
Contributor

Hi,

I'm hoping to return the ValidationState struct from a Rust Node API using serde_wasm_bindgen. However, the struct does not serialize how I would expect it to.

println!("state = {state:#?}");
let json = serde_json::to_string(&state).unwrap();
println!("state (json) = {}", json);
let json = serde_json::to_string(&state.errors.get(0).unwrap()).unwrap();
println!("error (json) = {}", json);
let json = serde_json::to_string(&state.errors.get(0).unwrap().downcast::<OneOf>()).unwrap();
println!("error_downcast (json) = {}", json);

The above code produces the following output (formatted):

state = ValidationState {
  errors: [
      OneOf {
          path: "/jobs/example_job",
          states: [
              ValidationState {
                  errors: [
                      Required {
                          path: "/jobs/example_job/runs-on",
                      },
                  ],
                  missing: [],
                  replacement: None,
                  evaluated: {
                      "/jobs/example_job/steps/0",
                      "/jobs/example_job/steps/0/name",
                      "/jobs/example_job/steps",
                      "/jobs/example_job",
                      "/jobs/example_job/steps/0/with/submodules",
                      "/jobs/example_job/steps/0/uses",
                      "/jobs/example_job/steps/0/with",
                  },
              },
              ValidationState {
                  errors: [
                      Properties {
                          path: "/jobs/example_job",
                          detail: "Additional property 'steps' is not allowed",
                      },
                      Required {
                          path: "/jobs/example_job/uses",
                      },
                  ],
                  missing: [],
                  replacement: None,
                  evaluated: {
                      "/jobs/example_job",
                  },
              },
          ],
      },
  ],
  missing: [],
  replacement: None,
  evaluated: {
      "/on/pull_request/branches",
      "/on/pull_request",
      "/on/pull_request/branches/0",
      "/name",
      "/on",
      "",
      "/jobs",
  },
}

state (json) = {
  "errors": [
    {
      "code": "one_of",
      "path": "/jobs/example_job",
      "title": "OneOf conditions are not met"
    }
  ],
  "missing": []
}

error (json) = {
  "code": "one_of",
  "path": "/jobs/example_job",
  "title": "OneOf conditions are not met"
}

error_downcast (json) = {
  "code": "one_of",
  "path": "/jobs/example_job",
  "states": [
    {
      "errors": [
        {
          "code": "required",
          "path": "/jobs/example_job/runs-on",
          "title": "This property is required"
        }
      ],
      "missing": []
    },
    {
      "errors": [
        {
          "code": "properties",
          "detail": "Additional property 'steps' is not allowed",
          "path": "/jobs/example_job",
          "title": "Property conditions are not met"
        },
        {
          "code": "required",
          "path": "/jobs/example_job/uses",
          "title": "This property is required"
        }
      ],
      "missing": []
    }
  ],
  "title": "OneOf conditions are not met"
}

Note that the "states" field is missing from the serialized error unless it is downcast.

Is this the expected/intended behaviour?

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

Successfully merging a pull request may close this issue.

1 participant