dedoc / scramble

Modern Laravel OpenAPI (Swagger) documentation generator. No PHPDoc annotations required.
https://scramble.dedoc.co/
MIT License
1.18k stars 112 forks source link

Fixed incorrect data wrap key when using `AnonymousResourceCollection` and redefining it in collected resource #517

Closed axelrindle closed 1 week ago

axelrindle commented 4 weeks ago

Accesses the $wrap property on the $collectingResourceType directly to decide whether to wrap a resource collection in a data array or not.

romalytvynenko commented 4 weeks ago

@axelrindle Hey! Can you explain the reasoning?

axelrindle commented 4 weeks ago

Certainly. I have a resource where I set the static $wrap property to null. This results in the following JSON response (example):

[
  {
    "type": "attachment",
    "url": "..."
  }
]

Scramble however incorrectly displays the following structure:

{
  "data": [
    {
      "type": "attachment",
      "url": "..."
    }
  ]
}

I fixed it by directly accessing the $wrap property on the collection type ($collectingResourceType) in the class AnonymousResourceCollectionTypeToSchema. Otherwise AnonymousResourceCollection::$wrap will always return 'data' instead of what's defined by the actual resource.

romalytvynenko commented 4 weeks ago

@axelrindle oh, gotcha. Nice catch! Will merge soon!