-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
string with format date
is generated as DateTimeOffset
but should be DateOnly
#240
Comments
You have option to customize the serialization |
@Thorium thanks - that feels more like a workaround though, since the client generated by the provider creates API calls that are wrong according to the schema. I have taken a look at the C# client that gets generated by NSwag for the same schema, and while they also use [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.3.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")]
internal class DateFormatConverter : Newtonsoft.Json.Converters.IsoDateTimeConverter
{
public DateFormatConverter()
{
DateTimeFormat = "yyyy-MM-dd";
}
} which then decorates the fields that are marked via |
Here is the place where we define a type for Here is the code that add a custom attribute to the generated property |
The offset (with time-zone) is a bit weird guy with "date" as there is no time-zone conversions and SwaggerProvider is a server-side tool where you'd expect everything to be UTC. If you want, you could do line 411 conditional compilation something like | "date" ->
#if NETSTANDARD2.1
typeof<DateOnly>
#else
typeof<DateTime>
#endif ...but that could make the maintenance more complex than the real gain. Because the end-user may compile the same SwaggerProvider using source-code to multiple targets too, and then they would have to also do conditional compilations. |
Type inference code ( I am not sure if it is possible to conditionally check the target compilation runtime for the TP design-time component. |
oh right it goes straight to the problem where VS Code runs on netstandard2.1 and VS full runs on netstandard 2.0 |
What if there were a switch for the Provider where the user can decide if Date is a DateTimeOffset or a DateOnly? |
Description
Hi there, thanks for this awesome library.
I have a ASP.NET core API that uses the
DateOnly
type for a field, which looks like this in the generated OpenAPI doc:From the docs of the OpenAPI spec,
"format": "date"
indicates:But the OpenAPI provider sets the field type as
DateTimeOffset
in the generated spec. This only works when parsing responses, but fails when posting data with this field to the API, because it cannot parse the provided string toDateOnly
:Is this happening because you also want to target
netstandard2.0
? IIRCDateOnly
is available starting withnet6.0
.Affected Type Providers
Related information
The text was updated successfully, but these errors were encountered: