Closed xqliu closed 3 years ago
I think for a controller method with POST http method enable, an implicitly request body parameter could be added to parameter list. since for grails, sometimes we just use request.JSON
to get request body, without define any explicit method parameter.
Also there's no request parameter input for get request which consumes param.xxxx (request query parameter)
Would it be possible for you to create an example project that I can reproduce the issue?
Also, you can apply Swagger annotations to the actions in controllers to adjust how the UI is built. For example, you can have the UI render a body input for an action that doesn't have any fields defined in the method declaration:
@ApiImplicitParams([
@ApiImplicitParam(
name = "json",
paramType = "body",
required = true,
value = "json",
dataType = "java.util.HashMap"
)
])
@ApiOperation(value = "custom", nickname = "/your/route", httpMethod = "POST")
def custom() {
println(request.JSON)
}
The PublisherController also has an example of how to attach custom query params.
Hi, Thanks for your information.
For the query parameter, I have added them explicitly as parameters to my controller methods. and then they appear in UI.
For the post body parameter, I confirmed your suggestion works.
But seems put ApiParam to method parameter like below, the value of @ApiParam didn't render on frontend.
@ApiImplicitParams([
@ApiImplicitParam(
name = "domainJson",
paramType = "body",
required = true,
value = "JSON represent of domain properties",
dataType = "java.util.HashMap"
)])
@Transactional
def update(String domainName, @ApiParam(value = "domain id") Long id) {
This is what rendered on swagger-ui, you can see the ApiImplicitParam value actually rendered correctly, but the @ApiParam value didn't render.
Thanks for your great help :)
The plugin doesn't look at any annotations that are defined on the method parameters.
Might be able to use an @ApiImplicitParam
with a paramType="path"
to allow adjustment of the domain id.
Thanks for your clarification :) thanks again for your work on the package :)
Hi, thanks for your great work on the plugin :)
I have found an issue that, there's no request body edit textarea appears on POST endpoint
as per attached
While for normal post controller, it renders like follow(There's a textarea where request body json content could be input)
I am using swagger-ui-react(https://www.npmjs.com/package/swagger-ui-react) to generate the UI based on json file generated by swagger-grails.
I have attached the generated meta data for the API as below
Seems because grails has no @RequestBody annotation, so request body was not generated as a parameter, so swagger-ui didn't render the textarea for post request body.
I have tried to add a @RequestBody to controller method parameter, and the textarea can be generated as expected, but seems grails can not do the value binding correctly.
Not sure whether I have expressed the issue clearly...