Parse and validate AT Protocol Lexicons with DTO generation for Laravel
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix NSID fragment handling for proper namespace resolution

+33 -15
+16 -13
src/Generator/MethodGenerator.php
··· 215 215 return "\$data['{$name}'] ?? null"; 216 216 } 217 217 218 - // Handle NSID fragments - extract just the NSID part 218 + // Handle NSID fragments 219 219 if (str_contains($ref, '#')) { 220 - $ref = explode('#', $ref)[0]; 220 + [$baseNsid, $fragment] = explode('#', $ref, 2); 221 + $className = $this->naming->toClassName($fragment); 222 + } else { 223 + $refClass = $this->naming->nsidToClassName($ref); 224 + $className = basename(str_replace('\\', '/', $refClass)); 221 225 } 222 - 223 - $refClass = $this->naming->nsidToClassName($ref); 224 - $className = basename(str_replace('\\', '/', $refClass)); 225 226 226 227 if ($isRequired) { 227 228 return "{$className}::fromArray(\$data['{$name}'])"; ··· 241 242 242 243 // Handle NSID fragments 243 244 if (str_contains($ref, '#')) { 244 - $ref = explode('#', $ref)[0]; 245 + [$baseNsid, $fragment] = explode('#', $ref, 2); 246 + $className = $this->naming->toClassName($fragment); 247 + } else { 248 + $refClass = $this->naming->nsidToClassName($ref); 249 + $className = basename(str_replace('\\', '/', $refClass)); 245 250 } 246 - 247 - $refClass = $this->naming->nsidToClassName($ref); 248 - $className = basename(str_replace('\\', '/', $refClass)); 249 251 250 252 return "isset(\$data['{$name}']) ? array_map(fn (\$item) => {$className}::fromArray(\$item), \$data['{$name}']) : []"; 251 253 } ··· 279 281 foreach ($externalRefs as $ref) { 280 282 // Handle NSID fragments 281 283 if (str_contains($ref, '#')) { 282 - $ref = explode('#', $ref)[0]; 284 + [$baseNsid, $fragment] = explode('#', $ref, 2); 285 + $className = $this->naming->toClassName($fragment); 286 + } else { 287 + $refClass = $this->naming->nsidToClassName($ref); 288 + $className = basename(str_replace('\\', '/', $refClass)); 283 289 } 284 - 285 - $refClass = $this->naming->nsidToClassName($ref); 286 - $className = basename(str_replace('\\', '/', $refClass)); 287 290 $variantClasses[] = "{$className}::class"; 288 291 } 289 292
+17 -2
src/Generator/TypeMapper.php
··· 421 421 // Handle NSID fragments - convert fragment to class name 422 422 if (str_contains($ref, '#')) { 423 423 [$baseNsid, $fragment] = explode('#', $ref, 2); 424 - $namespace = $this->naming->nsidToNamespace($baseNsid); 424 + // For fragments, we need to include ALL segments of the base NSID 425 + // Parse the NSID and convert each segment to PascalCase 426 + $nsid = \SocialDept\Schema\Parser\Nsid::parse($baseNsid); 427 + $segments = $nsid->getSegments(); 428 + $namespaceParts = array_map( 429 + fn ($part) => $this->naming->toPascalCase($part), 430 + $segments 431 + ); 432 + $namespace = $this->naming->getBaseNamespace() . '\\' . implode('\\', $namespaceParts); 425 433 $className = $this->naming->toClassName($fragment); 426 434 427 435 return [$namespace . '\\' . $className]; ··· 449 457 // Handle NSID fragments - convert fragment to class name 450 458 if (str_contains($ref, '#')) { 451 459 [$baseNsid, $fragment] = explode('#', $ref, 2); 452 - $namespace = $this->naming->nsidToNamespace($baseNsid); 460 + // For fragments, we need to include ALL segments of the base NSID 461 + $nsid = \SocialDept\Schema\Parser\Nsid::parse($baseNsid); 462 + $segments = $nsid->getSegments(); 463 + $namespaceParts = array_map( 464 + fn ($part) => $this->naming->toPascalCase($part), 465 + $segments 466 + ); 467 + $namespace = $this->naming->getBaseNamespace() . '\\' . implode('\\', $namespaceParts); 453 468 $className = $this->naming->toClassName($fragment); 454 469 $classes[] = $namespace . '\\' . $className; 455 470 } else {