DoclerLabs / api-client-generator

API client generator is a console application capable of generating an API client based on OpenAPI(Swagger) specification.
MIT License
31 stars 19 forks source link

String Enum with integers fails abruptly #69

Closed vsouz4 closed 2 years ago

vsouz4 commented 2 years ago

wrong parameter (string enum with int values)

    EnabledFilter:
      in: query
      name: enabled
      schema:
        type: string
        enum:
          - 0
          - 1

Output from generator:

Backup original source.
 Restore original source from backup.

Expected: error message (e.g. "Error on mapping enabled: Only string enum fields are currently supported"). This message is already shown if you set type: integer instead.

vsouz4 commented 2 years ago

Generator was failing abruptly because of TypeError:

TypeError: Argument 2 passed to DoclerLabs\ApiClientGenerator\Naming\SchemaNaming::getEnumConstName() must be of the type string, int given, called in /generator/src/Generator/Mu
tatorAccessorClassGeneratorAbstract.php on line 109 and defined in /generator/src/Naming/SchemaNaming.php:39

Instead of just identifying this scenario and presenting error message, I opened PR for adding support for numeric enums. The only caveat is that we ain't generating constants for these.