byte-it / openapi-spec-generator

Creates Open API spec for a Laravel JSON:API
3 stars 6 forks source link

BelongTo relation generates single object for PATCH/POST but it expects an array #12

Open bbrala opened 3 years ago

bbrala commented 3 years ago

HasMany::make('answers', 'answers')->type('concession-answers'),

results in

{
  "data": {
    "type": "concession-answers",
    "id": "7"
  }
}

but should be

{
  "data": [{
    "type": "concession-answers",
    "id": "7"
  }]
}
bbrala commented 3 years ago

ping @maartenpaauw @rocksheep

bbrala commented 3 years ago

I think the result should be as per spec:

# Array of Pets
type: array
items:
  $ref: '#/components/schemas/Pet'

Right not the it seems the data property is:

# Array of Pets
type: object
items:
  $ref: '#/components/schemas/Pet'
bbrala commented 3 years ago

Couldn't fix it unfortunately, got lost in the code. Any change you could have a look?

captnCC commented 3 years ago

I tried to reproduce this bug, but in the implementation, the HasMany relationship between Post and Comment works as expected and produces

{
  "data": {
    "type": "array",
    "items": {
      "$ref": "#/components/schemas/resources.posts.relationship.comments.fetch"
    }
  }
}

Can you provide more context to the problem?

bbrala commented 3 years ago

Check the related pr it proves the bug :)

captnCC commented 3 years ago

I'm a bit blind this morning, yes for the request bodies this was a real bug. But it should be fixed now, you can try it out with your branch for #13!