NSwag
NSwag copied to clipboard
JSON property is missing from schema when using conditional serialization
With a model that has a property that is hidden using ShouldSerialize, e.g:-
public class TestModel
{
public bool Foo { get; set; }
public bool Bar { get; set; }
public bool ShouldSerializeFoo() => false;
}
The schema generated for this model excludes the Foo
property when the model is used as a response (as expected) but it is also excluded when the module is used for a request.
As this Foo
property is only excluded from serialization, and not from deserialization, I would expect it to be present in the schema.
In addition, if the conditional serialization of a property relies on a value that is set only under certain conditions at runtime (and which is not satisifed when NSwag is run), the property is exlcuded from the spec.