[BUG] [CSharp] API client generated with v7.9.0 does not compile on netstandard (regression)
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [ ] Have you validated the input using an OpenAPI validator (example)?
- [ ] Have you tested with the latest master to confirm the issue still exists? Using last release
- [x] Have you searched for related issues/PRs?
- [x] What's the actual output vs expected output? Compilation error
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I'm generating an api client netstandard library, that is supported as stated in the documentation: https://openapi-generator.tech/docs/generators/csharp
After updating the C# generator from v7.8.0 to v7.9.0, the generated code raises this compile-time error at ClientUtils.cs in the Client folder:
error CS0246: The type or namespace name 'DateOnly' could not be found (are you missing a using directive or an assembly reference?)
openapi-generator version
Regression, v7.9.0 (when compiling netstandard2.0 and netstandard2.1 libraries).
OpenAPI declaration file content or url
- Repository to reproduce (at branch
repro-oag-netstandard-regression): https://github.com/javiertuya/samples-openapi/tree/repro-oag-netstandard-regression - The .NET project in this repository is at folder
client-netstandard. - Schema (although it does not have influence on this regression): https://github.com/javiertuya/samples-openapi/blob/repro-oag-netstandard-regression/schema/api.yml
Generation Details
Api and Model generated from a pom.xml with additionalProperties set to: nullableReferenceTypes=false
Change to folder client-netstandard and run mvn generate-sources to generate the api client.
Steps to reproduce
Just run dotnet build from the folder client-netstandard
Related issues/PRs
Not found
Suggest a fix
The compilation error is caused by DateOnlyat the ClientUtils.cs line 103. It is caused by a new statement in v7.9.0, therefore, it would require a different implementation or a new option to generate netstandard compatible code:
if (obj is DateOnly dateOnly)
// Return a formatted date string - Can be customized with Configuration.DateTimeFormat
// Defaults to an ISO 8601, using the known as a Round-trip date/time pattern ("o")
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
// For example: 2009-06-15
return dateOnly.ToString((configuration ?? GlobalConfiguration.Instance).DateTimeFormat);
@javiertuya Question on this one, I don't see where you set the targetFramework for the generator to netstandard2.0/2.1. The default is net8.0 (basing that off of what I'm reading here), and that DateOnly branch is placed in a conditional of {{#net60OrLater}} in the template file so if you don't specify the target framework it will be included.
@alec-petersen Thank you for the advice. I tested with the targetFramework setting and it works.
The issue can be closed, it was a false positive. Thank you for your work.
You're welcome!