2121use PhpApi \Swagger \Model \Path ;
2222use PhpApi \Swagger \Model \RequestBody ;
2323use PhpApi \Swagger \Model \RequestObjectParseResults ;
24+ use PhpApi \Swagger \Model \RequestObjectQueryParam ;
2425use PhpApi \Swagger \Model \Response ;
2526use PhpApi \Swagger \Model \ResponseContent ;
2627use PhpApi \Swagger \Model \Schema ;
@@ -126,14 +127,15 @@ private function generateSwagger(array $urls): SwaggerDoc
126127 throw new InvalidArgumentException ("Intersection types are not supported " );
127128 }
128129
130+ // TODO: This should be an attribute
129131 $ description = $ reflectionMethod ->getDocComment ();
130132 if ($ description == false ) {
131133 $ description = $ reflectionMethod ->getName ();
132134 }
133135
134136 $ paths [$ cleanPath ][strtolower ($ method )] = new Path (
135137 tags: [],
136- summary: $ description ,
138+ summary: $ description , //TODO: Add summary attribute to the method
137139 description: $ description ,
138140 operationId: $ method . '_ ' . $ reflectionClass ->getName (),
139141 parameters: $ parameters ,
@@ -163,7 +165,7 @@ private function generateSwagger(array $urls): SwaggerDoc
163165 url: $ this ->swaggerOptions ->externalDocsUrl ,
164166 description: $ this ->swaggerOptions ->externalDocsDescription ,
165167 ),
166- tags: [],
168+ tags: [], // TODO: tags for endpoints
167169 paths: $ paths ,
168170 );
169171 }
@@ -185,12 +187,15 @@ private function parseRequestType(ReflectionNamedType|ReflectionUnionType $refle
185187 throw new InvalidArgumentException ("Return type must be a subclass of AbstractResponse " );
186188 }
187189
188- foreach ($ parsedType ->queryParams as $ name => $ schema ) {
190+ foreach ($ parsedType ->queryParams as $ name => $ propertyData ) {
189191 $ parameters [] = new Parameter (
190192 name: $ name ,
191193 in: 'query ' ,
192- required: !$ type ->allowsNull (),
193- schema: $ schema ,
194+ required: !$ reflectionType ->allowsNull ()
195+ && !$ parsedType ->allowsNull
196+ && !$ propertyData ->allowsNull ,
197+ schema: $ propertyData ->schema ,
198+ description: $ propertyData ->description ,
194199 );
195200 }
196201 } else {
@@ -231,16 +236,15 @@ private function parseRequestType(ReflectionNamedType|ReflectionUnionType $refle
231236
232237 $ parsedType = $ this ->parseNamedRequestType ($ reflectionType , $ method );
233238
234- foreach ($ parsedType ->queryParams as $ name => $ schema ) {
239+ foreach ($ parsedType ->queryParams as $ name => $ propertyData ) {
235240 $ parameters [] = new Parameter (
236241 name: $ name ,
237242 in: 'query ' ,
238- // This does not work with nullable properties becuase the schema does not have a
239- // required property. This data, along with "description" will have to be pulled
240- // up from the property class. This should probably be done with a wrapper on the
241- // schema
242- required: !$ reflectionType ->allowsNull () && !$ parsedType ->allowsNull ,
243- schema: $ schema ,
243+ required: !$ reflectionType ->allowsNull ()
244+ && !$ parsedType ->allowsNull
245+ && !$ propertyData ->allowsNull ,
246+ schema: $ propertyData ->schema ,
247+ description: $ propertyData ->description ,
244248 );
245249 }
246250
@@ -257,6 +261,7 @@ private function parseRequestType(ReflectionNamedType|ReflectionUnionType $refle
257261 return null ;
258262 }
259263
264+ // TODO: Request object descriptions
260265 return new RequestBody (
261266 required: !$ reflectionType ->allowsNull (),
262267 content: $ content ,
@@ -284,7 +289,12 @@ private function parseNamedRequestType(ReflectionNamedType $reflectionType, stri
284289 }
285290
286291 if ($ paramType ->type === InputParamType::Query) {
287- $ queryContent [$ paramType ->name ] = $ this ->getSchemaFromClass ($ propertyType );
292+ $ queryContent [$ paramType ->name ] = new RequestObjectQueryParam (
293+ schema: $ this ->getSchemaFromClass ($ propertyType ),
294+ allowsNull: $ propertyType ->allowsNull ()
295+ || $ paramType ->hasDefaultValue ,
296+ description: '' // TODO: Add description attribute to the property
297+ );
288298 } elseif ($ paramType ->type === InputParamType::Json) {
289299 if ($ inputContentType === null ) {
290300 $ inputContentType = InputParamType::Json;
0 commit comments