nelmio / NelmioApiDocBundle

Generates documentation for your REST API from annotations
MIT License
2.22k stars 834 forks source link

[Bug]: Not all integer range types supported #2252

Open RobertMe opened 4 months ago

RobertMe commented 4 months ago

Version

4.25.0

Description

The release notes of 4.24.0 mention that integer range types are now supported, and links to PHPStans documentation for an explanation. But it seems like non-negative-int, which is on that list, isn't supported?

When I use:

        /**
         * @var non-negative-int
         */
        #[Assert\Range(min: 0)]
        #[Property(
            description: '...',
        )]
        public readonly int $pageNumber = 0;

A LogicException is thrown:

Schema of type "\\\non-negative-int" can't be generated, no describer supports it. Class "\\\non-negative-int" does not exist, did you forget a use statement, or typed it wrong?

And the same applies to non-positive-int as well.

Additional context

No response

DjordyKoert commented 4 months ago

Sadly non-negative-int is not supported, you can read more about it in the related PR discussion https://github.com/nelmio/NelmioApiDocBundle/pull/2236#discussion_r1524883343

RobertMe commented 4 months ago

Hmm, bit strange that the release notes mention something which doesn't work then (i.e.: linking to PHPStan documentation listing type names which aren't supported).

As a work-a-round I'm now using int<0, max>, which behaves identical / for which non-negative-int is an alias. So it seems a bit odd that one "style" works and the other doesn't.

DjordyKoert commented 4 months ago

As a work-a-round I'm now using int<0, max>, which behaves identical / for which non-negative-int is an alias. So it seems a bit odd that one "style" works and the other doesn't.

It is odd yes, you could try and open an issue or maybe even a PR at https://github.com/phpDocumentor/TypeResolver about this issue 😄