Skip to content
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

[PHP] enum values generated without comma #12411

Open
that-guy-iain opened this issue Jun 12, 2024 · 2 comments
Open

[PHP] enum values generated without comma #12411

that-guy-iain opened this issue Jun 12, 2024 · 2 comments

Comments

@that-guy-iain
Copy link

Description

Enums returns invalid code

public function getFailureReasonAllowableValues()
    {
        return [
            self::FAILURE_REASON_EXPIRED_CARD
            self::FAILURE_REASON_INVALID_DETAILS
            self::FAILURE_REASON_FRAUD
            self::FAILURE_REASON_AUTHENTICATION_REQUIRED
            self::FAILURE_REASON_INVALID_CARD
            self::FAILURE_REASON_GENERAL_DECLINE
            self::FAILURE_REASON_CONTACT_PROVIDER
            self::FAILURE_REASON_LACK_OF_FUNDS
        ];
    }
Swagger-codegen version

Swagger-codegen-v3 docker:latest

Swagger declaration file content or url
description: Payment response
content:
  application/json:
    schema:
      type: object
      properties:
        paid:
          type: boolean
        failure_reason:
          type: string
          nullable: true
          enum: [expired_card, invalid_details, fraud, authentication_required, invalid_card, general_decline, contact_provider, lack_of_funds]
Command line used for generation
docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli-v3:latest generate     -i /local/openapi.yaml     -l php     -o /local/out/php --invoker-package=BillaBear --git-user-id=billabear --git-repo-id=php-sdk
Related issues/PRs

This appears to be related #12404

@loneregister
Copy link

12404 is a circular reference, and while generating client code from swagger.io, I still end up with invalid enums.

@loneregister
Copy link

Example definition as documented:

paths:
  /products:
    get:
      parameters:
      - in: query
        name: color
        required: true
        schema:
          $ref: '#/components/schemas/Color'
      responses:
        '200':
          description: OK
components:
  schemas:
    Color:
      type: string
      enum:
        - black
        - white
        - red
        - green
        - blue

Specific example of real use:

SponsoredProductsLocale:
      type: string
      enum:
        - en_AE
        - de_DE
        - ar_EG
        - es_ES
        - fr_FR
        - en_GB
        - it_IT
        - nl_NL
        - pl_PL
        - en_SA
        - sv_SE
        - tr_TR
        - en_AU
        - en_IN
        - ja_JP
        - en_SG
        - pt_BR
        - en_CA
        - es_MX
        - en_US

In PHP - as generated by editor.swagger.io produces an invalid enum type of:

public static function getAllowableEnumValues()
    {
        return [
            self::EN_AE
            self::DE_DE
            self::AR_EG
            self::ES_ES
            self::FR_FR
            self::EN_GB
            self::IT_IT
            self::NL_NL
            self::PL_PL
            self::EN_SA
            self::SV_SE
            self::TR_TR
            self::EN_AU
            self::EN_IN
            self::JA_JP
            self::EN_SG
            self::PT_BR
            self::EN_CA
            self::ES_MX
            self::EN_US
        ];
    }

The proper output in PHP must be:

public static function getAllowableEnumValues()
    {
        return [
            self::EN_AE,
            self::DE_DE,
            self::AR_EG,
            self::ES_ES,
            self::FR_FR,
            self::EN_GB,
            self::IT_IT,
            self::NL_NL,
            self::PL_PL,
            self::EN_SA,
            self::SV_SE,
            self::TR_TR,
            self::EN_AU,
            self::EN_IN,
            self::JA_JP,
            self::EN_SG,
            self::PT_BR,
            self::EN_CA,
            self::ES_MX,
            self::EN_US,
        ];
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants