swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Nullable int is with a default value of null is still getting POST with Zero

Open Emrikol01 opened this issue 2 years ago • 2 comments

In my model I have the following definied:

[DefaultValue(null)] public int? MyAttrId { get; set; }

When swagger is opened the generated json shows as "MyAttrid" : 0

I had expected "MyAttrid" : null

The Post to my endpoint controller has default Zero when Null was expected.

Is there a setting or another attribute available to fix this?

Emrikol01 avatar Aug 16 '22 13:08 Emrikol01

In my model I have the following definied:

[DefaultValue(null)] public int? MyAttrId { get; set; }

When swagger is opened the generated json shows as "MyAttrid" : 0

I had expected "MyAttrid" : null

The Post to my endpoint controller has default Zero when Null was expected.

Is there a setting or another attribute available to fix this?

Please post the generated swagger json.

mathis-m avatar Sep 04 '22 00:09 mathis-m

I cannot post my swagger or code on here, the company I work for is extremely sensitive about this. On the hand we are allowed to use tools like Postman /shrug

I can say when I import swagger openapi.json into Postman the models are correctly displayed. For example: if I open one of the POST actions to add a new entity then "MyAttrid" : null and not zero. This works as expected. I have recommended to the tester that they 'test' via Postman and not via the swagger UI. thanks

Emrikol01 avatar Sep 13 '22 11:09 Emrikol01

Could you share just the part of the generated schema with only the number in it. Or look at the schema and create a minimal reproduction schema definition.

mathis-m avatar Oct 07 '22 18:10 mathis-m