Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

C# port should enforce missing fields in Json deserialization #2314

Closed
stishkin opened this issue Aug 29, 2022 · 1 comment · Fixed by #2328
Closed

C# port should enforce missing fields in Json deserialization #2314

stishkin opened this issue Aug 29, 2022 · 1 comment · Fixed by #2328
Assignees
Labels
bug Something isn't working

Comments

@stishkin
Copy link
Contributor

stishkin commented Aug 29, 2022

POSTing following JSON to Pool APIs in C#

{
  "name": "FT-DELETE-4812d4da-a9ab-40e1-88f1-2d9e148254fa",
  "oss": "linux",
  "arch": "x86_64",
  "managed": true
}

with typo for "OS" will succeed with setting OS to Windows

Meanwhile Python endpoint fails creation with error:

{"code": 450, "errors": ["os: field required"]}

ORM must enforce that all fields are present

AB#41119374

@stishkin stishkin added the bug Something isn't working label Aug 29, 2022
@ghost ghost added the Needs: triage label Aug 29, 2022
@Porges
Copy link
Member

Porges commented Aug 30, 2022

Not currently possible, according to documentation:

System.Text.Json ignores extra properties in the JSON, except when you use the [JsonExtensionData] attribute. There's no workaround for the missing member feature.

One option is that we add [JsonExtensionData] to a BaseRequest and then assert it is empty.

Porges added a commit that referenced this issue Sep 2, 2022
…null properties are [Required] (#2328)

Closes #2314 via two fixes, one for additional properties and one for missing properties:

- Make all request types inherit from `BaseRequest` which has an `ExtensionData` property, and ensure that it is empty in `ParseRequest`.
- Add `[Required]` attribute to non-nullable properties that do not have defaults, and add a test that ensures we have this attribute where necessary.
@ghost ghost locked as resolved and limited conversation to collaborators Oct 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
3 participants