2323use RonasIT \AutoDoc \Traits \GetDependenciesTrait ;
2424use RonasIT \AutoDoc \Validators \SwaggerSpecValidator ;
2525use Symfony \Component \HttpFoundation \Response ;
26- use Exception ;
26+ use Throwable ;
2727
2828/**
2929 * @property SwaggerDriverContract $driver
@@ -73,6 +73,10 @@ public function __construct(Container $container)
7373 $ this ->setDriver ();
7474
7575 if (config ('app.env ' ) === 'testing ' ) {
76+ // client must enter at least `contact.email` to generate a default `info` block
77+ // otherwise an exception will be called
78+ $ this ->checkEmail ();
79+
7680 $ this ->container = $ container ;
7781
7882 $ this ->security = $ this ->config ['security ' ];
@@ -134,12 +138,6 @@ protected function setDriver()
134138
135139 protected function generateEmptyData (?string $ view = null , array $ viewData = [], array $ license = []): array
136140 {
137- // client must enter at least `contact.email` to generate a default `info` block
138- // otherwise an exception will be called
139- if (!empty ($ this ->config ['info ' ]) && !Arr::get ($ this ->config , 'info.contact.email ' )) {
140- throw new EmptyContactEmailException ();
141- }
142-
143141 if (empty ($ view ) && !empty ($ this ->config ['info ' ])) {
144142 $ view = $ this ->config ['info ' ]['description ' ];
145143 }
@@ -165,6 +163,13 @@ protected function generateEmptyData(?string $view = null, array $viewData = [],
165163 return $ data ;
166164 }
167165
166+ protected function checkEmail (): void
167+ {
168+ if (!empty ($ this ->config ['info ' ]) && !Arr::get ($ this ->config , 'info.contact.email ' )) {
169+ throw new EmptyContactEmailException ();
170+ }
171+ }
172+
168173 protected function generateSecurityDefinition (): ?array
169174 {
170175 if (empty ($ this ->security )) {
@@ -796,18 +801,6 @@ protected function getActionName($uri): string
796801 return Str::camel ($ action );
797802 }
798803
799- /**
800- * @deprecated method is not in use
801- * @codeCoverageIgnore
802- */
803- protected function saveTempData ()
804- {
805- $ exportFile = Arr::get ($ this ->config , 'files.temporary ' );
806- $ data = json_encode ($ this ->data );
807-
808- file_put_contents ($ exportFile , $ data );
809- }
810-
811804 public function saveProductionData ()
812805 {
813806 if (ParallelTesting::token ()) {
@@ -831,8 +824,12 @@ public function getDocFileContent()
831824 $ documentation = $ this ->driver ->getDocumentation ();
832825
833826 $ this ->openAPIValidator ->validate ($ documentation );
834- } catch (Exception $ exception ) {
835- return $ this ->generateEmptyData ($ this ->config ['defaults ' ]['error ' ], ['message ' => $ exception ->getMessage ()]);
827+ } catch (Throwable $ exception ) {
828+ return $ this ->generateEmptyData ($ this ->config ['defaults ' ]['error ' ], [
829+ 'message ' => $ exception ->getMessage (),
830+ 'type ' => $ exception ::class,
831+ 'error_place ' => $ this ->getErrorPlace ($ exception ),
832+ ]);
836833 }
837834
838835 $ additionalDocs = config ('auto-doc.additional_paths ' , []);
@@ -852,6 +849,18 @@ public function getDocFileContent()
852849 return $ documentation ;
853850 }
854851
852+ protected function getErrorPlace (Throwable $ exception ): string
853+ {
854+ $ firstTraceEntry = Arr::first ($ exception ->getTrace ());
855+
856+ $ formattedTraceEntry = Arr::map (
857+ array: $ firstTraceEntry ,
858+ callback: fn ($ value , $ key ) => $ key . '= ' . (is_array ($ value ) ? json_encode ($ value ) : $ value ),
859+ );
860+
861+ return implode (', ' , $ formattedTraceEntry );
862+ }
863+
855864 protected function camelCaseToUnderScore ($ input ): string
856865 {
857866 preg_match_all ('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)! ' , $ input , $ matches );
@@ -973,7 +982,7 @@ protected function prepareInfo(?string $view = null, array $viewData = [], array
973982 if (!empty ($ view )) {
974983 $ info ['description ' ] = view ($ view , $ viewData )->render ();
975984 }
976-
985+
977986 return array_merge ($ this ->config ['info ' ], $ info );
978987 }
979988
0 commit comments