Forum Discussion

aubergine_joe's avatar
aubergine_joe
Occasional Visitor
2 years ago

Specify deepObject inside POST request

For a GET request I can specify a deepObject like this and it works correctly:

 

/things:
  get:
    tags:
      - Searching
    summary: searches Things
    operationId: searchThings
    description: my get endpoint
    parameters:
      - in: query
        name: myVar
        description: `myVar[prop1]=hello&myVar[prop2]=world`
        schema:
          type: object
          properties:
            prop1:
              type: string
              example: hello
            prop2:
              type: integer
              example: world
        style: deepObject
        explode: true

 

 

The expected query string is created:

myVar%5Bprop1%5D=hello&myVar%5Bprop2%5D=world

 

I want to use the same structure for a related POST end point. But I can't seem to define a deepObject in the requestBody after trying a few things

 

/addThings:
  post:
    tags:
      - adding
    summary: Add things
    operationId: createThings
    description: My post end point
    requestBody:
      required: true
      content:
        application/x-www-form-urlencoded:
          encoding: # didnt work
            myVar: # didnt work
              style: deepObject # didnt work
              explode: true # didnt work
          schema:
            type: object
            required:
              - myVar
            properties:
              myVar:
                type: object
                description: `myVar[prop1]=hello&myVar[prop2]=world`
                properties:
                  prop1:
                    type: string
                    example: hello
                  prop2:
                    type: string
                    example: world
                #style: deepObject # Does not work - not permitted
                #explode: true # Does not work - not permitted

 

 

I get the following response:

myVar=%7B%0A%20%20%22prop1%22%3A%20%22hello%22%2C%0A%20%20%22prop2%22%3A%20%22world%22%0A%7D

 

My question. Is there a way to get the desired deepObject encoding for POST requests?

myVar%5Bprop1%5D=hello&myVar%5Bprop2%5D=world

 

Or do I need to explore other options?

 

Thanks in advance!

Joe

 

Seems to be the same questions as this: https://community.smartbear.com/t5/Swagger-Open-Source-Tools/deepObject-not-working-as-expected-when-used-inside-requestBody/m-p/180634

 

 

No RepliesBe the first to reply