OpenAPITools / OpenAPITools/openapi-generator

[BUG] [C#] [Unity] Exception in ApiClient precludes use of ExceptionFactory

Open
#21,755 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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?
  • 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

In Deserialize in ApiClient, an exception is thrown for any response code outside of the 200 range. However, this precludes usage of the ExceptionFactory which is called into after the response is deserialized.

openapi-generator version

7.12.0

OpenAPI declaration file content or url
Generation Details
Steps to reproduce

Code is generated with these options:
{ "applicationNameOrId", applicationNameOrId },
{ "language", "csharp" },
{ "packageName", Config.packageName },
{ "options", "library=unityWebRequest," +
"optionalEmitDefaultValues=false," +
"nullableReferenceTypes=false," +
"useDateTimeOffset=false," +
"targetFramework=net48," +
"useDateTimeForDate=true" +
"optionalAssemblyInfo=false" +
"optionalProjectFile=false" }

Related issues/PRs
Suggest a fix

We may want to consider simply removing the else here. I'm happy to do this but I'd like validation from someone else first :)

                if (request.responseCode >= 200 && request.responseCode < 300)
                {
                    try
                    {
                        // Deserialize as a model
                        return JsonConvert.DeserializeObject(text, type, _serializerSettings);
                    }
                    catch (Exception e)
                    {
                        throw new UnexpectedResponseException(request, type, e.ToString());
                    }
                }
                else
                {
                    throw new ApiException((int)request.responseCode, request.error, text);
                }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated C# Unity ApiClient Deserialize path and the response-code branch shown in the issue, using the listed generation options to reproduce the behavior. Verify how non-2xx responses interact with ExceptionFactory and consider the issue complete when that factory can be used without the current unconditional exception preventing it.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, unity
Domain
api, game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.