autorest icon indicating copy to clipboard operation
autorest copied to clipboard

Compatibility: Does the client include a property that has a null value?

Open msfcolombo opened this issue 11 months ago • 3 comments

If I add a new foo property with type integer and x-nullable: true in the Swagger definition, will the generated client send "foo": null in the request payload? Or will foo be absent from the payload?

The reason I'm asking is that I'm not sure if existing server versions will tolerate an extraneous property with an explicit null in the payload.

msfcolombo avatar Mar 25 '24 21:03 msfcolombo

Do you want to describe optional properties or nullable? x-nullable will technically mean you can set it to null over the wire. For optional properties they should just not be part of teh required: [] array

timotheeguerin avatar Mar 25 '24 23:03 timotheeguerin

Do you want to describe optional properties or nullable? x-nullable will technically mean you can set it to null over the wire. For optional properties they should just not be part of teh required: [] array

The property is both optional and nullable.

msfcolombo avatar Mar 26 '24 20:03 msfcolombo

By that you mean in your backend or over the wire? From your original message you said you are not sure if null would be accepted over the wire.

If you are doing a CSharp server that use null to represent optionality then what you want is to define the property as optional. Nullable properties should be extremely rare and only used in case like json merge patch for Microsoft services.

timotheeguerin avatar Mar 26 '24 21:03 timotheeguerin