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

Use of imprecise data types bool instead of bool?

Open AP-G opened this issue 5 years ago • 1 comments

Among other things I am using the this component to convert between the different API versions and representations. Unfortunately some information gets lost, especially with some boolean values.

The reason is that some properties are currently modelled as bool instead of bool? it cannot be differentiated, if a value was set before or not. In the writer-Source it is solved by hardcoding default-values and ommitting the write step if the boolean value and the default value are equal. While this works well for the writer this information gets lost in the global objects and cannot be used in other tools. Or the hard-codings have to be re-done.

It would be much nicer to replace the bool by bool? and add a function for getting the default value, if not set. This way the default values need only to be implemented once and the information is not lost. It is even possible to create a backwards-compatible version returning a bool with the default value if the bool? is null...

For example in OpenApiSchema bool? is used several times like with UniqueItems

Only bool is used at least for the following properties:

OpenApiParameter.AllowReserved
OpenApiParameter.AllowEmptyValue
OpenApiParameter.Deprecated
OpenApiParameter.Explode
OpenApiParameter.Required

OpenApiHeader.AllowReserved
OpenApiHeader.AllowEmptyValue
OpenApiHeader.Deprecated
OpenApiHeader.Explode
OpenApiHeader.Required

OpenApiRequestBody.Required

OpenApiSchema.AdditionalPropertiesAllowed
OpenApiSchema.Nullable
OpenApiSchema.Deprecated
OpenApiSchema.ReadOnly
OpenApiSchema.WriteOnly

AP-G avatar Sep 04 '20 19:09 AP-G

Hey @AP-G thanks for raising this issue. How about if we implemented IsXXXDefault functions for all properties that have a non-null default?

darrelmiller avatar Sep 27 '20 23:09 darrelmiller