kiota icon indicating copy to clipboard operation
kiota copied to clipboard

Possible dropping or missing properties during model interface object to class instance mapping

Open nikithauc opened this issue 3 years ago • 1 comments

The current design of TypeScript maps a request body object to the model class at the time of request as follows:

interface User { name: string } const user: User = { name: "xyz" }

const createdUser = await clients.users.post(user); In the post function, the user object is mapped to a new UserImpl model class instance. This implementation detail is abstracted from the user.

If the user adds a property to the request body that does not exist in the generated model interface, example const user = {name : "xyz", someNewProp : 123232 }, or a custom class with additional properties implementing the model class, then new properties will not be mapped and not forwarded to the API. This would be ambiguous to the user not aware of the implementation detail.

nikithauc avatar Jun 23 '22 06:06 nikithauc

Here we could do two things:

  • In the Serialization Writer implementation, write object value, for any property we find that hasn't been written, stuff it into the additional data manager (before we write the additional data)
  • Just warn based on observability, pending on #618

No matter what, if the property is a complex type that doesn't implement parsable, the serialization code won't know what to do, and this will be a best effort.

baywet avatar Jun 23 '22 17:06 baywet

I don't believe this is relevant anymore with the approach we have we interfaces now. Closing.

baywet avatar Apr 26 '23 15:04 baywet