How to add default JSON object in body of post request swagger

1.1k Views Asked by At

I'd like to add JSON as the default to this swagger endpoint for the body of the POST request. I can not for the life of me figure out what this format is supposed to be to add a very large JSON object as the default for a POST endpoint. See example swagger spec below

{
  "consumes": [
    "application/x-www-form-urlencoded"
  ],
  "definitions": {},
  "info": {
    "title": "swagger help",
    "version": "1.0"
  },
  "paths": {
    "/endpoint_name": {
      "post": {
        "consumes": [
          "application/json"
        ],
        "parameters": [
          {
            "default": {
              "application/json": [{"test": "value"}]
            },
            "description": "JSON of a list of values",
            "in": "body",
            "name": "body",
            "required": true,
            "type": "object"
          }
        ],
        "produces": [
          "application/json"
        ],
        "security": [
          {
            "APIKeyHeader": [
              "Authorization"
            ]
          }
        ],
      }
    },
  "produces": [
    "application/json"
  ],
  "securityDefinitions": {
    "APIKeyHeader": {
      "description": "description here",
      "in": "header",
      "name": "Authorization",
      "type": "apiKey"
    }
  },
  "swagger": "2.0"
}
1

There are 1 best solutions below

0
Helen On

In OpenAPI 2.0, body parameters use the schema keyword. That's where you specify the type, default, example, and other type-related details.

        "parameters": [
          {
            "description": "JSON of a list of values",
            "in": "body",
            "name": "body",
            "required": true,
            "schema": {
              "type": "object",
              "default": {"test": "value"}
            }
          }
        ],