Skip to content

[PHP] Invalid classes generated if models start with a digit #2392

Closed

Description

@willemstuursma

Some of the models start with a digit. E.g. a small part from my definition:

          "400": {
            "description": "Bad Request Data",
            "schema": {
              "$ref": "#/definitions/400ResponseModel"
            }
          },
          "401": {
            "description": "Unauthorized request",
            "schema": {
              "$ref": "#/definitions/401ResponseModel"
            }
          },

Apparently this works fine in some languages but for the PHP client it generates invalid classnames since PHP classes are not allowed to start with a digit:

/**
 * 400ResponseModel Class Doc Comment
 *
 * @category    Class
 * @description 
 * @package     Supplier\Cybersource
 * @author      http://github.com/swagger-api/swagger-codegen
 * @license     http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
 * @link        https://github.com/swagger-api/swagger-codegen
 */
class 400ResponseModel implements ArrayAccess
{
    /**
      * Array of property to type mappings. Used for (de)serialization 
      * @var string[]
      */
    static $swaggerTypes = array(
    /* ... */

Activity

  1. added this to the v2.1.6 milestone on Mar 16, 2016
  2. wing328 commented on Mar 16, 2016

    @wing328
    Contributor

    @willemstuursma thanks for reporting the issue. Similar to reserved keyword, we'll prepend "Model" to to the model name that starts with number.

  3. wing328 commented on Mar 16, 2016

    @wing328
    Contributor

    The fix has been merged into master. Please pull the latest and give it a try.

  4. willemstuursma commented on Mar 18, 2016

    @willemstuursma
    Author

    Thanks. This looks like a good solution. I am not really sure how I can get the master .jar file? I used the wagger-codegen-cli-2.1.5.jar from the maven repos before.

  5. wing328 commented on Mar 19, 2016

    @wing328
    Contributor

    @willemstuursma please do the following

    git clone https://github.com/swagger-api/swagger-codegen.git
    cd swagger-codegen
    mvn package
    ls ./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions