flask-swagger-ui icon indicating copy to clipboard operation
flask-swagger-ui copied to clipboard

How to add headers in JSON file?

Open JodhwaniMadhur opened this issue 2 years ago • 0 comments

Hello, I need to add headers for my API for it to work in Swagger but I am new to this, how should I add it?

Here is my JSON:

   "swagger":"2.0",
   "info":{
      "description":"This is a CSV translator server.  You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).",
      "version":"1.0.6",
      "title":"Swagger CSV translator",
      "termsOfService":"http://swagger.io/terms/",
      "contact":{
         "email":"[email protected]"
      },
      "license":{
         "name":"Apache 2.0",
         "url":"http://www.apache.org/licenses/LICENSE-2.0.html"
      }
   },
   "host":"127.0.0.1:5000",
   "basePath":"/",
   "tags":[
      {
         "name":"/translate",
         "description":"CSV translator",
         "externalDocs":{
            "description":"Find out more",
            "url":"http://swagger.io"
         }
      },
      {
         "name":"/download-translated-csv",
         "description":"Access to Petstore orders"
      },
      {
         "name":"/download-previously-translated-csv",
         "description":"Operations about user",
         "externalDocs":{
            "description":"Find out more about our store",
            "url":"http://swagger.io"
         }
      }
   ],
   "schemes":[
      "http"
   ],
   "paths":{
      "/translate":{
         "post":{
            "tags":[
               "upload file"
            ],
            "summary":"uploads a CSV",
            "description":"",
            "operationId":"uploadFile",
            "consumes":[
               "multipart/form-data"
            ],
            "produces":[
               "application/json"
            ],
            "parameters":[
               {
                  "name":"file_name",
                  "requestHeaders":{
                  "file_name":{
                     "description":"file name for server",
                     "required":true,
                     "type":"string"
                     }
                  }
               },
               {
                  "name":"file",
                  "in":"formData",
                  "description":"file to upload",
                  "required":true,
                  "type":"file"
               }
            ],
            "responses":{
               "200":{
                  "description":"successful operation"
               },
               "500":{
                  "description":"internal server error"
               }
            },
            "security":[
               {
                  "petstore_auth":[
                     "write:pets",
                     "read:pets"
                  ]
               }
            ]
         }
      },
      "/download-translated-csv":{
         "post":{
            "tags":[
               "download file"
            ],
            "summary":"translate and download the csv",
            "description":"",
            "operationId":"placeOrder",
            "consumes":[
               "application/json"
            ],
            "produces":[
               "application/json"
            ],
            "parameters":[
               {
                  "in":"file_name",
                  "name":"file_name",
                  "description":"file name for server",
                  "required":true,
                  "schema":{
                     "$ref":"#/definitions/Order"
                  }
               },
               {
                  "in":"language",
                  "name":"language",
                  "description":"language to translate to",
                  "required":true,
                  "schema":{
                     "$ref":"#/definitions/Order"
                  }
               }
            ],
            "responses":{
               "200":{
                  "description":"successful operation",
                  "schema":{
                     "$ref":"#/definitions/Order"
                  }
               },
               "400":{
                  "description":"Error"
               },
               "503":{
                  "description":"Server is down"
               }
            }
                  
            }
         }
      ,
      "/download-previously-translated-csv":{
         "post":{
            "tags":[
               "download file"
            ],
            "summary":"translate and download the csv",
            "description":"",
            "operationId":"placeOrder",
            "consumes":[
               "application/json"
            ],
            "produces":[
               "application/json"
            ],
            "parameters":[
               {
                  "in":"file_name",
                  "name":"file_name",
                  "description":"file name for server",
                  "required":true,
                  "schema":{
                     "$ref":"#/definitions/Order"
                  }
               },
               {
                  "in":"language",
                  "name":"language",
                  "description":"language to translate to",
                  "required":true,
                  "schema":{
                     "$ref":"#/definitions/Order"
                  }
               }
            ],
            "responses":{
               "200":{
                  "description":"successful operation",
                  "schema":{
                     "$ref":"#/definitions/Order"
                  }
               },
               "400":{
                  "description":"Error"
               },
               "503":{
                  "description":"Server is down"
               }
            }
                  
            }
         },
   "securityDefinitions":{
   },
   "definitions":{
      "ApiResponse":{
         "type":"object",
         "properties":{
            "code":{
               "type":"integer",
               "format":"int32"
            },
            "type":{
               "type":"string"
            },
            "message":{
               "type":"string"
            }
         }
      },
      "Category":{
         "type":"object",
         "properties":{
            "id":{
               "type":"integer",
               "format":"int64"
            },
            "name":{
               "type":"string"
            }
         },
         "xml":{
            "name":"Category"
         }
      },
      "Pet":{
         "type":"object",
         "required":[
            "name",
            "photoUrls"
         ],
         "properties":{
            "id":{
               "type":"integer",
               "format":"int64"
            },
            "category":{
               "$ref":"#/definitions/Category"
            },
            "name":{
               "type":"string",
               "example":"doggie"
            },
            "photoUrls":{
               "type":"array",
               "xml":{
                  "wrapped":true
               },
               "items":{
                  "type":"string",
                  "xml":{
                     "name":"photoUrl"
                  }
               }
            },
            "tags":{
               "type":"array",
               "xml":{
                  "wrapped":true
               },
               "items":{
                  "xml":{
                     "name":"tag"
                  },
                  "$ref":"#/definitions/Tag"
               }
            },
            "status":{
               "type":"string",
               "description":"pet status in the store",
               "enum":[
                  "available",
                  "pending",
                  "sold"
               ]
            }
         },
         "xml":{
            "name":"Pet"
         }
      },
      "Tag":{
         "type":"object",
         "properties":{
            "id":{
               "type":"integer",
               "format":"int64"
            },
            "name":{
               "type":"string"
            }
         },
         "xml":{
            "name":"Tag"
         }
      },
      "Order":{
         "type":"object",
         "properties":{
            "id":{
               "type":"integer",
               "format":"int64"
            },
            "petId":{
               "type":"integer",
               "format":"int64"
            },
            "quantity":{
               "type":"integer",
               "format":"int32"
            },
            "shipDate":{
               "type":"string",
               "format":"date-time"
            },
            "status":{
               "type":"string",
               "description":"Order Status",
               "enum":[
                  "placed",
                  "approved",
                  "delivered"
               ]
            },
            "complete":{
               "type":"boolean"
            }
         },
         "xml":{
            "name":"Order"
         }
      },
      "User":{
         "type":"object",
         "properties":{
            "id":{
               "type":"integer",
               "format":"int64"
            },
            "username":{
               "type":"string"
            },
            "firstName":{
               "type":"string"
            },
            "lastName":{
               "type":"string"
            },
            "email":{
               "type":"string"
            },
            "password":{
               "type":"string"
            },
            "phone":{
               "type":"string"
            },
            "userStatus":{
               "type":"integer",
               "format":"int32",
               "description":"User Status"
            }
         },
         "xml":{
            "name":"User"
         }
      }
   },
   "externalDocs":{
      "description":"Find out more about Swagger",
      "url":"http://swagger.io"
   }
}
}

I want the translate route's first parameter to be sent as a header.

JodhwaniMadhur avatar Aug 12 '22 10:08 JodhwaniMadhur