Skip to content

Commit

Permalink
better client generation
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Jan 30, 2025
1 parent c0f8347 commit 62c0457
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/Version/Definition/TypeExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected static function extractTypesFromXSD(Config $config, Version $version,
$type = TypeBuilder::build($config, $version, $fhirName, $child, $sourceFile);

// add type
$types->addType($type);
$type = $types->addOrReturnType($type);

// proceed with decoration
SimpleTypeElementTypeDecorator::decorate($config, $types, $type, $child);
Expand All @@ -148,7 +148,7 @@ protected static function extractTypesFromXSD(Config $config, Version $version,
$type = TypeBuilder::build($config, $version, $fhirName, $child, $sourceFile);

// add type
$types->addType($type);
$type = $types->addOrReturnType($type);

// proceed with decoration
ComplexTypeElementTypeDecorator::decorate($config, $types, $type, $child);
Expand All @@ -173,7 +173,7 @@ protected static function extractTypesFromXSD(Config $config, Version $version,
$type = TypeBuilder::build($config, $version, $fhirName, $child, $sourceFile);

// add type
$types->addType($type);
$type = $types->addOrReturnType($type);

// proceed with decoration
ElementElementTypeDecorator::rootDecorate($config, $types, $type, $child);
Expand Down
13 changes: 6 additions & 7 deletions src/Version/Definition/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(Version $version)
// TODO(dcarbone): this sucks.
$xt = new Type($version, PHPFHIR_XHTML_TYPE_NAME);
$xt->setKind(TypeKindEnum::PHPFHIR_XHTML);
$this->addType($xt);
$this->addOrReturnType($xt);
}

/**
Expand Down Expand Up @@ -117,14 +117,14 @@ public function getTypeByFQN(string $fqn, bool $leadingSlash): null|Type
* same type running around...
*
* @param \DCarbone\PHPFHIR\Version\Definition\Type $type
* @return \DCarbone\PHPFHIR\Version\Definition\Types
* @return \DCarbone\PHPFHIR\Version\Definition\Type
*/
public function addType(Type &$type): Types
public function addOrReturnType(Type $type): Type
{
$tname = $type->getFHIRName();
foreach ($this->_types as $current) {
if ($type === $current) {
return $this;
return $current;
}
if ($current->getFHIRName() === $tname) {
// this happens with FHIR types sometimes...
Expand All @@ -136,12 +136,11 @@ public function addType(Type &$type): Types
$type->getSourceFileBasename()
)
);
$type = $current;
return $this;
return $current;
}
}
$this->_types[] = $type;
return $this;
return $type;
}

/**
Expand Down
12 changes: 10 additions & 2 deletions template/versions/core/class_version_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
);

foreach($types->getIterator() as $type) {
if (($type->isResourceType() || $type->hasResourceTypeParent()) && !$type->isAbstract() && !$type->getKind()->isResourceContainer($version)) {
if ($type->hasResourceTypeParent()
&& 'Bundle' !== $type->getFHIRName()
&& 'DomainResource' !== $type->getFHIRName()
&& !$type->isAbstract()
&& !$type->getKind()->isResourceContainer($version)) {
$imports->addVersionTypeImports($type);
}
}
Expand Down Expand Up @@ -212,7 +216,11 @@ protected function _requireOK(<?php echo PHPFHIR_CLIENT_CLASSNAME_RESPONSE; ?> $
}
}
<?php foreach($version->getDefinition()->getTypes()->getNameSortedIterator() as $rsc) :
if (!($rsc->isResourceType() || $rsc->hasResourceTypeParent()) || $rsc->isAbstract() || $rsc->getKind()->isResourceContainer($version)) {
if (!$rsc->hasResourceTypeParent()
|| 'Bundle' === $rsc->getFHIRName()
|| 'DomainResource' === $rsc->getFHIRName()
|| $rsc->isAbstract()
|| $rsc->getKind()->isResourceContainer($version)) {
continue;
}

Expand Down

0 comments on commit 62c0457

Please sign in to comment.