3

I have a Spring Boot REST app that is Swagger-enabled using springdoc-openapi-ui. For the life of me, I can't get the generated Swagger UI to actually POST JSON. Instead, the frontend passes args as request parameters. How do I get the Swagger UI to actually submit JSON?

@Data
public static class SampleData {
    private String info;        
}
    
@PostMapping(value = "/test", consumes = "application/json")
public void postData(@ParameterObject @RequestBody SampleData data) {
    // do something
}

After clicking "Try it out" and "Execute" in the Swagger UI, the request fails with:

{
  "status": 415,
  "error": "Unsupported Media Type",
  ...
}

Because the UI tried to POST this:

http://localhost:8080/myapp/v1/test?info=test

The generated curl command is also incorrect (not POSTing JSON):

curl -X 'POST' \
  'http://localhost:8080/myapp/v1/test?info=test' \
  -H 'accept: */*' \
  -d ''

Note that the Swagger UI will POST JSON if I remove the @ParameterObject annotation. However, then the UI doesn't present the user-friendly form (which in the full example contains documentation annotations for fields in that bean)

What am I missing?

Spring Boot: 2.6.3, springdoc-openapi-ui: 1.6.5

João Dias
  • 16,277
  • 6
  • 33
  • 45
Noky
  • 471
  • 1
  • 4
  • 11
  • 1
    I would recommend you open an issue in `springdoc` github: https://github.com/springdoc/springdoc-openapi/issues. – João Dias Jan 28 '22 at 19:49
  • Thanks, I posted an issue there. Resolution was to remove the `@ParameterObject` annotation and switch to the "Schema" view in the UI to see the documentation for the POJO fields. Not quite the solution I was hoping for but it works. https://github.com/springdoc/springdoc-openapi/issues/1482 – Noky Jan 31 '22 at 15:58

1 Answers1

1

Resolution from springdoc github was to remove the @ParameterObject annotation and switch to the "Schema" view in the UI to see the documentation for the POJO fields. Not quite the solution I was hoping for but it works. github.com/springdoc/springdoc-openapi/issues/1482

Noky
  • 471
  • 1
  • 4
  • 11