cancel
Showing results for 
Search instead for 
Did you mean: 

nullable and default are not generating as expected in my model

Highlighted
New Contributor

nullable and default are not generating as expected in my model

Good Morning,

 

I'm having difficulty with nullable: false not generating correctly. From everything I can see it is correct. I am wondering if this is applicable to my scenario.

 

https://community.smartbear.com/t5/SwaggerHub/json-schema-validation-of-null-values/m-p/186450#M861

 

Here is the relevant snippet:

isWithdrawalPaused:
   type: boolean
   nullable: false

Which produces:

[DataMember(Name="isWithdrawalPaused")]
public bool? IsWithdrawalPaused { get; set; }

For those not familiar with c# the bool? is a nullable and I want bool.

 

I don't know where the breakdown is and so perhaps it is the engine we are using to interpret the swagger into C#?

swagger-codegen-cli-2.3.0.jar

Any suggestions would be greatly appreciated.

 

TIA

1 REPLY 1
Highlighted
Moderator

Hi @ramjet69,

 

Currently, the C# generator always handles required properties as non-nullable and optional properties as nullable. There's an open issue to improve the nullable logic:

https://github.com/swagger-api/swagger-codegen/issues/2885


Helen Kosova
SmartBear Documentation Team Lead
________________________
Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
New Here?
Join us and watch the welcome video:
Announcements