Similar Problem : Use object type query param in swagger documentation
My ask :
I have an API for which lets I have 3 query parameters but in the future, it can have multiple parameters with different datatypes. So instead of directly mentioning them in my api-doc.yaml I want to create a model(class) which can hold all these parameters. Please note I only want to go with this solution. I know we can pass it in the body. But I am in a tightly coupled setup hence I am interested to see how we can wrap these parameters into a single class
My current implementation:
My api-defs.yaml file where I am defining this model as a schema PayloadQueryParams
PayloadQueryParams:
  type: object
  properties:
    workflow:
      type: string
      required: true
    timestamp:
      type: integer
      format: int64
      required : true
    createdTill:
      type: integer
      format: int64
      description: "timestamp in ms for querying scheduler service tasks"
      required : false
    page:
      type: integer
      description: "page number for scheduled tasks"
      required: false
Now I am trying to use this model, into my api-internal.yaml
  /tasks:
    get:
      tags:
        - "internal"
      operationId: "getTask"
      parameters:
        - in: query
          name : PayloadQueryParams
          schema:
            $ref: '#/components/schemas/PayloadQueryParams'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                  $ref: '#/components/schemas/ResponseModel'
        "401":
          description: "Unauthorized"
          content: { }
        "403":
          description: "Forbidden"
          content: { }
Now usually my approach stays is that with this codegen structure generates a custom boiler plater interface which I implement into my controller layer and override methods,
PROBLEM With above structure problem I am facing is
- The methods codegen is generating (getTask) that is created with modelPayloadQueryParamswhich I expect it to do but the problem is when I am trying to send query parameters from the URLs its receiving it as null.
- As part of testing I removed all these definitions from swagger and created my own query paramter class PayloadQueryParamsexactly same which was generated by swagger and when I try to use that directly into my controller layer, my UTs are working fine that means when I send the query params from URL they are parsed correctly
- But as I mentioned I cant go with the setup-2 I have to do same thing via swagger codegen
- I have validated by copying the exact definition of class PayloadQueryParamsgenerated by swagger into my own custom class, even when they are identical, my APIs without swagger are working but not working when I used swagger codegen for generating query param model
SOLUTIONS I EXPECT
- Is there any structual problem in my yaml files ?
- I am on openAPI so I belive that is not the problem
- Is there any other way we can get these query parameters into a hashmap or multivalue map
