RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.4k stars 535 forks source link

Nullable AdditionalProperties? #1543

Closed ackginger closed 2 years ago

ackginger commented 2 years ago

I can't figure out a way to specify this in an OpenApi schema, but would really like the generated C# code for AdditionalProperties to go from this:

        private System.Collections.Generic.IDictionary<string, object> _additionalProperties = new System.Collections.Generic.Dictionary<string, object>();

        [System.Text.Json.Serialization.JsonExtensionData]
        public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
        {
            get { return _additionalProperties; }
            set { _additionalProperties = value; }
        }

to this:

        private System.Collections.Generic.IDictionary<string, object>? _additionalProperties = default!;

        [System.Text.Json.Serialization.JsonExtensionData]
        public System.Collections.Generic.IDictionary<string, object>? AdditionalProperties
        {
            get { return _additionalProperties; }
            set { _additionalProperties = value; }
        }

Specifically to stop masses of unnecessary allocations when there are no additional properties. Would you accept an MR for this as an opt in feature?