-
Notifications
You must be signed in to change notification settings - Fork 937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array shapes support #1676
Comments
Fair point. I think I mayredo that for v5 still, but I am not inclined to write more ad-hoc docblock parsing code. |
Current behavior could be preserved pretty easily: function extractVarTypeAndDescription(?string $docblock): array
{
$config = new ParserConfig([]);
$lexer = new Lexer($config);
$constExprParser = new ConstExprParser($config);
$parser = new PhpDocParser($config, new TypeParser($config, $constExprParser), $constExprParser);
$tokens = new TokenIterator($lexer->tokenize($docblock));
$phpDocNode = $parser->parse($tokens);
$varTags = $phpDocNode->getVarTagValues();
// Not sure if a var tag can have more than 1?
foreach ($varTags as $varTag) {
if($varTag->type instanceof 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 |
Yep, gets tricky pretty quick. Good for adding support for multiple types, though. |
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: