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

[perl] Referenced Swagger datatype modules are not loaded #6313

Closed
lbordowitz opened this issue Aug 15, 2017 · 2 comments · Fixed by #6500
Closed

[perl] Referenced Swagger datatype modules are not loaded #6313

lbordowitz opened this issue Aug 15, 2017 · 2 comments · Fixed by #6500

Comments

@lbordowitz
Copy link
Contributor

lbordowitz commented Aug 15, 2017

Description

When I have nested objects in a perl client, it doesn't work correctly. I get an error on deserialization:

Can't call method "from_hash" on an undefined value at /lib/WWW/SwaggerClient/Object/Thingy.pm line 133

This happens whenever the type is "number" or when I use a referenced object type. This issue is about the latter case.

Swagger-codegen version

2.2.3

Swagger declaration file content or url

This happens in the PetStore example, and I use that in this test case.

Steps to reproduce

Save this file as test.pl in the samples directory.

Run perl test.pl with all the necessary modules installed. You will get the following error message:

Can't call method "from_hash" on an undefined value at lib/WWW/SwaggerClient/Object/Pet.pm

The reason this problem doesn't come up in the normal test is because all the necessary objects are included as part of the test. This means, in order to use a perl client generated by swagger, you would need to require the end-user to include both the object and all the object's property dependencies transitively. That hardly seem reasonable.

Suggest a fix/enhancement

In the "use" block there should be a bundle of lines that refers to all the datatypes, like use {{moduleName}}::Object::{{datatype}} for each datatype. That way, when the eval is called the $_instance variable won't be undefined. Please make sure to handle ARRAY properties correctly, as well.

@wing328
Copy link
Contributor

wing328 commented Sep 5, 2017

@lbordowitz thanks for reporting the issue. Please file a PR with the suggested fix so that we can review the fix more easily.

@lbordowitz
Copy link
Contributor Author

@wing328 Okay, added change in pull request #6500 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants