openapi-python-client icon indicating copy to clipboard operation
openapi-python-client copied to clipboard

Using dictionary in query param

Open siddhsql opened this issue 1 year ago • 1 comments

Describe the bug I have an endpoint that takes in a dictionary as a query param:

- name: metadata
          in: query
          required: false
          style: deepObject
          explode: true
          schema:
            type: object
            additionalProperties:
              type: string

note this:

          style: deepObject
          explode: true

The openapi generator generates same code whether I have

          style: deepObject
          explode: true

present or not. I am using version 0.19.1.

The URL generated is like:

http://localhost:8080/foo?author=Joshua%20Bloch&publisher=Pearson%20Addison-Wesley

When

          style: deepObject
          explode: true

is present, the URL should be like:

http://localhost:8080/foo?metadata[author]=Joshua%20Bloch&metadata[publisher]=Pearson%20Addison-Wesley

refer: https://swagger.io/docs/specification/serialization/

OpenAPI Spec File see above

Desktop (please complete the following information):

  • OS: [e.g. macOS 10.15.1] macOS ventura (13)
  • Python Version: [e.g. 3.8.0]
  • openapi-python-client version [e.g. 0.1.0] 0.19.0

Additional context Add any other context about the problem here.

siddhsql avatar Jun 25 '24 20:06 siddhsql

I might have stumbled into same kind of situation(?)

For endpoint "/projects/{projectId}/testruns, a call should be generated:

   ?fields[testruns]=@all

but is generated:

   ?testruns=@all

openapi json spec is:

{
 {
  "name" : "fields",
  "in" : "query",
  "description" : "Filter...",
  "style" : "deepObject",
  "schema" : {
    "$ref" : "#/components/schemas/sparseFields"
  }
},

I fixed this into the generated code, to def _get_kwargs(...)

# REMOVED THIS:
#if not isinstance(fields, Unset):
#    json_fields = fields.to_dict()

# ADDED THIS:
if not isinstance(fields, Unset):
    if getattr(fields, "testruns", UNSET) is not UNSET:
        params["fields[testruns]"] = fields.testruns

# REMOVED ALSO THIS:
#if not isinstance(json_fields, Unset):
#    params.update(json_fields)

...at least this fixed the situation for me...

TG0 avatar Aug 08 '25 11:08 TG0