@@ -950,17 +950,23 @@ public function convertExampleXmlToObject(string $xml): array
950950 $ root = new \SimpleXMLElement ($ xml );
951951
952952 $ toArray = function (\SimpleXMLElement $ node ) use (&$ toArray ) {
953- if (!count ($ node ->children ())) {
953+ if (!count ($ node ->children ()) && ! count ( $ node -> attributes ()) ) {
954954 return trim ((string )$ node );
955955 }
956- // Group children by tag name; repeated names become arrays
956+
957+ // Handle any attributes
957958 $ grouped = [];
959+ foreach ($ node ->attributes () as $ attribute ) {
960+ $ grouped ['oaXmlAttributes ' ][] = [$ attribute ->getName () => (string ) $ attribute ];
961+ }
962+
963+ // Group children by tag name; repeated names become arrays
958964 foreach ($ node ->children () as $ child ) {
959965 $ name = $ child ->getName ();
960966 $ grouped [$ name ][] = $ toArray ($ child );
961967 }
962968 return array_map (function ($ items ) {
963- return (count ($ items ) === 1 ) ? $ items[ 0 ] : $ items ;
969+ return (count ($ items ) === 1 ) ? array_pop ( $ items) : $ items ;
964970 }, $ grouped );
965971 };
966972
@@ -1014,7 +1020,7 @@ protected function determineResponses(array $rules, string $plugin, string $meth
10141020
10151021 // If the return type is void, use the generic response type
10161022 if (empty ($ successArray ['ref ' ]) && !empty ($ returnType ) && strval ($ returnType ) === 'void ' ) {
1017- $ successArray ['ref ' ] = '#/components/responses/GenericSuccessNoBody ' ;
1023+ $ successArray ['ref ' ] = '#/components/responses/GenericSuccess ' ;
10181024 }
10191025
10201026 // If it's a generic type and there's no custom description, use one of the global generic responses
@@ -1389,6 +1395,7 @@ public function buildPropertyAnnotationFromXmlExample(string $propName, array $v
13891395 sprintf ('type="%s", ' , $ type ),
13901396 ];
13911397
1398+ $ hasAttributes = false ;
13921399 $ childLines = [];
13931400 // Recursively check if any of the children are arrays
13941401 foreach ($ values as $ key => $ value ) {
@@ -1397,6 +1404,13 @@ public function buildPropertyAnnotationFromXmlExample(string $propName, array $v
13971404 continue ;
13981405 }
13991406
1407+ // Special handling for XML attributes
1408+ if ($ key === 'oaXmlAttributes ' ) {
1409+ $ hasAttributes = true ;
1410+ $ childLines [] = $ this ->buildXmlAttributeSchemaLines ($ value );
1411+ continue ;
1412+ }
1413+
14001414 // Handle nested arrays
14011415 if (!is_string ($ key )) {
14021416 if (!is_array (reset ($ value ))) {
@@ -1421,7 +1435,7 @@ public function buildPropertyAnnotationFromXmlExample(string $propName, array $v
14211435
14221436 // Handle arrays of strings which don't have named properties
14231437 $ originalKeys = array_keys ($ originalValues );
1424- if (!is_string (reset ($ originalKeys )) && !is_string (reset ($ values ))) {
1438+ if (!is_string (reset ($ originalKeys )) && !is_string (reset ($ values )) && ! $ hasAttributes ) {
14251439 $ itemProperties = ['type="string" ' ];
14261440 }
14271441
@@ -1431,6 +1445,23 @@ public function buildPropertyAnnotationFromXmlExample(string $propName, array $v
14311445 return ['@OA\Property ' => array_merge ($ propertyLines , $ childLines )];
14321446 }
14331447
1448+ public function buildXmlAttributeSchemaLines (array $ attributes ): array
1449+ {
1450+ $ attributeSchemaLines = [];
1451+ foreach ($ attributes as $ index => $ attribute ) {
1452+ $ key = is_array ($ attribute ) ? array_keys ($ attribute )[0 ] : $ index ;
1453+ $ value = is_array ($ attribute ) ? $ attribute [$ key ] : $ attribute ;
1454+ $ attributeSchemaLines [] = ['@OA\Property ' => [
1455+ "property= \"$ key \", " ,
1456+ 'type="string", ' ,
1457+ '@OA\Xml(attribute=true), ' ,
1458+ "example= \"$ value \"" ,
1459+ ]];
1460+ }
1461+
1462+ return $ attributeSchemaLines ;
1463+ }
1464+
14341465 /**
14351466 * Take a list of lines and remove the trailing comma from the last line.
14361467 *
0 commit comments