OpenAPI.NET icon indicating copy to clipboard operation
OpenAPI.NET copied to clipboard

NRE if RequestBody.Extensions is set to null

Open Tasteful opened this issue 4 years ago • 2 comments

The RequestBody.Extensions is initiated with a dictionary but if this is set to null the following line will throw an NullReferenceException that is very hard to track down without any pointer of what the source object it is.

https://github.com/microsoft/OpenAPI.NET/blob/2db9643cdf99ad2135de897a7fcd530da3e2c8b5/src/Microsoft.OpenApi/Models/OpenApiOperation.cs#L260

Tasteful avatar Nov 10 '20 13:11 Tasteful

Extensions is initialized to an empty dictionary so I am assuming this error only happens when someone explicitly sets the Extensions to null. Is there a valid reason for doing this, or should we prevent people from setting extensions to be null?

darrelmiller avatar Dec 13 '20 20:12 darrelmiller

I don't remember why I was setting it to null in the first case, but when I upgraded the OpenAPI package it was a change in the behavior that was hard to track down to this row and I was needing to checkout the source for the OpenAPI package and execute my code with.

Either a proper null-check should be used or the property should throw exception if null-value is set. Removing the property-set is a breaking change so I think that should be avoided.

Tasteful avatar Dec 14 '20 07:12 Tasteful