L5-Swagger icon indicating copy to clipboard operation
L5-Swagger copied to clipboard

Issue with route change in version 8.6

Open artem-dev2 opened this issue 7 months ago • 6 comments

After updating composer we noticed that Swagger UI is no longer loads JSON annotations. the version that worked fine was 8.6.3 after the update it is now 8.6.5.

You have removed this segment {jsonFile?} from this route $router->get($config['routes']['docs'].'/{jsonFile?}', []) and now it can't load the json file and shows 500 error.

artem-dev2 avatar May 27 '25 10:05 artem-dev2

Yes this was removed due to path traversal vulnerability. More details here: https://github.com/DarkaOnLine/L5-Swagger/pull/630

DarkaOnLine avatar May 27 '25 12:05 DarkaOnLine

ok, and what is the new way of the handling?

artem-dev2 avatar May 27 '25 16:05 artem-dev2

ok, and what is the new way of the handling?

Register path to your json in config $config['paths']['docs_json'] - https://github.com/DarkaOnLine/L5-Swagger/blob/master/src/Http/Controllers/SwaggerController.php#L46

DarkaOnLine avatar May 28 '25 04:05 DarkaOnLine

I think it was already defined there, what we are missing?

return [
    'default' => 'default',
    'documentations' => [
        'app' => [
            'api' => [
                'title' => 'Snapfix Api Specs for web app',
            ],

            'routes' => [
                /*
                 * Route for accessing api documentation interface
                */
                'api' => 'api/documentation',
            ],
            'paths' => [
                /*
                 * Edit to include full URL in ui for assetreg
                */
                'use_absolute_path' => env('L5_SWAGGER_USE_ABSOLUTE_PATH', true),

                /*
                 * File name of the generated json documentation file
                */
                'docs_json' => 'app.json',

                /*
                 * File name of the generated YAML documentation file
                */
                'docs_yaml' => 'app.yaml',

                /*
                * Set this to `json` or `yaml` to determine which documentation file to use in UI
                */
                'format_to_use_for_docs' => env('L5_FORMAT_TO_USE_FOR_DOCS', 'json'),

                /*
                 * Absolute paths to directory containing the swagger annotations are stored.
                */
                'annotations' => [
                    base_path('app/Http/Controllers/v1/Openapi/App'),
                ],

            ],
        ],
        'admin' => [
            'api' => [
                'title' => 'Snapfix Api Specs for web admin',
            ],

            'routes' => [
                /*
                 * Route for accessing api documentation interface
                */
                'api' => 'api/documentation',
            ],
            'paths' => [
                /*
                 * Edit to include full URL in ui for assetreg
                */
                'use_absolute_path' => env('L5_SWAGGER_USE_ABSOLUTE_PATH', true),

                /*
                 * File name of the generated json documentation file
                */
                'docs_json' => 'admin.json',

                /*
                 * File name of the generated YAML documentation file
                */
                'docs_yaml' => 'admin.yaml',

                /*
                * Set this to `json` or `yaml` to determine which documentation file to use in UI
                */
                'format_to_use_for_docs' => env('L5_FORMAT_TO_USE_FOR_DOCS', 'json'),

                /*
                 * Absolute paths to directory containing the swagger annotations are stored.
                */
                'annotations' => [
                    base_path('app/Http/Controllers/v1/Openapi/Admin'),
                ],

            ],
        ],
   ],

artem-dev2 avatar May 28 '25 07:05 artem-dev2

This broke for me too, I was using multiple config files:

Image

My config:

const ui = SwaggerUIBundle({
  dom_id: '#swagger-ui',
  urls:[
    { url: "/docs/api-docs.json", name: "API" },
    { url: "/docs/files-docs.json", name: "Arquivos" }
  ],
[... more code]

And now how to use my multiple files on the same screen?

viniciusvts avatar Jun 11 '25 21:06 viniciusvts

Could this also have broken ability to generate yaml? Cause I can't make it work.

furai avatar Jun 16 '25 12:06 furai