Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change NSwagStudio serialization setting to allow for Nulls

Tags:

nswagstudio

Is there a way to change the settings in NSwagStudio so that when the JSON serialization setting outputs as Newtonsoft.Json.Required.AllowNull instead of Newtonsoft.Json.Required.Always?

I currently have the property manually changed to allow for nulls.

[Newtonsoft.Json.JsonProperty("returnCode", Required = Newtonsoft.Json.Required.Always)]
public int ReturnCode { get; set; }

And I need it to be:

[Newtonsoft.Json.JsonProperty("returnCode", Required = Newtonsoft.Json.Required.AllowNull)]
public int ReturnCode { get; set; }
like image 303
Wesley von Graevenitz Avatar asked Oct 19 '25 03:10

Wesley von Graevenitz


1 Answers

It will not be nullable inside the generated code if it is not nullable at the API-spec

API spec example:

    ReturnCode:
      type: integer
      nullable: true
like image 186
Dennis Meissel Avatar answered Oct 22 '25 07:10

Dennis Meissel