@@ -4633,7 +4633,7 @@ public function __construct(Router $router, Responder $responder, OpenApiService
46334633
46344634 public function openapi (ServerRequestInterface $ request ): ResponseInterface
46354635 {
4636- return $ this ->responder ->success ($ this ->openApi ->get ());
4636+ return $ this ->responder ->success ($ this ->openApi ->get ($ request ));
46374637 }
46384638 }
46394639}
@@ -9195,6 +9195,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
91959195// file: src/Tqdev/PhpCrudApi/OpenApi/OpenApiBuilder.php
91969196namespace Tqdev \PhpCrudApi \OpenApi {
91979197
9198+ use Psr \Http \Message \ServerRequestInterface ;
91989199 use Tqdev \PhpCrudApi \Column \ReflectionService ;
91999200 use Tqdev \PhpCrudApi \OpenApi \OpenApiDefinition ;
92009201
@@ -9217,21 +9218,19 @@ public function __construct(ReflectionService $reflection, array $base, array $c
92179218 }
92189219 }
92199220
9220- private function getServerUrl (): string
9221+ private function getServerUrl (ServerRequestInterface $ request ): string
92219222 {
9222- $ protocol = @$ _SERVER ['HTTP_X_FORWARDED_PROTO ' ] ?: @$ _SERVER ['REQUEST_SCHEME ' ] ?: ((isset ($ _SERVER ["HTTPS " ]) && $ _SERVER ["HTTPS " ] == "on " ) ? "https " : "http " );
9223- $ port = @intval ($ _SERVER ['HTTP_X_FORWARDED_PORT ' ]) ?: @intval ($ _SERVER ["SERVER_PORT " ]) ?: (($ protocol === 'https ' ) ? 443 : 80 );
9224- $ host = @explode (": " , $ _SERVER ['HTTP_HOST ' ])[0 ] ?: @$ _SERVER ['SERVER_NAME ' ] ?: @$ _SERVER ['SERVER_ADDR ' ];
9225- $ port = ($ protocol === 'https ' && $ port === 443 ) || ($ protocol === 'http ' && $ port === 80 ) ? '' : ': ' . $ port ;
9226- $ path = @trim (substr ($ _SERVER ['REQUEST_URI ' ], 0 , strpos ($ _SERVER ['REQUEST_URI ' ], '/openapi ' )), '/ ' );
9227- return sprintf ('%s://%s%s/%s ' , $ protocol , $ host , $ port , $ path );
9223+ $ uri = $ request ->getUri ();
9224+ $ path = $ uri ->getPath ();
9225+ $ uri = $ uri ->withPath (trim (substr ($ path , 0 , strpos ($ path , '/openapi ' )), '/ ' ));
9226+ return $ uri ->__toString ();
92289227 }
92299228
9230- public function build (): OpenApiDefinition
9229+ public function build (ServerRequestInterface $ request ): OpenApiDefinition
92319230 {
92329231 $ this ->openapi ->set ("openapi " , "3.0.0 " );
92339232 if (!$ this ->openapi ->has ("servers " ) && isset ($ _SERVER ['REQUEST_URI ' ])) {
9234- $ this ->openapi ->set ("servers|0|url " , $ this ->getServerUrl ());
9233+ $ this ->openapi ->set ("servers|0|url " , $ this ->getServerUrl ($ request ));
92359234 }
92369235 if ($ this ->records ) {
92379236 $ this ->records ->build ();
@@ -9873,6 +9872,7 @@ private function setTag(int $index, string $tableName) /*: void*/
98739872// file: src/Tqdev/PhpCrudApi/OpenApi/OpenApiService.php
98749873namespace Tqdev \PhpCrudApi \OpenApi {
98759874
9875+ use Psr \Http \Message \ServerRequestInterface ;
98769876 use Tqdev \PhpCrudApi \Column \ReflectionService ;
98779877 use Tqdev \PhpCrudApi \OpenApi \OpenApiBuilder ;
98789878
@@ -9885,9 +9885,9 @@ public function __construct(ReflectionService $reflection, array $base, array $c
98859885 $ this ->builder = new OpenApiBuilder ($ reflection , $ base , $ controllers , $ customBuilders );
98869886 }
98879887
9888- public function get (): OpenApiDefinition
9888+ public function get (ServerRequestInterface $ request ): OpenApiDefinition
98899889 {
9890- return $ this ->builder ->build ();
9890+ return $ this ->builder ->build ($ request );
98919891 }
98929892 }
98939893}
0 commit comments