Skip to content

[PHP] Non-leading numbers removed from generated classnames #4211

Closed

Description

@careys7
Description

Trying to generate classes for the Magento 2 schema JSON (which has other issues that need addressing within the schema itself), the versioning that Magento has applied to their API gets removed. I wonder if this should be supported in swagger-codegen?

For example: catalogAttributeSetRepositoryV1 gets converted to an API class of : CatalogAttributeSetRepositoryVApi. The classname CatalogAttributeSetRepositoryV1Api would be legal in PHP (just not if the first character of the class was a number).

Swagger-codegen version

2.2.2-SNAPSHOT

Swagger declaration file content or url

http://devdocs.magento.com/swagger/schemas/latest-2.0.schema.json

{
  "tags": [
    {
      "name": "storeStoreRepositoryV1",
      "description": "Store repository interface"
    },
  ]
}
Command line used for generation

Using jimschubert/swagger-codegen-cli:

docker-compose.yml:

  swagger:
    image: jimschubert/swagger-codegen-cli
    volumes:
      - ./swagger/config:/root/config
      - ./swagger/schema:/root/schema
      - ./swagger/export:/root/export

config.json:

{
  "variableNamingConvention" : "camelCase",
  "invokerPackage" : "SwaggerClient\\MagentoEnterprise212",
  "packagePath" : "MagentoEnterprise212",
  "composerProjectName" : "swaggerclient-magentoenterprise212",
  "gitUserId" : "test"
}

Command:

docker-compose run --rm swagger generate \
            -i /root/schema/magento2/schema.json \
            -l php \
            -o /root/export/result/ \
            -c /root/config/magento2/config.json
Steps to reproduce
  1. Create docker-compose file with service shown above, with host sub-directories shown (./swagger/config,./swagger/schema,./swagger/export)
  2. Download Magento 2 schema to ./swagger/schema/schema.json
  3. Create config.json in ./swagger/config/config.json with contents shown above
  4. Run above command
Related issues

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

Magento 2 - PR 7446 - addressing issue with schema generation.

Suggest a Fix

Activity

  1. added this to the v2.2.2 milestone on Nov 19, 2016
  2. wing328 commented on Nov 19, 2016

    @wing328
    Contributor

    @careysizer agreed with you that non-leading numbers should not be removed.

    I'll try to fix it over the weekend. Will keep you posted.

  3. wing328 commented on Nov 20, 2016

    @wing328
    Contributor

    @careysizer I did a test with the latest master but couldn't repeat the issue. Here is partial result:

    [main] INFO io.swagger.codegen.AbstractGenerator - writing file /var/tmp/php/tag3/SwaggerClient-php/lib/Api/CatalogAttributeSetRepositoryV1Api.php
    [main] INFO io.swagger.codegen.AbstractGenerator - writing file /var/tmp/php/tag3/SwaggerClient-php/test/Api/CatalogAttributeSetRepositoryV1ApiTest.php
    [main] INFO io.swagger.codegen.AbstractGenerator - writing file /var/tmp/php/tag3/SwaggerClient-php/docs/Api/CatalogAttributeSetRepositoryV1Api.md
    

    Did you try building the local JAR based on the latest master?

  4. careys7 commented on Nov 21, 2016

    @careys7
    Author

    Thanks @wing328 - I tested with latest master (I was at cafcf51) and looks like that's working for me too.

  5. wing328 commented on Nov 21, 2016

    @wing328
    Contributor

    Glad to hear that it's working for you.

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