1- <?php
1+ <?php
22
33namespace Mezatsong \SwaggerDocs \Definitions ;
44
@@ -75,7 +75,7 @@ function generateSchemas(): array {
7575
7676 if ($ obj instanceof Model) { //check to make sure it is a model
7777 $ reflection = new ReflectionClass ($ obj );
78-
78+
7979 // $with = $reflection->getProperty('with');
8080 // $with->setAccessible(true);
8181
@@ -86,16 +86,15 @@ function generateSchemas(): array {
8686 ->filter (
8787 fn ($ method ) => !empty ($ method ->getReturnType ()) &&
8888 str_contains (
89- $ method ->getReturnType (),
89+ $ method ->getReturnType (),
9090 \Illuminate \Database \Eloquent \Relations::class
9191 )
9292 )
9393 ->pluck ('name ' )
9494 ->all ();
9595
9696 $ table = $ obj ->getTable ();
97- $ list = Schema::connection ($ obj ->getConnectionName ())->getColumnListing ($ table );
98- $ list = array_diff ($ list , $ obj ->getHidden ());
97+ $ columns = Schema::getColumns ($ table );
9998
10099 $ properties = [];
101100 $ required = [];
@@ -110,39 +109,18 @@ function generateSchemas(): array {
110109 $ table = $ prefix . $ table ;
111110 }
112111
113- foreach ($ list as $ item ) {
114-
115- /**
116- * @var \Doctrine\DBAL\Schema\Column
117- */
118- $ column = $ conn ->getDoctrineColumn ($ table , $ item );
119-
120- $ data = $ this ->convertDBalTypeToSwaggerType (
121- Type::getTypeRegistry ()->lookupName ($ column ->getType ())
122- );
123-
124- if ($ data ['type ' ] == 'string ' && ($ len = $ column ->getLength ())) {
125- $ data ['description ' ] .= "( $ len) " ;
126- }
127-
128- $ description = $ column ->getComment ();
112+ foreach ($ columns as $ column ) {
113+ $ description = $ column ['comment ' ];
129114 if (!is_null ($ description )) {
130- $ data ['description ' ] .= ": $ description " ;
115+ $ column ['description ' ] .= ": $ description " ;
131116 }
132117
133- $ default = $ column ->getDefault ();
134- if (!is_null ($ default )) {
135- $ data ['default ' ] = $ default ;
136- }
137-
138- $ data ['nullable ' ] = ! $ column ->getNotnull ();
118+ $ this ->addExampleKey ($ column );
139119
140- $ this -> addExampleKey ( $ data ) ;
120+ $ properties [ $ column [ ' name ' ]] = $ column ;
141121
142- $ properties [$ item ] = $ data ;
143-
144- if ($ column ->getNotnull ()) {
145- $ required [] = $ item ;
122+ if (!$ column ['nullable ' ]) {
123+ $ required [] = $ column ['name ' ];
146124 }
147125 }
148126
@@ -152,7 +130,7 @@ function generateSchemas(): array {
152130 'type ' => 'object ' ,
153131 '$ref ' => '#/components/schemas/ ' . last (explode ('\\' , $ relatedClass )),
154132 ];
155-
133+
156134 $ resultsClass = get_class ((object ) ($ obj ->{$ relationName }()->getResults ()));
157135
158136 if (str_contains ($ resultsClass , \Illuminate \Database \Eloquent \Collection::class)) {
@@ -164,7 +142,7 @@ function generateSchemas(): array {
164142 $ properties [$ relationName ] = $ refObject ;
165143 }
166144 }
167-
145+
168146 // $required = array_merge($required, $with->getValue($obj));
169147
170148 foreach ($ appends ->getValue ($ obj ) as $ item ) {
@@ -204,7 +182,7 @@ function generateSchemas(): array {
204182 'type ' => 'object ' ,
205183 'properties ' => (object ) $ properties ,
206184 ];
207-
185+
208186 if ( ! empty ($ required )) {
209187 $ definition ['required ' ] = $ required ;
210188 }
@@ -295,7 +273,7 @@ private function convertDBalTypeToSwaggerType(string $type): array {
295273 case 'bigserial ' :
296274 case 'bigint ' :
297275 $ property = [
298- 'type ' => 'integer ' ,
276+ 'type ' => 'integer ' ,
299277 'format ' => 'int64 '
300278 ];
301279 break ;
0 commit comments