Closed manuelpeiso closed 8 months ago
As noted in #543 I will not accept this PR as-is. I feel the potential for BC breaks is too high. If you are keen on introducing a programmatic solution to this issue, then my preference would likely be a configuration option that explicitly controls the behavior you are seeking rather than relying on SAPI. This solution could probably be added to your existing PR with minimal changes and with the added benefit of no potential for BC breaks.
Also, I believe the issue you have identified here was previously identified and has been resolved in version 3.x of this library. I elected to not port it down because of some reason, probably laziness. Ultimately, I moved the poorly performing operations out of the constructor (bad coding practice anyways) and handled building openapi this way:
I believe this is basically what you've accomplished in this PR in a roundabout way.
The SwaggerFactory creates an instance of RouteScanner and also an instance of ModelScanner. No matter what, the RouteScanner is going to read all the routes and the ModelScanner is going to iterate over all the tables. This behavior is quite rare when the hotReload is set to false, because the expected behavior would be to read the swagger.json and return the proper view (why to check routes and schema if we are not generating the swagger.json?)
This PR goal is to avoid this, avoid to load routes and schema in the swagger instance when the request is coming from the web and the hotReload configuration key is set to false. The CLI requests are excluded because even when hotReload is set to false we need to check routes and schema when, for example, the command
bin/cake swagger bake
is execute.