knuckleswtf / scribe

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

Scribe using type Laravel hardcodes URL at generate time #431

Closed ElvenSpellmaker closed 2 years ago

ElvenSpellmaker commented 2 years ago

What happened?

  1. I set my configuration to type => 'laravel',
  2. Then I ran php artisan scribe:generate and it generates the blade template
  3. But I saw the APP_URL is hardcoded into the blade template.

instead of using APP_URL at render time.

The problem we have is that we build a Docker image one and use it later and don't have the URLs at the build time and so hardcoded URL from the .env isn't appropriate.

E.g. APP_URL is set to the correct URL on the container, however examples etc are all using the value from .env at build time: image

image

My environment:

shalvah commented 2 years ago

Did you check the config file or docs? https://scribe.knuckles.wtf/blog/2021/06/08/laravel-v3#multiple-urls

ElvenSpellmaker commented 2 years ago

@shalvah Yeah I checked the docs, didn't realise it'd be in a section about multiple URLs because I don't have multiple URLs.

Either way this doesn't fix my problem because it seems to put the URL into blade at build time and not at runtime which makes me rather stuck now.

Edit: Here's the config for those three URLs:

...
    'base_url' => null,
...
    'try_it_out' => [
        'enabled' => true,
        'base_url' => null,
        'use_csrf' => false,
        'csrf_url' => '/sanctum/csrf-cookie',
    ]
...

Edit 2: I don't have permissions to reopen the issue.

shalvah commented 2 years ago

Not really, Scribe is fairly extensible, so you're hardly ever "stuck". Yes, it puts the URLs in at build time. We could change that for Laravel type, but that would be extra complexity and not everyone would want to use APP_URL.

However, you can override the default templates and replace the URL part with your dynamic version. There's a section in the docs about customising.

shalvah commented 2 years ago

Oh, another option: you could use the afterGenerating() hook to do a search and replace.