0
votes

I have a requirement to integrate OpenAPI 3 documentation for my Spring Boot 2 project. We did not used modals/DTOs on controllers.

Here is the sample controller:

@RestController
@RequestMapping(value = "/pet")
public class PetController {
    @RequestMapping(value = "/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ResponseEntity<Map<String, Object>> savePet( 
            @RequestBody Map<String, Object> petObj, HttpServletRequest request)
            throws Exception {
        String petResponse = petDAO.savePet(petObj, request, true);
        return new ResponseEntity<Map<String, Object>>(petResponse, HttpStatus.OK);
    }
}

Request body:

{
  "name":"Test",
  "category":"school"
}

My response:

{
  "petId":"1",
  "petName":"Test",
  "petCategory":"school",
  "petStaus":"active"
}

I am not able to find a way to add the OpenAPI doc for my custom Map object. I want to add key, description, type, example(s) for each property in my Map manually.

Can anyone suggest how to do this?

1

1 Answers

0
votes

This is the default behaviour of the springdoc-openapi library in order to ignore other injectable parameters supported by Spring MVC.

If you want to change this behaviour, you can just exlcude it as follow:

    SpringDocUtils.getConfig().removeRequestWrapperToIgnore(Map.class);