OpenAPITools / OpenAPITools/openapi-generator
[BUG] [csharp] [unityWebRequest] The type of Timeout is not int, causing an error.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- 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?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When generating code using openapi-generator-cli-7.11.0.jar with the language set to C#, the library set to unityWebRequest, and targetFramework set to netstandard2.1, the following error occurs in ApiClient.cs.
<html>Cannot apply operator '>' to operands of type 'System.TimeSpan' and 'int',<br/>candidates are:<br/>bool operator >(System.TimeSpan, System.TimeSpan) (in struct TimeSpan)
<html>Cannot resolve method 'Ceiling(System.TimeSpan)', candidates are:<br/>decimal Ceiling(decimal) (in class Math)<br/>double Ceiling(double) (in class Math)
The config.json at that time was as follows.
{
"apiPackage": "Routes",
"packageName": "App.Server.Api.Generated",
"optionalAssenblyInfo": false,
"optionalProjectFile": false,
"targetFramework": "netstandard2.1",
"library": "unityWebRequest",
"validatable": false,
"sourceFolder": ""
}
By the way, when generating code in the same way using openapi-generator-cli-7.9.0.jar, the error did not occur.
Comparing the code generated by version 7.11.0 with that generated by version 7.9.0, the following differences were found.
Client/Configuration.cs
- Timeout = 100000;
+ Timeout = TimeSpan.FromSeconds(100);
Client/IReadableConfiguration.cs
+ /// Gets the HTTP connection timeout.
- /// Gets the HTTP connection timeout (in milliseconds)
/// </summary>
/// <value>HTTP connection timeout.</value>
+ TimeSpan Timeout { get; }
- int Timeout { get; }
Presumably, in version 7.9.0, Timeout was of type int, but in version 7.11.0, it changed to TimeSpan. As a result, an error occurs in code using comparison operators like if (configuration.Timeout > 0).
openapi-generator version
7.11.0
OpenAPI declaration file content or url
Generation Details
java -jar bin/openapi-generator-cli-7.11.0.jar generate -i gen/openapi.yaml -g csharp -c config.json -o tmp --global-property modelTests=false,apiTests=false
config.json
{
"apiPackage": "Routes",
"packageName": "App.Server.Api.Generated",
"optionalAssenblyInfo": false,
"optionalProjectFile": false,
"targetFramework": "netstandard2.1",
"library": "unityWebRequest",
"validatable": false,
"sourceFolder": ""
}
Steps to reproduce
- generate OpenAPI client
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided openapi-generator-cli 7.11.0 command and config.json, then inspect the generated Client/Configuration.cs, Client/IReadableConfiguration.cs, and ApiClient.cs for the Timeout type mismatch. Compare the output with version 7.9.0 to locate the affected C# unityWebRequest generation path. Done means the generated netstandard2.1 client compiles without the reported TimeSpan comparison and Math.Ceiling errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100