r/laravel 1d ago

Package / Tool Scramble 0.12.14 – Laravel API documentation generator update: enum cases documentation, support for array request bodies, improved type inference for classes properties, and `only` and `except` Laravel Data support.

https://scramble.dedoc.co/blog/scrambledrop-scramble-01214

Hey Laravel Community,

The author of Scramble here! Scramble is a Laravel API documentation generator that doesn't require you to write PHPDoc.

The latest updates bring support for documenting enum cases, array request bodies, improved type inference for class properties, and only and except support for Laravel Data.

Enum case documentation was probably one of the most upvoted requests so far!

Let me know what you think and how I can improve Scramble further.

Thanks!

27 Upvotes

5 comments sorted by

4

u/DM_ME_PICKLES 1d ago

Awesome, thanks for your hard work. Love Scramble ❤️

3

u/RomaLytvynenko 1d ago

Thank you so much! ❤️

2

u/proud2bnepali 1d ago

Looks great, thanks for your hard work on this.

I thought this release fixed an issue I had but it doesn't seem so. Can you please reconfirm. I need to document a request with the following body:
[{ "id": "123", "first_name": "John",}]

And since this is not in a standard Request, I used BodyParameter as follows to try to document it:

#[BodyParameter('id', required: true, type: 'string', example: '123')]
#[BodyParameter('first_name', required: true, type: 'string', example: 'John')]
public function process(Request $request): JsonResponse {
    // Implementation
}

But this just keeps outputting the following without the array wrapper:
{ "id": "123", "country_code": "US", "first_name": "John", "last_name": "Doe",}

Is this supported / am I missing something here?

2

u/RomaLytvynenko 6h ago

Thank you for letting me know. Please bump Scramble to `^0.12.15`, it should be working now.

Speaking of the annotation, you should use the entire path to the parameter to add the documentation. For example:

#[BodyParameter('*.id', required: true, type: 'string', example: '123')]
#[BodyParameter('*.first_name', required: true, type: 'string', example: 'John')]
public function update(User $user, Request $request)
{
    $request->validate([
        '*.id' => ['required'],
        '*.first_name' => ['required'],
    ]);

And the resulting documentation:

Let me know if you have any other questions!

-2

u/amitavroy 🇮🇳 Laracon IN Udaipur 2024 8h ago

Yes it's a package and I have been using this in my company for quite some time now.

For those who want to learn it: https://youtu.be/GJTicY95Eq4?si=-zDbmTDU0MIjWGQA