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
Moderator

Re: nullable and default are not generating as expected in my model

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 Technical Writer
________________________
Vote up helpful replies.
Accept this reply if you think it's the best solution to your question.
New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video