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

Generated PHP classes sometimes contain invalid chars #1145

Closed
jamiehannaford opened this issue Aug 28, 2015 · 9 comments
Closed

Generated PHP classes sometimes contain invalid chars #1145

jamiehannaford opened this issue Aug 28, 2015 · 9 comments

Comments

@jamiehannaford
Copy link

If I reference the following in my Swagger schema:

"parameters": [
   {
      "name": "cat",
      "in": "body",
      "description": "The JSON payload for the new cat",
      "required": true,
      "schema": {
         "$ref": "cat-new.json"
      }
   }
]

Then it will generate a model file called Cat-new.php, with a Cat-new class inside, which is prohibited. Ideally we should be generating CatNew rather than Cat_New.

@jamiehannaford jamiehannaford changed the title Generated PHP classes sometimes contain invalid classes Generated PHP classes sometimes contain invalid chars Aug 28, 2015
@wing328
Copy link
Contributor

wing328 commented Aug 28, 2015

@jamiehannaford is cat-new a model? if yes, it should be defined as #/definitions/CatNew

Ref: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.json#L238

Seems like the parameter is related to creating new "cat". I simply name it as just "cat"

@wing328
Copy link
Contributor

wing328 commented Aug 28, 2015

@jamiehannaford also do you mind sharing with us how your swagger spec is generated? Is that using some third-party swagger plug-ins?

@jamiehannaford
Copy link
Author

@wing328 But there are different permutations of the model, depending on the operation. For example, when creating a cat the user would not send an id property, which would be returned when all cats are listed. I've renamed the file to catNew.json, but it'd be great if filenames can be formatted to suit the language constraints.

All that's happening above is that I'm referencing an externally defined model schema. I'm not using a third-party plugin.

@wing328
Copy link
Contributor

wing328 commented Aug 28, 2015

@jamiehannaford Thanks for sharing with me how the swagger spec was created and it's definitely valid to use relative schema file in swagger spec.

But I couldn't repeat the issue with the following:

        "parameters": [
          {
            "in": "body",
            "name": "body",
            "description": "Pet object that needs to be added to the store",
            "required": false,
            "schema": {
              "$ref": "new-Pet.json"
            }
          }
        ],

manually created a file named "new-Pet.json" and ran ./bin/php-petstore.sh but didn't get any "New_Pet" model.

Do you mind sharing with me what the content of catNew.json looks like?

@jamiehannaford
Copy link
Author

Sure, it's here. Please note I renamed it from cat-new.json to catNew.json after your first message

@wing328
Copy link
Contributor

wing328 commented Aug 28, 2015

Thanks. But still no luck in reproducing the issue. I'll given it another try this weekend.

@xhh
Copy link
Contributor

xhh commented Sep 21, 2015

Hey @jamiehannaford, I can reproduce it with this model (in definitions):

"cat-new": {
    "$ref": "cat-new.json"
}

which would generate the model file: lib/Model/Cat-new.php
Is your case like this? That is, it should have nothing to do with parameters.

If so, changing the key (model name) to CatNew will work:

"CatNew": {
    "$ref": "cat-new.json"
}

@jamiehannaford
Copy link
Author

@xhh Yep, that's it.

I didn't see any documentation which indicated that camel case was the only acceptable format. IMO, the code generator needs to always convert class names so they end up being idiomatic in the outputted language, regardless of input.

wing328 added a commit that referenced this issue Sep 23, 2015
Fix #1145: sanitize model name in PHP client
@jamiehannaford
Copy link
Author

Thanks @xhh! 😄

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

3 participants