OpenAPITools / OpenAPITools/openapi-generator

[BUG][CSHARP] .NET Framework 3.5. Build errors in generated project.

Open
#9,959 0 comments 0 reactions 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 (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

There is build error while generating C # .net framework 3.5 project from swagger json.
The generated code below uses overload for the string.Join(",", x.Value)) method that takes string and object arguments,
but in .NET Framework 3.5 there is such overload (https://docs.microsoft.com/en-us/dotnet/api/system.string.join?view=netframework-3.5). This causes build errors.

return new ApiResponse<Category>(localVarStatusCode,
    localVarResponse.Headers.ToDictionary(x => x.Name, x => string.Join(",", x.Value)),
    (Category) this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(Category)));
openapi-generator version

5.0.0-beta3

OpenAPI declaration file content or url
"get": {
        "tags": [
          "Category"
        ],
        "summary": "",
        "operationId": "GetCategoryAsync",
        "consumes": [],
        "produces": [
          "text/plain",
          "application/json",
          "text/json",
          "application/xml",
          "text/xml"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "",
            "schema": {
              "$ref": "#/definitions/Category"
            }
          },
          "500": {
            "description": ""
          }
        }
      },
Generation Details

generation command for powershell :

java -jar .\openapi-generator\modules\openapi-generator-cli\target\openapi-generator-cli.jar generate `
  -i $baseUrl `
  -g csharp `
  -o $output `
  --additional-properties packageName=$packageName `
  --additional-properties targetFramework=v3.5
Suggest a fix

Use another overload for method string.Join()
For example: https://docs.microsoft.com/en-us/dotnet/api/system.string.join?view=netframework-3.5#System_String_Join_System_String_System_String___

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 C# generator entry point used by the provided Java CLI command and trace where the generated Headers.ToDictionary expression is produced. Reproduce generation with targetFramework=v3.5, then verify that the generated project builds successfully against .NET Framework 3.5 without the unsupported string.Join overload.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, java
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.