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

[Discuss]: How do we handle optional flattened property? #5101

Closed
archerzz opened this issue Oct 9, 2024 · 1 comment
Closed

[Discuss]: How do we handle optional flattened property? #5101

archerzz opened this issue Oct 9, 2024 · 1 comment

Comments

@archerzz
Copy link
Member

archerzz commented Oct 9, 2024

Problem

This is derived from comment here. Consider the following scenario of property flattening.

model Foo {
  name: string;

  @flattenProperty
  properties?: B; // optional property to be flattened
}

model Bar {
  a: int; // required
  b?: int; // optional
}

In M4, both Bar.a and Bar.b will be flattened into Foo and will all be optional. That is, the expected CSharp model codes should be like.

public partial class Foo
{
    public string Name { get; set; }
    public int? A { get; set; }
    public int? B { get; set; }
}

However, that will have a few problems.

  1. If we change A to be optional, then our serialization logic doesn't check if both A and B are null, before writing value of properties. We should skip properties if both A and B are null.
  2. If we change A to be optional, how do we enforce it must be set if any other property on the same level is set? Like, a customer sets foo.B = 12, but leaves foo.A to be null.
    a. Check A during serialization, which will surprise users since A is int?.
    b. Don't check, wait for the server side to return error, which will still surprise users.
  3. If we choose to maintain the original optionality, then how do we give users a way to unset properties?
@archerzz
Copy link
Member Author

close since this issue has existed for quite a long time, and we only allow model flattening in brown field SDKs.

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

1 participant