diff --git a/src/Metadata/Converter/Types/Configurator/ElementSingleConfigurator.php b/src/Metadata/Converter/Types/Configurator/ElementSingleConfigurator.php index 66a3236..e30b56c 100644 --- a/src/Metadata/Converter/Types/Configurator/ElementSingleConfigurator.php +++ b/src/Metadata/Converter/Types/Configurator/ElementSingleConfigurator.php @@ -3,6 +3,8 @@ namespace Soap\WsdlReader\Metadata\Converter\Types\Configurator; +use GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef; +use GoetasWebservices\XML\XSDReader\Schema\Element\ElementRef; use GoetasWebservices\XML\XSDReader\Schema\Element\ElementSingle; use Soap\Engine\Metadata\Model\TypeMeta; use Soap\Engine\Metadata\Model\XsdType as EngineType; @@ -17,7 +19,11 @@ public function __invoke(EngineType $engineType, mixed $xsdType, TypesConverterC } // Elements can have inline types. Mark the attribute as a local type in that case. - $innerType = $xsdType->getType(); + $innerType = match (true) { + $xsdType instanceof ElementDef, + $xsdType instanceof ElementRef => null, + default => $xsdType->getType(), + }; $isConsideredAnInlineType = $innerType && $innerType->getName() === null; if ($isConsideredAnInlineType) { $engineType = $engineType->withMeta( diff --git a/src/Metadata/Converter/Types/Detector/ElementTypeNameDetector.php b/src/Metadata/Converter/Types/Detector/ElementTypeNameDetector.php index fb8db0a..0044ed5 100644 --- a/src/Metadata/Converter/Types/Detector/ElementTypeNameDetector.php +++ b/src/Metadata/Converter/Types/Detector/ElementTypeNameDetector.php @@ -2,9 +2,10 @@ namespace Soap\WsdlReader\Metadata\Converter\Types\Detector; +use GoetasWebservices\XML\XSDReader\Schema\Element\Any\Any; use GoetasWebservices\XML\XSDReader\Schema\Element\ElementItem; +use GoetasWebservices\XML\XSDReader\Schema\Element\ElementRef; use GoetasWebservices\XML\XSDReader\Schema\Element\ElementSingle; -use GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType; use GoetasWebservices\XML\XSDReader\Schema\Type\Type; use Soap\WsdlReader\Metadata\Converter\Types\ParentContext; @@ -14,18 +15,31 @@ public function __invoke(ElementItem $element, ParentContext $parentContext, ?st { $type = $element instanceof ElementSingle ? $element->getType() : null; $typeName = $calculatedTypeName ?? ($type?->getName() ?: $element->getName()); + $rootParent = $parentContext->rootParent(); - // For inline simple types, we prefix the name of the element with the name of the parent type. - if ($type instanceof SimpleType && !$type->getName()) { - $parent = $parentContext->currentParent(); + // Add some conditions to validate if the element type name should be modified: + if ( + $rootParent === $element // Dont enhance yourself + || $element instanceof Any // Any types are just objects. 'any' is a proper name here. + || $element instanceof ElementRef // Refs already have a proper name + || $type?->getName() // Named types already have a proper name + ) { + return $typeName; + } + + // Make sure the root parent has a name: + if ( + !$rootParent instanceof Type + && !$rootParent instanceof ElementItem + ) { + return $typeName; + } - if ($parent instanceof Type || $parent instanceof ElementItem) { - if ($parentName = $parent->getName()) { - $typeName = $parentName . ucfirst($typeName); - } - } + $rootParentName = $rootParent->getName(); + if (!$rootParentName) { + return $typeName; } - return $typeName; + return $rootParentName . ucfirst($typeName); } } diff --git a/src/Metadata/Converter/Types/Visitor/ElementVisitor.php b/src/Metadata/Converter/Types/Visitor/ElementVisitor.php index 0c02c07..63bc874 100644 --- a/src/Metadata/Converter/Types/Visitor/ElementVisitor.php +++ b/src/Metadata/Converter/Types/Visitor/ElementVisitor.php @@ -8,6 +8,7 @@ use Soap\Engine\Metadata\Model\Type as EngineType; use Soap\Engine\Metadata\Model\XsdType as MetaType; use Soap\WsdlReader\Metadata\Converter\Types\Configurator; +use Soap\WsdlReader\Metadata\Converter\Types\Detector\ElementTypeNameDetector; use Soap\WsdlReader\Metadata\Converter\Types\TypesConverterContext; use function Psl\Fun\pipe; @@ -35,9 +36,11 @@ public function __invoke(AbstractElementSingle $element, TypesConverterContext $ static fn (MetaType $metaType): MetaType => (new Configurator\ElementConfigurator())($metaType, $element, $context), ); + $name = (new ElementTypeNameDetector())($element, $context->parent()->unwrap(), $element->getName()); + return new TypeCollection( new EngineType( - $configure(MetaType::guess($element->getName())), + $configure(MetaType::guess($name)), (new PropertiesVisitor())($xsdType, $context) ), ...((new InlineElementTypeVisitor())($xsdType, $context)) diff --git a/tests/PhpCompatibility/schema036.phpt b/tests/PhpCompatibility/schema036.phpt index 1105014..9992f1d 100644 --- a/tests/PhpCompatibility/schema036.phpt +++ b/tests/PhpCompatibility/schema036.phpt @@ -26,8 +26,8 @@ Methods: Types: > http://test-uri/:testType { int $int - testType2 $testType2 + testTypeTestType2 $testType2 } - > http://test-uri/:testType2 { + > http://test-uri/:testTypeTestType2 { int $int } diff --git a/tests/PhpCompatibility/schema1002.phpt b/tests/PhpCompatibility/schema1002.phpt index 4a47811..fbcbc67 100644 --- a/tests/PhpCompatibility/schema1002.phpt +++ b/tests/PhpCompatibility/schema1002.phpt @@ -24,10 +24,10 @@ Methods: Types: > http://test-uri/:VoluntaryChangesType { - ?Penalty $Penalty + ?VoluntaryChangesTypePenalty $Penalty @?boolean $VolChangeInd } - > http://test-uri/:Penalty { + > http://test-uri/:VoluntaryChangesTypePenalty { @?string $PenaltyType @?string $DepartureStatus } diff --git a/tests/PhpCompatibility/schema1003.phpt b/tests/PhpCompatibility/schema1003.phpt index 2518ac7..1b07969 100644 --- a/tests/PhpCompatibility/schema1003.phpt +++ b/tests/PhpCompatibility/schema1003.phpt @@ -27,8 +27,8 @@ Methods: Types: > http://test-uri/:SpecialEquipPrefs { - array, SpecialEquipPref> $SpecialEquipPref + array, SpecialEquipPrefsSpecialEquipPref> $SpecialEquipPref } - > http://test-uri/:SpecialEquipPref { + > http://test-uri/:SpecialEquipPrefsSpecialEquipPref { @?string $Action } diff --git a/tests/PhpCompatibility/schema1005.phpt b/tests/PhpCompatibility/schema1005.phpt index 9a60334..772a76a 100644 --- a/tests/PhpCompatibility/schema1005.phpt +++ b/tests/PhpCompatibility/schema1005.phpt @@ -31,12 +31,12 @@ Methods: Types: > http://test-uri/:LoyaltyTravelInfoType { - ?HotelStayInfo $HotelStayInfo - ?AirFlightInfo $AirFlightInfo + ?LoyaltyTravelInfoTypeHotelStayInfo $HotelStayInfo + ?LoyaltyTravelInfoTypeAirFlightInfo $AirFlightInfo } - > http://test-uri/:HotelStayInfo { + > http://test-uri/:LoyaltyTravelInfoTypeHotelStayInfo { ?string $ReservationID } - > http://test-uri/:AirFlightInfo { + > http://test-uri/:LoyaltyTravelInfoTypeAirFlightInfo { ?string $FlightSegment } diff --git a/tests/PhpCompatibility/schema1007.phpt b/tests/PhpCompatibility/schema1007.phpt index c814a19..fa135f9 100644 --- a/tests/PhpCompatibility/schema1007.phpt +++ b/tests/PhpCompatibility/schema1007.phpt @@ -40,9 +40,9 @@ Types: } > http://test-uri/:VerificationType { ?string $Email - ?StartLocation $StartLocation + ?VerificationTypeStartLocation $StartLocation } - > http://test-uri/:StartLocation extends LocationType { + > http://test-uri/:VerificationTypeStartLocation extends LocationType { string $_ @?string $LocationCode @?dateTime $AssociatedDateTime diff --git a/tests/PhpCompatibility/schema1016.phpt b/tests/PhpCompatibility/schema1016.phpt new file mode 100644 index 0000000..cd0d8d1 --- /dev/null +++ b/tests/PhpCompatibility/schema1016.phpt @@ -0,0 +1,50 @@ +--TEST-- +SOAP XML Schema 1016: Group ref with minOccurs / MaxOccurs +--FILE-- + + + + + + + + + + + + + + + + + + + + + + + + + + +EOF; +test_schema($schema,'type="tns:Element"'); +?> +--EXPECT-- +Methods: + > test(Element $testParam): void + +Types: + > http://test-uri/:Code { + string $code + } + > http://test-uri/:SomeSpecificTypeCodeEnum extends string in (foo|bar) + > http://test-uri/:SomeType { + ?SomeTypeCode $code + } + > http://test-uri/:SomeTypeCode extends Code { + ?SomeSpecificTypeCodeEnum in (foo|bar) $code + }