First of all thanks for a great library. Worthy of being part of STJ itself.
Using OptionalValues.Swashbuckle I found nullability to not being output for parameters (in swagger.json) . I then tried OptionalValues.OpenApi which do behave as expected.
Example code that reproduces the issue
public record UserUpdateRecord(Guid UserId)
{
public OptionalValue<string?> Name { get; set; }
public OptionalValue<string?> Email { get; set; }
}
[HttpPut]
public async Task<ActionResult<UserResponse>> UpdateUser(UserUpdateRecord userUpdateRecord)
{
...
}
Code difference OptionalValues.OpenApi vs OptionalValues.Swashbuckle
There is a difference in the source code with regards to handling of parameters and nullability. Perhaps that is the source of the issue, see code below.
OptionalValues.OpenApi
|
private static NullabilityInfo? GetNullabilityInfo(ICustomAttributeProvider memberInfo) |
|
{ |
|
var nullabilityInfoContext = new NullabilityInfoContext(); |
|
return memberInfo switch |
|
{ |
|
PropertyInfo propertyInfo => nullabilityInfoContext.Create(propertyInfo), |
|
FieldInfo fieldInfo => nullabilityInfoContext.Create(fieldInfo), |
|
ParameterInfo parameterInfo => nullabilityInfoContext.Create(parameterInfo), |
|
_ => null, |
|
}; |
|
} |
OptionalValues.Swashbuckle
|
private static NullabilityInfo? GetNullabilityInfo(MemberInfo memberInfo) |
|
{ |
|
var nullabilityInfoContext = new NullabilityInfoContext(); |
|
|
|
return memberInfo switch |
|
{ |
|
PropertyInfo propertyInfo => nullabilityInfoContext.Create(propertyInfo), |
|
FieldInfo fieldInfo => nullabilityInfoContext.Create(fieldInfo), |
|
_ => null, |
|
}; |
First of all thanks for a great library. Worthy of being part of STJ itself.
Using
OptionalValues.SwashbuckleI found nullability to not being output for parameters (in swagger.json) . I then triedOptionalValues.OpenApiwhich do behave as expected.Example code that reproduces the issue
Code difference OptionalValues.OpenApi vs OptionalValues.Swashbuckle
There is a difference in the source code with regards to handling of parameters and nullability. Perhaps that is the source of the issue, see code below.
OptionalValues.OpenApi
OptionalValues/src/OptionalValues.OpenApi/OptionalValuesSchemaTransformer.cs
Lines 121 to 131 in 41e4686
OptionalValues.Swashbuckle
OptionalValues/src/OptionalValues.Swashbuckle/OptionalValueDataContractResolver.cs
Lines 93 to 102 in 41e4686