Search code examples
springdocspringdoc-openuispringdoc-openapi-ui

Springdoc-openapi - Is there any way to override default value as null or empty in the POST request?


I am using Spring Boot and Open API 3. Through OAS2 Swagger when I make a POST request, I see that all String fields are coming default value as a Spring and I don't see a way to remove it, either through SpringDoc Open UI nor through code.

{
  "firstName": "string",
  "lastName": "string",
  "age": 0,
  "email": "string",
  "address1": "string",
  "address2": "string",
  "address3": "string",
  "telephone" : "0",
  "department" : "string",
  .....
}

Here consumer not willing to remove the string from field while making the request. Is there any way

  1. If we can remove "string" as a value and set null or "" as default value?
  2. Is there any way if we can read the custom object and reset all values to null where it finds the "string"?

Solution

  • You could use

    @Schema(example = "<your example here>")
    

    to provide another example for swagger-ui.

    For "" you can do (yes, it's a space):

    @Schema(example = " ")