swagger-api / swagger-api/swagger-codegen

[PHP] Bug generating client SDK has invalid PHP code

Open
#12,095 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Invalid code is generated when creating a PHP client SDK from a URL. I have made some minor updates to the URL and auth to remove sensative information. I created a gist of the JSON config file that is at the URL and the link is below.

Thank you for the help,
Ken Grigsby

Swagger-codegen version

2.4.31-SNAPSHOT
Unfortunately, I cant use V3 because we are using an internal PHP 7 server.

Swagger declaration file content or url

https://gist.github.com/kengrigsby/885b74d7e61727e0c0fd9ebeeec6c031

Command line used for generation
java -jar swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
    -i "https://windchill.com/Windchill/netmarkets/html/wrs/odata-to-swagger.jsp?v=2&d=BACMgmt" \
    -l php \
    --model-name-prefix "WindchillApiBACMgmt" \
    -o "/home/ABC/kgrigsby/windchillApiClassGeneration/swagger-codegen/generatedClasses/BACMgmt" \
    -a "Authorization:Basic [**redacted**]" \
    -c /home/ABC/kgrigsby/windchillApiClassGeneration/config.json \
    -Dio.swagger.parser.util.RemoteUrl.trustAll=true \
    -Dio.swagger.v3.parser.util.RemoteUrl.trustAll=true \
    --git-repo-id=not_used \
    -DcomposerVendorName=testingwindchill,ProjectName=windchillapi;

config.json

{
    "variableNamingConvention":"camelCase"
}
Steps to reproduce
  1. Executed the generate command.
  2. This PHP code is not valid in file SwaggerClient-php/lib/Api/ServiceEndpointsApi.php
    $resourcePath = '/BACReceivedDeliveries('{BACReceivedDeliveryId}')';
  3. This code is repeated in all of the request functions
    protected function deleteBACReceivedDeliveryRequest($bACReceivedDeliveryId, $cSRFNONCE = null)
Related issues/PRs

I didn't find any.

Suggest a fix/enhancement

I don't know what this code should look like.
$resourcePath = '/BACReceivedDeliveries('{BACReceivedDeliveryId}')';

Maybe escaping the single quotes by adding the "\" character before the single quotes that are in the string.
$resourcePath = '/BACReceivedDeliveries(\'{BACReceivedDeliveryId}\')';

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the PHP client with the listed swagger-codegen CLI command and inspect SwaggerClient-php/lib/Api/ServiceEndpointsApi.php, especially the generated $resourcePath and deleteBACReceivedDeliveryRequest method. Done means the generated file contains valid PHP syntax and all repeated request functions use valid resource paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.