Method arguments in http put request (csv? Body with String?)

Viewed 263

I am trying to write a method that will respond to this http request. Unfortunately, I do not know what the argument of such a method should be.

cat data.csv | curl --header "Content-Type: text/plain" --request PUT --data-binary @- http://localhost:8080/endpoint

Swagger :

put:
  tags:
  - "employees"
  summary: "Stores employees hierarchy tree on server"
  description: "Sends or replaces employees hierarchy tree on server"
  operationId: "endpoint"
  consumes:
  - "text/plain"
  parameters:
  - in: "body"
    name: "body"
    description: "CSV with four columns - employee id, employee name, employee surname and employee superior id. Columns are separated with ',' character."
    required: true
    schema:
      type: string
      example:[tons of employees data here]

At first I thought it would be a Multipartfile and then I would just process it (see dummy approach below), but then I saw a "string" in swagger and it confused me a bit. I have no clue anymore what the format of the input data is.

 @PutMapping("/endpoint")
public void readCSV(MultipartFile file) throws IOException {
    String content = new String(file.getBytes());
    System.out.println(content);
}
2 Answers

I am facing the same thing right now. Actually, you have the information that it is String, text / plain (Swagger) and Content-Type "text / plain" which makes me believe that the transmitted data is just a String that was created from the data contained in the CSV file. So your method may look like this

@PutMapping("/endpoint")
public void readCSV(@RequestBody String csvData) 

and this csvData String will contain all the text from the CSV file.

Related