Skip to content

[BUG][csharp-netcore] ParameterToMultiMap method generates inconsistent MultiMap for Dictionary as compared to Swagger UI #8798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 of 6 tasks
aaronxu6 opened this issue Feb 22, 2021 · 6 comments · Fixed by #8848

Comments

@aaronxu6
Copy link

aaronxu6 commented Feb 22, 2021

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

In my GET API, I have a Dictionary<string, string> as parameter.
When I run it in Swagger UI, the URL it generated does not include the name of the dictionary and my controller is able to receive the KeyValues of the dictionary.
When I use the codegen to generate the client library and run the same method. The URL includes the name of the dictionary itself and my controller is not able to receive any value in the dictionary.

openapi-generator version

I use openapi-generator-cli-5.0.0-beta3

OpenAPI declaration file content or url

Parameter part of the schema

"parameters": [
          {
            "name": "args",
            "in": "query",
            "required": true,
            "schema": {
              "type": "object",
              "additionalProperties": {
                "type": "string"
              }
            }
          }
        ]
Generation Details
Steps to reproduce
  1. Run the API in swagger UI with dictionary parameter:
    args : {
    "key1": "value1",
    "key2": "value2"
    }
  2. URL generated is http://localhost:5050/api/v1/pitos/option?key1=value1&key2=value2
  3. Generate client library using the codegen
  4. Run the same API in the client code with the same parameter
  5. URL generated in client code becomes http://localhost:5050/api/v1/pitos/option?args=%5bkey1%2c%20value1%5d%2c%5bkey2%2c%20value2%5d
Related issues/PRs
Suggest a fix

It seems to be the problem within the query parameter generation process i.e. ParameterToMultiMap. Please fix it to be consistent with Swagger UI ASAP. Thank you.

@Blackclaws
Copy link
Contributor

Blackclaws commented Feb 26, 2021

Interesting. I think Swagger UI might actually be in the wrong here. What you show only works if you don't actually specify the parameter name in aspnetcore in FromQuery. Which is something that was fixed by me recently as it introduced a different bug when parameter names contained an underscore. Going by the spec you posted I would expect that the swagger ui creates an object called args.

@Blackclaws
Copy link
Contributor

I just tested it out by adding another parameter to the list. Without the change I made to the aspnetcore generator it gets picked up as an additional dictionary entry, which makes no sense, as its supposed to be a separate parameter. Swagger UI indeed creates a flat object there (which is wrong).

@Blackclaws
Copy link
Contributor

After further investigation it appears you are also right in that the generated client code ALSO doesn't bind correctly to the query parameter.

@Blackclaws
Copy link
Contributor

What you actually want as an api spec is the following:

"parameters": [
          {
            "name": "args",
            "in": "query",
            "style": "deepObject",
            "required": true,
            "schema": {
              "type": "object",
              "additionalProperties": {
                "type": "string"
              }
            }
          }
        ]

Note the added deepObject. This currently breaks with the default codegen in general however, as deepObject expects (though according to the spec might not need) a schema. I'll try to fix that.

@Blackclaws
Copy link
Contributor

This seems related: OAI/OpenAPI-Specification#1006, as does this: #469

@Blackclaws
Copy link
Contributor

Pull request to fix this is up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants