MLogdberg / APIManagementARMTemplateCreator

Azure API Management Template Extractor, extracts ARM templates for your API's to be used in the CI/CD process.
MIT License
45 stars 43 forks source link

Fix param null check #109

Closed chrismansfield closed 3 years ago

chrismansfield commented 3 years ago

A recent change seems to have broken the null check for property values for parameters. When not using the service url of an API, we still get a serviceUrl parameter with a default value of null. This requires us to supply a value, even though it should just be null.

The change that broke this changed the null check of property values. In order to fully understand why this failed I tested JObject as follows:

   var jObject = JObject.Parse("{\"test\": null}");

   var jValueIsNull = jObject["test"] == null; // JValue
   var stringIsNull = (string)jObject["test"] == null; // null
   var toStringIsNull = jObject["test"].ToString() == null; // ""

   Console.WriteLine(jValueIsNull); // False
   Console.WriteLine(stringIsNull); // True
   Console.WriteLine(toStringIsNull); // False

To summarize, a JValue object encapsulating a null value is not null, but casting it will return null if the value is null. ToString will return an empty string.