You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am on .Net 7 with nullable enable and on the following reporducer i do not get my property PnlGenerated mark as nullable inside the generated OpenApi specification.
The swassbuckle configuration :
options.SchemaFilter<RequireAllPropertiesPropertiesSchemaFilter>();
options.SupportNonNullableReferenceTypes();
options.MapType<DateOnly>(() => new OpenApiSchema { Type = "string", Format = "date" });
}
}
public sealed class RequireAllPropertiesPropertiesSchemaFilter : ISchemaFilter
{
/// <summary>
/// Add to model.Required all properties where Nullable is false.
/// </summary>
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
var additionalRequiredProps = schema.Properties
.Where(x => !schema.Required.Contains(x.Key))
.Select(x => x.Key);
foreach (var propKey in additionalRequiredProps)
{
schema.Required.Add(propKey);
}
}
}
the Controller and its DTO :
[HttpPost(
"xxx")]
[ProducesResponseType(typeof(ComputedPeriodDto), StatusCodes.Status200OK)]
[SwaggerOperation(OperationId = "ComputePeriodForConvertToForecast")]
public async Task<ActionResult<ComputedPeriod>> ComputePeriodForConvertToForecast(
[FromRoute, Required] int companyId, [FromRoute, Required] Guid pnlId, [FromBody] ConvertToForecastDto dto)
{
var conversionPeriod = xxx;
return this.Ok(conversionPeriod.MapToDto());
}
}
public sealed record ConvertToForecastDto(int? ScenarioId, bool GenerateForecastInPast = false);
public sealed record ComputedPeriodDto(
PeriodDto? PnlGenerated, [property: JsonRequired] PeriodDto PnlFile);
public sealed record PeriodDto([property: JsonRequired] DateOnly StartDate, [property: JsonRequired] DateOnly EndDate);
To make issue tracking a bit less overwhelming for the new maintainers (see #2778), I've created a new tracking issue to roll-up various nullability issues here: #2793.
We'll refer back to this issue from there and include it as part of resolving that issue, but I'm going to close this one to help prune the backlog.
Hello ,
I am on .Net 7 with nullable enable and on the following reporducer i do not get my property PnlGenerated mark as nullable inside the generated OpenApi specification.
The swassbuckle configuration :
the Controller and its DTO :
Generate for ComputedPEriodDto :
I would have expect to see :
The text was updated successfully, but these errors were encountered: