I have a controller
import models.UserRegistration
import javax.inject._
import play.api.mvc._
import com.example.WritableImplicits._
@Singleton
class UserController @Inject()(val controllerComponents: ControllerComponents) extends BaseController {
def postExample = Action { implicit request: Request[AnyContent] =>
val userRegistration = UserRegistration.form.bindFromRequest().get
Ok(userRegistration)
}
def getExample() = Action { implicit request: Request[AnyContent] =>
val user1 : UserRegistration = new UserRegistration("ian", "ian@gmail.com", "123")
val user2 : UserRegistration = new UserRegistration("asdfasdf", "asdfasdf@gmail.com", "1233123")
val list: List[UserRegistration] = List(user1, user2)
Ok(list)
}
}
and a routes entry
###
# summary: post a user
# parameters:
# - in: body
# name: name
# schema:
# type: string
# required: true
# description: post a user in json format eg {name:"foo", email:"sdfsd", hash:"13123"}
# tags:
# - users
# responses:
# '200':
# description: OK
# content:
# application/json:
# schema:
# type: string
###
+nocsrf
POST /api/users controllers.UserController.postExample()
when posting in swagger like so
I get a npe, debugging shows that my body is empty
looking at the post from swagger it appears the payload is missing
possibly there is an issue with the swagger docs above the routes entry? but i am lost
I did indeed have the swaggerdoc wrong, rather than parameters it should have been
# requestBody:
# content:
# application/json:
# schema:
# type: object
# examples:
# Basic:
# value:
# name:
# "123"
# email:
# "9780987654321"
# hash:
# "9780987654321"