OpenAPITools / OpenAPITools/openapi-generator

[BUG] csharp-netcore different handling of deepObject GET parameters between async and sync methods

Open
#10,160 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

The example below uses style:deepObject in components/parameters/GeoPosition. The generated csharp-netcore method for sync calls is handling the position parameter as follows:

            if (position != null)
            {
                if (position.Lat != null)
                {
                    localVarRequestOptions.QueryParameters.Add(Org.OpenAPITools.Client.ClientUtils.ParameterToMultiMap("", "position[lat]", position.Lat));
                }
                if (position.Lon != null)
                {
                    localVarRequestOptions.QueryParameters.Add(Org.OpenAPITools.Client.ClientUtils.ParameterToMultiMap("", "position[lon]", position.Lon));
                }
            }

But the async method is doing:

            if (position != null)
            {
                localVarRequestOptions.QueryParameters.Add(Org.OpenAPITools.Client.ClientUtils.ParameterToMultiMap("", "position", position));
            }

So the string representation of the generated GeoPosition class get added to the parameter when using async methods.

openapi-generator version

cli-5.2.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: My Api
  version: 1.0.0
paths:
  /registration:
    get:
      operationId: getRegistration
      parameters:
        - $ref: '#/components/parameters/GeoPosition'
      responses:
        '200':
          description: successful registration
components:
  parameters:
    GeoPosition:
      name: position
      in: query
      required: false
      style: deepObject
      schema:
        $ref: '#/components/schemas/GeoPosition'
  schemas:
    GeoPosition:
      type: object
      nullable: true
      properties:
        lat:
          type: number
        lon:
          type: number
Generation Details
Steps to reproduce
java -jar openapi-generator-cli-5.2.0.jar generate -i myapi.yaml -g csharp-netcore

have a look into DefaultApi.cs and compare GetRegistrationWithHttpInfoAsync vs. GetRegistrationWithHttpInfo

Related issues/PRs
Suggest a fix

async methods should have the same code generated as the sync methods. To clarify: the sync method is ok. The async method is faulty.

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

Generate the provided OpenAPI example with openapi-generator-cli 5.2.0 using the csharp-netcore generator, then inspect DefaultApi.cs. Compare GetRegistrationWithHttpInfoAsync with GetRegistrationWithHttpInfo, focusing on how the deepObject position parameter is added. Done means both methods generate equivalent position[lat] and position[lon] query handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.