OpenAPITools / OpenAPITools/openapi-generator

[BUG][CSHARP] DeepObject query params are not sent in the Api when additional properties are enable

Open
#19,350 1 comment 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

Currently there is support of deepObjects on query params which produces parameters with square brackets.
Example: Query param named fields can produce /endpoint?fields["key_1"]=value_1&fields["key_2"]=value2

When the query param is deepobject and additional properties is allowed, the generated code creates APIs that does nothing to the query param.

 - name: fields
          in: query
          description: Holds types of fields and its values
          style: deepObject
          explode: true
          schema:
            type: object
            additionalProperties:
              type: string
            description: Dictionary that holds the optional query filters of a request called fields. This dictionary is case insensitive.

Generated API

localVarRequestOptions.PathParameters.Add("userId", Sdk.Client.ClientUtils.ParameterToString(userId)); // path parameter
            if (fields != null)
            {
            }
Expected behavior

When the deepobject query-param with additional properties is found, the API generated code should be

if (fields != null)
{
    localVarRequestOptions.QueryParameters.Add(Sdk.Simple.Client.ClientUtils.ParameterToMultiMap("deepObject", "fields", fields));
}

Note: Support for deepObject is already there but when object only support "additional objects" it does nothing.

openapi-generator version

v7.7.0

OpenAPI declaration file content or url

Use the following swagger to generate the API code in csharp

openapi: 3.0.1
info:
  title: Testing single
  version: 0.0.1
paths:
  /single/session/{userId}:
    get:
      summary: Single endpoint session
      parameters:
        - name: fields
          in: query
          description: Holds types of fields and its values
          style: deepObject
          explode: true
          schema:
            type: object
            additionalProperties:
              type: string
            description: Dictionary that holds the optional query filters of a request called fields. This dictionary is case insensitive.
        - name: userId
          in: path
          description: The identity of the user.
          required: true
          schema:
            type: string

Complete swagger in: https://gist.github.com/alfredo-accuris/65e5961ff763e00bc7dd6718b192b8a9

Generation Details

docker run --rm openapitools/openapi-generator-cli:v7.7.0 generate -i ./deepobject-swagger.json --package-name Simple -g csharp -o ./Sdk/Simple --additional-properties targetFramework=net8.0

Steps to reproduce

Execute the cli with the specific swagger.

Related issues/PRs
Suggest a fix

Going through the code I can see on org.openapitools.codegen.DefaultCodegen that has a property loadDeepObjectIntoItems=true that always tries to load specify keys for deepobjects but if the variable is set to false, then the generated code works as expected generating:

if (fields != null)
{
    localVarRequestOptions.QueryParameters.Add(Sdk.Simple.Client.ClientUtils.ParameterToMultiMap("deepObject", "fields", fields));
}

I suggest make the loadDeepObjectIntoItems configurable to support both options.

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 org.openapitools.codegen.DefaultCodegen and the loadDeepObjectIntoItems property, then reproduce the issue using the supplied OpenAPI YAML and C# generation command. Compare generated handling of a deepObject query parameter with additionalProperties against the expected QueryParameters call, and verify the behavior after the configuration is addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.