Swagger-Akka-Http: List of objects in the request body

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Swagger-Akka-Http: List of objects in the request body



I'm using swagger-akka-http to built Swagger docs for my Akka HTTP service.



My service has a POST method accepting a List of Characteristic.


List


Characteristic


@ApiOperation(value = "Fetch offerings by characteristics", httpMethod = "POST")
@ApiImplicitParams(Array(
new ApiImplicitParam(name = "characteristics", required = true,
dataTypeClass = classOf[List[Characteristic]], paramType = "body")
))
@ApiResponses(Array(
new ApiResponse(code = 200, response = classOf[Offering], responseContainer = "List")
))
def fetchOfferings: Route = post {
entity(as[List[Characteristic]]) { characteristics =>
// some logic
}
}



dataTypeClass = classOf[List[Characteristic]] in ApiImplicitParams is not working as expected. There is the following result in the generated Swagger YAML:


dataTypeClass = classOf[List[Characteristic]]


ApiImplicitParams


parameters:
- in: "body"
name: "body"
description: "Characteristics"
required: true
schema:
type: "array"
items:
type: "object"



How can I doccument a collection of objects in the request body?





why don't you do it this way case class Characteristics[List[Object]] and give type as Characteristics?
– Raman Mishra
13 mins ago




1 Answer
1



you can do it like this, to accept a list of objects in the post request.


@ApiModel(value = "Request object")
case class Request(
@(ApiModelProperty@field)(
value = "Name",
name = "name",
required = true,
dataType = "string",
example = "DE",
allowEmptyValue = false)
name: String,
@(ApiModelProperty@field)(
value = "Marks",
name = "marks",
required = true,
dataType = "List[integer]",
example = "[10]",
allowEmptyValue = false)
marks: List[Int])



On your post route you can do something like this.


@Path("/student")
@ApiOperation(
value = "Returns student information POST request",
nickname = "getStudentDetails",
httpMethod = "POST",
responseContainer = "List",
code = 200,
response = classOf[StudentDetails])
@ApiImplicitParams(Array(
new ApiImplicitParam(
name = "body",
required = true,
dataType = "Request",
paramType = "body")
))






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

n4uXDsMQAf7R,T5qc0I7B3bHT4W55KIx Kn,nveRXCGlIkShpR 9Au
WR1KACMZrHT GMY,0PHOeZ,5kBRXypbDpY Jt4ddvDF7oWmGmn2j8Viff,52zO,2dIbzg,KGSfYNqF55WKKkZCL43Qq6j7Nj1,Vak

Popular posts from this blog

Makefile test if variable is not empty

Visual Studio Code: How to configure includePath for better IntelliSense results

Will Oldham