Loopback-next: Cannot POST array for multi insert anymore ?

Created on 11 Jun 2020  路  3Comments  路  Source: strongloop/loopback-next

Steps to reproduce

  1. Go on the /explore link of the API
  2. Open a POST REST route that is made to add a new model insertion
    Replace the object by an array of the object :
    image
  3. Click execute

Current Behavior

422 error

image

Expected Behavior

A success answer with the entries in an array like this I suppose: https://github.com/strongloop/loopback/issues/1275#issuecomment-264409854

[
   {
     "id": "3"
     "name": "array one"
   },
   {
     "id": "4"
     "name": "array two"
   }
]

Link to reproduction sandbox

https://github.com/mathias22osterhagen22/loopback-array-post-sample

Additional information

Seems like it was working on the previous version?
https://stackoverflow.com/a/54955999/12530707

OpenAPI question

All 3 comments

@mathias22osterhagen22 : You can also use
Promise<People[]> { return await this.peopleRepository.createAll(people) }
@achrinza we can close this issue as its solved..

Just to summarise,

  • @requestBody.array() is needed to allow OpenAPI validation to accept an array of the model.
  • yourRepoHere.createAll() is needed to allow the ORM to accept an array of the model.

I'll close this issue due to no reply, and the question being straightforward and well-documented;

Feel free to ping this issue if the problem is not resolved.

Further reading

Was this page helpful?
0 / 5 - 0 ratings