knuckleswtf / scribe

Generate API documentation for humans from your Laravel codebase.✍
https://scribe.knuckles.wtf/laravel/
MIT License
1.59k stars 281 forks source link

Scribe doesn't overwrite URL parameters which bound to corresponding models #696

Closed cody-gawr closed 1 year ago

cody-gawr commented 1 year ago

Scribe version

4.19

Your question

Scribe doesn't overwrite URL parameters which bound to corresponding Models

Hello

I love this library to make my life easy. I have been having some issues recently where I have been trying to generate an api documentation for routes which include URL parameters of binding to Models. It seems it's treating them as ID which is primary key of a corresponding model. Route::post('/{restaurant}/profile', [RestaurantProfileController::class, 'create']); Since {restaurant} is a parameter which indicates uuid field of restaurant table, I defined resolveRouteBinding function in Restaurant model and attributes in RestaurantProfileController to let scribe know that the controller has a URL parameter of which name is restaurant using URLParam attribute. public function resolveRouteBinding($value, $field = null) { return $this->where('uuid', $value)->firstOrFail(); } image

#[UrlParam(name: "restaurant", type: "string", description: "The uuid of the restaurant.", example: "3315946")] image

However, a final API documentation is as below. image

Any guidance will be greatly appreciated. Thank you!

Docs

shalvah commented 1 year ago

Hmm, it may be hard for Scribe to figure that out, since it doesn't "read" the resolving code. Have you tried the normalizeEndpointUrlUsing() hook? https://scribe.knuckles.wtf/laravel/hooks#normalizeendpointurlusing

It should solve your problem.

cody-gawr commented 1 year ago

I didn't know that Scribe was providing a Hook functionality. I think it will fix my problems. Thank you very much.

image