question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nswag CLI generates incorrect DateTime type for C# clients

See original GitHub issue

Hi,

I have below class definition:

public class SomeClass
{
    public DateTime SomeDateTime { get; set; }
}

After generating C# client with below command:

nswag openapi2csclient /runtime:NetCore31 /dateTimeType: 'System.DateTime'

(Other configuration options like URL address, output file name etc. have been ommitted for brevity).

I get an auto-generated client with method definitions containing DateTimeOffset class:

[Newtonsoft.Json.JsonProperty("someDateTime", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
public System.DateTimeOffset SomeDateTime { get; set; }

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
justin-murtaghcommented, Jul 21, 2022

@RicoSuter how do you do that via the command line (as this bug still exists and is technically two bugs)?

1reaction
RicoSutercommented, May 7, 2021

You can configure this:

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

NSwagStudio Generated C# Client Offsets Dates
The DateTime from the serializer will have a DateTimeKind of DateTimeKind.Utc . Unfortunately, comparing that with another DateTime (even of ...
Read more >
Generate TypeScript and C# clients with NSwag based on ...
Learn how to generate TypeScript and C# API clients with NSwag to reduce your workload when building a project.
Read more >
Maintaining API Clients With NSwag Model Generation
Using this CLI, the following command successfully generated the C# models we needed from the OpenAPI models defined in the spec. Command:
Read more >
NSwag – Emil's Lost & Found Archive - Meadow
Net DateTime types for dates rather than DateTimeOffset which NSwag for some reason seems to default to. /GenerateExceptionClasses:false and / ...
Read more >
Auto Generated .NET API Clients using NSwag and ...
This article shows how auto generated code for a C# HTTP API client could be created using Swagger and NSwag . The API...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found