NSwag generating primitive fields as Nullable
Asked Answered
J

0

7

I have a RESTful WebAPI 2 service in C# and I am using swagger as API descriptor. Now, on the client side I am using NSwag which can be found here to generate client side code: https://github.com/RSuter/NSwag

Now, I have been using nSwag for more than a year and I am seeing this behavior for the first time not sure if something in my code is causing it or NSwag itself is acting up but when I generated client using nSwag, it generates int fields which are marked [Required] as Nullable properties on the client side. Which may looks like below on the service side:

[Required]
[Range(1, Int32.MaxValue, ErrorMessage = "GenTrainId must be greater than 0")]
public int MyField { get; set; } 

However, when I generate it on the client side, it looks something like below:

 [Newtonsoft.Json.JsonProperty("genTrainId", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        [System.ComponentModel.DataAnnotations.Range(1, 2147483647)]
        public int? GenTrainId
        {
            get { return _genTrainId; }
            set 
            {
                if (_genTrainId != value)
                {
                    _genTrainId = value; 
                    RaisePropertyChanged();
                }
            }
        }

I have no idea what part of my service side code is telling NSwag to translate it as a NUllable property when it is clearly a required Non-Nullable property on the service side. Am I missing anything?

Jailhouse answered 21/6, 2018 at 17:37 Comment(2)
This looks like a bug, can you create an issue on github with a repro?Antidote
Was this ever resolved? I'm getting this.Preform

© 2022 - 2024 — McMap. All rights reserved.