guide-microprofile-openapi icon indicating copy to clipboard operation
guide-microprofile-openapi copied to clipboard

Please add an example of @RequestBody

Open bmarwell opened this issue 7 years ago • 6 comments

Hello OpenLiberty-Team!

Your example is a great way to learn about the OpenAPI spec. Please add an example about @RequestBody, that would be very helpful.

Reason: With OpenAPI 3.0, form-data parameters were moved from Parameter to RequestBody. So I initially thought that ParameterIn.RequestBody was missing. Instead, there is a requestBody annotation for those parameters, and the parameters need to be hidden.

See for reference: https://github.com/eclipse/microprofile-open-api/issues/299

(Especially for a login which is using APPLICATION_FORM_URLENCODED).

bmarwell avatar Nov 20 '18 07:11 bmarwell

Just an additional question. I just tried the @RequestBody annotation, but in my method signature I got two Form Parameters, which are now set to "hidden". Still, the request body does not show up in the liberty generated openapi output. Do I need an additional parameter for the body? That would somehow be redundant to the existing parameters.

bmarwell avatar Nov 20 '18 09:11 bmarwell

@arturdzm @arthurdm, can you comment on the question above?

yeekangc avatar Nov 20 '18 18:11 yeekangc

Currently mpOpenAPI-1.0 does not support scanning of @FormParam annotation. It is possible to use @RequestBody annotation as follows:

@Consumes(MediaType.APPLICATION_FORM_URLENCODED) @RequestBody(content=@Content(schema=@Schema(implementation=SomeModel.class)))

Using this approach it is possible to put parameter definitions into a POJO

arturdzm avatar Nov 22 '18 16:11 arturdzm

Thanks for your input. The @RequestBody annotation can be applied to parameters, which is confusing. I added it to the String parameter, which (obviously) did not show up in the generated OpenAPI description. Is this a Liberty issue or a problem from the OpenAPI annotations?

bmarwell avatar Aug 11 '20 07:08 bmarwell

Adding @RequestBody to parameters generated OpenAPI documentation for me. Can't seem to reproduce the issue in the latest version of OpenLiberty. It might have been fixed?

tt-le avatar Oct 28 '20 18:10 tt-le

Hi @tt-le,

thanks for your input. I can revise this issue (and create a minimal example) in a few weeks at best – sorry!

I can also add @RequestBody annotations to Parameters, but please also see my note that I am using multiple of those – @FormParam. Maybe that is the difference?

bmarwell avatar Oct 28 '20 18:10 bmarwell