You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to get my custom processor to get a good swagger.json for arrays. I've tried to use the PhpDocParser but noticed it gets a bit complex after a while. Then I looked at how doctypes are handled by and saw the extractVarTypeAndDescription method. It uses some regex that won't really work with array shapes.
Current behavior could be preserved pretty easily:
functionextractVarTypeAndDescription(?string$docblock): array
{
$config = newParserConfig([]);
$lexer = newLexer($config);
$constExprParser = newConstExprParser($config);
$parser = newPhpDocParser($config, newTypeParser($config, $constExprParser), $constExprParser);
$tokens = newTokenIterator($lexer->tokenize($docblock));
$phpDocNode = $parser->parse($tokens);
$varTags = $phpDocNode->getVarTagValues();
// Not sure if a var tag can have more than 1?foreach ($varTagsas$varTag) {
if($varTag->typeinstanceof IdentifierTypeNode){
return ['type' => $varTag->type->name, 'description' => $varTag->description?:null];
}
}
}
But there probably need to be changes in some more places to handle cases like NullableTypeNode and UnionTypeNode. Since the mapNativeType is also a bit rudimentary
I've been trying to get my custom processor to get a good swagger.json for arrays. I've tried to use the PhpDocParser but noticed it gets a bit complex after a while. Then I looked at how doctypes are handled by and saw the extractVarTypeAndDescription method. It uses some regex that won't really work with array shapes.
Let's take a simple one:
/* @var array{id: int, name: string} */
Calling the extract on it returns:
Which results in:
Which isn't the desired result.
The text was updated successfully, but these errors were encountered: