StydeNet / enlighten

Enlighten your APIs with auto-generated documentation
MIT License
575 stars 32 forks source link

Docblocks cannot be parsed correctly because of line endings #52

Closed ajcastro closed 3 years ago

ajcastro commented 3 years ago

Currently getting the docbloc annotations depends on parsing the string $docComment and exploding it in by PHP_EOL. This brings an issue when some files are not in correct line endings. Also docblocks like this /** @enlighten {"order": 4} **/ does not work because the current implementation has splice(1, -1).

image

I propose to change it into something like the code below and I think this works better:

   protected static function fromDocComment($docComment)
    {
        $str = \Str::between($docComment, '@enlighten {', '}');

        $decoded = json_decode('{'.$str.'}', true) ?? [];

        return collect([
            'enlighten' => ['include' => true] + $decoded
        ]);
    }
sileence commented 3 years ago

@ajcastro now you'll be able to have a one line annotation but we're not supporting several annotations on a single line.

I couldn't fix the issue if the test has inconsistent line ending. I think you can fix that with your editor or with git.