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: use container to make requests for extraction #509

Closed james2doyle closed 2 weeks ago

james2doyle commented 1 month ago

FormRequest that have a binding in container will not be properly instantiated when the docs are being generated.

Screen Shot 2024-08-30 at 11 18 16 AM

The solution proposed in this comment seems to work for me:

https://github.com/dedoc/scramble/pull/399#issuecomment-2134314719

Resolving the class from the container instead of newing it up, works.

I don't see the other error where "it evaluates the request rendering".

The change to using app breaks the tests though. It tries to actually create the FormRequest which causes the validation to trigger. At least that is what it seems like.

Any thoughts on how to proceed here? I can take a crack at a PR, if that helps. But I'm not sure what to fix....

romalytvynenko commented 4 weeks ago

@james2doyle this approach was avoided due to instances of Illuminate\Foundation\Http\FormRequest being validated when resolved from a container.

So if your request is extending Illuminate\Foundation\Http\FormRequest, resolving it from a container would automatically trigger a validation which will result to docs generation failing.

romalytvynenko commented 2 weeks ago

@james2doyle any thought on this?

james2doyle commented 2 weeks ago

@romalytvynenko Yeah, I understand. I tried to write some code that would step through the container binding and try to find the classes that are injected. I'm not very experienced working with reflection though, so I couldn't figure it out. There were some examples of people getting it working but those were other classes that didn't trigger functionality when they were resolved.

romalytvynenko commented 2 weeks ago

@james2doyle closing this one then, as I also couldn't find a solution.