|
11 | 11 | use WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\Utils\RemoteSpecificationLoader; |
12 | 12 |
|
13 | 13 | return static function (Application $application, MiddlewareFactory $middlewareFactory): void { |
14 | | - $specPath = getenv('OPENAPI_SPEC') ?: null; |
| 14 | + $specPath = getenv('OPENAPI_SPEC') ?: null; |
15 | 15 | $packageRoot = realpath(__DIR__ . '/..') ?: '/app'; |
16 | 16 |
|
17 | | - if ($specPath === null || $specPath === false) { |
| 17 | + if (null === $specPath || false === $specPath) { |
18 | 18 | $specPath = $packageRoot . '/data/openapi.yaml'; |
19 | 19 | } elseif (!str_starts_with((string) $specPath, '/') && !str_starts_with((string) $specPath, 'http')) { |
20 | 20 | $resolveBase = str_contains($packageRoot, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR) |
|
33 | 33 | $content = file_exists($path) ? file_get_contents($path) : null; |
34 | 34 | } |
35 | 35 |
|
36 | | - if ($content === false || $content === null) { |
| 36 | + if (false === $content || null === $content) { |
37 | 37 | return new TextResponse('OpenAPI spec not found at ' . $path, 404); |
38 | 38 | } |
39 | 39 |
|
|
67 | 67 | } |
68 | 68 |
|
69 | 69 | // Determine the correct spec URL for Swagger UI |
70 | | - $path = (string) $specPath; |
| 70 | + $path = (string) $specPath; |
71 | 71 | $parsedPath = parse_url($path, PHP_URL_PATH) ?: $path; |
72 | | - $extension = strtolower(pathinfo($parsedPath, PATHINFO_EXTENSION)); |
73 | | - $specUrl = $extension === 'json' ? '/openapi.json' : '/openapi.yaml'; |
| 72 | + $extension = strtolower(pathinfo($parsedPath, PATHINFO_EXTENSION)); |
| 73 | + $specUrl = 'json' === $extension ? '/openapi.json' : '/openapi.yaml'; |
74 | 74 |
|
75 | 75 | $html = <<<HTML |
76 | | -<!DOCTYPE html> |
77 | | -<html lang="en"> |
78 | | -<head> |
79 | | - <meta charset="utf-8" /> |
80 | | - <meta name="viewport" content="width=device-width, initial-scale=1" /> |
81 | | - <meta name="description" content="SwaggerUI" /> |
82 | | - <title>OpenAPI Mock Server - Swagger UI</title> |
83 | | - <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5/swagger-ui.css" /> |
84 | | - <style> |
85 | | - html { box-sizing: border-box; overflow: -moz-scrollbars-vertical; overflow-y: scroll; } |
86 | | - *, *:before, *:after { box-sizing: inherit; } |
87 | | - body { margin: 0; background: #fafafa; } |
88 | | - </style> |
89 | | -</head> |
90 | | -<body> |
91 | | -<div id="swagger-ui"></div> |
92 | | -<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js" crossorigin></script> |
93 | | -<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-standalone-preset.js" crossorigin></script> |
94 | | -<script> |
95 | | - window.onload = () => { |
96 | | - window.ui = SwaggerUIBundle({ |
97 | | - url: '$specUrl', |
98 | | - dom_id: '#swagger-ui', |
99 | | - deepLinking: true, |
100 | | - presets: [ |
101 | | - SwaggerUIBundle.presets.apis, |
102 | | - SwaggerUIStandalonePreset |
103 | | - ], |
104 | | - plugins: [ |
105 | | - SwaggerUIBundle.plugins.DownloadUrl |
106 | | - ], |
107 | | - layout: "BaseLayout", |
108 | | - }); |
109 | | - }; |
110 | | -</script> |
111 | | -</body> |
112 | | -</html> |
113 | | -HTML; |
| 76 | + <!DOCTYPE html> |
| 77 | + <html lang="en"> |
| 78 | + <head> |
| 79 | + <meta charset="utf-8" /> |
| 80 | + <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 81 | + <meta name="description" content="SwaggerUI" /> |
| 82 | + <title>OpenAPI Mock Server - Swagger UI</title> |
| 83 | + <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5/swagger-ui.css" /> |
| 84 | + <style> |
| 85 | + html { box-sizing: border-box; overflow: -moz-scrollbars-vertical; overflow-y: scroll; } |
| 86 | + *, *:before, *:after { box-sizing: inherit; } |
| 87 | + body { margin: 0; background: #fafafa; } |
| 88 | + </style> |
| 89 | + </head> |
| 90 | + <body> |
| 91 | + <div id="swagger-ui"></div> |
| 92 | + <script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js" crossorigin></script> |
| 93 | + <script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-standalone-preset.js" crossorigin></script> |
| 94 | + <script> |
| 95 | + window.onload = () => { |
| 96 | + window.ui = SwaggerUIBundle({ |
| 97 | + url: '$specUrl', |
| 98 | + dom_id: '#swagger-ui', |
| 99 | + deepLinking: true, |
| 100 | + presets: [ |
| 101 | + SwaggerUIBundle.presets.apis, |
| 102 | + SwaggerUIStandalonePreset |
| 103 | + ], |
| 104 | + plugins: [ |
| 105 | + SwaggerUIBundle.plugins.DownloadUrl |
| 106 | + ], |
| 107 | + layout: "BaseLayout", |
| 108 | + }); |
| 109 | + }; |
| 110 | + </script> |
| 111 | + </body> |
| 112 | + </html> |
| 113 | + HTML; |
| 114 | + |
114 | 115 | return new HtmlResponse($html); |
115 | 116 | }, 'home'); |
116 | 117 | }; |
0 commit comments