1

I have this json

{
        "adnxs_uid": "10589",
        "ra":"1.2.3.4",
        “event”: {
            
        }
}

that goes as a param for a POST request BUT. I have defined it's definition in my go function as follows, here, I was trying to generate nested JSON structure using schema under parameters

    // swagger:route POST /1.0/log version-1 logPost
    //
    // This will log an event coming from the web
    // The request will be sent as a POST request
    //
    //     Consumes:
    //     - application/json
    //
    //     Produces:
    //     - application/json
    //
    //     Schemes: https
    //
    //     Parameters:
    //       + name: event
    //         in: body
    //         description: event to be logged, sent as JSON string
    //         type: string
    //         required: true
    //         schema:
    //           type: string
    //       + name: adnxs_uid
    //         in: body
    //         description: appnexus user id
    //         type: string
    //         required: false
    //         schema:
    //           type: string
    //       + name: ra
    //         in: body
    //         description: ip address of the user
    //
    //     Responses:
    //       200: body:StringBody Event logged successfully
    //       400: body:StringBody Invalid JSON structure
    //       401: body:StringBody Unauthorized, either key param is missing or is invalid

the results of this were not really nested, the command to generate swagger I am using is swagger generate spec -o ../swagger.json --scan-models

          {
            "description": "event to be logged, sent as JSON string",
            "name": "event",
            "in": "body",
            "required": true,
            "schema": {
              "description": "event to be logged, sent as JSON string",
              "type": "string"
            }
          },
          {
            "description": "appnexus user id",
            "name": "adnxs_uid",
            "in": "body",
            "schema": {
              "description": "appnexus user id",
              "type": "string"
            }
          },
          {
            "description": "ip address of the user",
            "name": "ra",
            "in": "body"
          }
        ]

I am not sure how to change it to a nested json like this.

"schema": { "type": "object", "properties": { "event": { "type": "string", "description": "..." }, "adnxs_uid": { "type": "string", "description": "..." } } }
Rajat Singh
  • 653
  • 6
  • 15
  • 29
  • Check out [this example](https://stackoverflow.com/a/31531983/113116), it shows how the body definition should be structured. – Helen Jun 20 '23 at 12:29

0 Answers0