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 source file "Swagger.php" seems to have an error (suffix "[1]" causes parse error) #614

Closed
jfiala opened this issue Apr 9, 2015 · 4 comments
Milestone

Comments

@jfiala
Copy link
Contributor

jfiala commented Apr 9, 2015

swagger-codegen-2.1.2-M1:
After generating PHP source files using
com.wordnik.swagger.codegen.Codegen -i http://localhost:8080/api-docs -l php

{"apiVersion":"1.0","apis":[{"description":"getUser","operations":[{"method":"GET","summary":"read User by ID","notes":"pass ID to read user","nickname":"getUser","produces":["*/*"],"consumes":["application/json"],"parameters":[{"allowMultiple":false,"defaultValue":"","description":"id","name":"id","paramType":"query","format":"int64","type":"integer","required":true}],"responseMessages":[{"code":200,"message":"Successful retrieval of user detail","responseModel":"User"},{"code":404,"message":"User not found","responseModel":"Void"}],"deprecated":"false","type":"User"}],"path":"/user"},{"description":"saveUser","operations":[{"method":"POST","summary":"create or update a user name by id","notes":"saveUser","nickname":"saveUser","produces":["*/*"],"consumes":["application/json"],"parameters":[{"allowMultiple":false,"defaultValue":"","description":"id","name":"id","paramType":"query","format":"int64","type":"integer","required":true},{"allowMultiple":false,"defaultValue":"","description":"name","name":"name","paramType":"query","type":"string","required":true}],"responseMessages":[{"code":200,"message":"User has been updated","responseModel":"User"}],"deprecated":"false","type":"User"}],"path":"/user"}],"basePath":"/","consumes":["application/json"],"models":{"User":{"description":"User object","id":"User","properties":{"id":{"description":"ID of the user","required":true,"format":"int64","type":"integer"},"bytes":{"items":{"format":"byte","type":"string"},"required":false,"type":"array"},"name":{"description":"Name of the user","required":true,"type":"string"},"state":{"enum":["ACTIVE","DISABLED"],"required":false,"type":"string"}}}},"produces":["*/*"],"resourcePath":"/user","swaggerVersion":"1.2"}

and calling the API in PHP 5 using:

$apiClient = new APIClient("http://localhost:8080", "");
$userApi = new UserApi($apiClient);
$userApi->getUser(1);

I get:
PHP Parse error: syntax error, unexpected '[' in J:\dev_php_new\confess-demo-client\Swagger.php on line 235

Swagger.php, line 235:
$subClass = explode(',', $inner, 2)[1];

after manually removing the suffix [1]:
$subClass = explode(',', $inner, 2);

it runs without any error.

@fehguy fehguy added this to the v2.1.0 milestone Apr 9, 2015
@fehguy
Copy link
Contributor

fehguy commented Apr 9, 2015

Please pull master, which is 2.1.0-M2 and retest.

@jfiala
Copy link
Contributor Author

jfiala commented Apr 9, 2015

Perfect, it now works without any code changes.
However, the root PHP file is named "SwaggerPetstore.php", which is quite confusing as my code doesn't have to do with the Petstore at all...

@wing328
Copy link
Contributor

wing328 commented Apr 10, 2015

@jfiala the PHP package name is hard-coded at the moment. I believe @fehguy is working on exposing a configuration object for package name #583

@jfiala
Copy link
Contributor Author

jfiala commented Apr 10, 2015

Perfect, so I'm closing this as the issue itself has been fixed with 2.1.0-M2.

@jfiala jfiala closed this as completed Apr 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants