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

class 'array' not found #189

Closed
ghost opened this issue May 8, 2014 · 4 comments
Closed

class 'array' not found #189

ghost opened this issue May 8, 2014 · 4 comments

Comments

@ghost
Copy link

ghost commented May 8, 2014

I have specified an array as a an operation return type for my operation, yet I seem to get this message in the when attempting to deserialize the server response.

Fatal error: Class 'array' not found in ~/Desktop/src/APIClient.php on line 199

However, according to the swagger-spec listed at the link below, array should be a valid type:
https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md

It seems that swagger-codegen is expecting this to be a user defined type, but according to the specification this is similar to a primitive type (at least that is how it reads).

@ghost
Copy link
Author

ghost commented May 8, 2014

Hmm, is it perhaps because those primitives are defined in another library? I noticed that this piece of code is defined in APIClient.php

function swagger_autoloader($className) {
    $currentDir = dirname(__FILE__);
    if (file_exists($currentDir . '/' . $className . '.php')) {
        include $currentDir . '/' . $className . '.php';
    } elseif (file_exists($currentDir . '/models/' . $className . '.php')) {
        include $currentDir . '/models/' . $className . '.php';
    }
}
spl_autoload_register('swagger_autoloader');

But that line indicates that the classes should be defined in the current working directory of the generated code files... I am a bit lost on this one.

@ellesborough
Copy link

I've seen something very similar generating Python and Java code.

When I have an 'array' defined in the api-docs as the return type of an operation, with an 'items' : { '$ref' : 'ListEntry' }, my mustache template translates the {{returnType}} as 'Array[ListEntry]' even though the Scala typeMapping is set to translate 'Array' to 'list' in Python or 'List' in Java.

If I remove the 'items' in the api-doc, then I get a warning about a missing model, but the {{returnType}} expands to 'list' and in Python my method returns a generic list of dicts which I can live with, but having a list of ListEntry objects is what is supposed to happen.

@fehguy
Copy link
Contributor

fehguy commented Jul 24, 2014

hi, i just did a merge which should fix this. Can you pull master and please try again?

@peterquirk
Copy link

I pulled master last night and tried to use the petstore API with the following test.

from petstore import *
apiUrl = 'http://petstore.swagger.wordnik.com:80/api'
apiKey = 'special_key'

client = swagger.ApiClient(apiKey, apiUrl)
pets = PetApi.PetApi(client)
pet = pets.getPetById(petId=3)
print ("Pet %d has status %s" % (pet.id, pet.status))
 # Get the same pet by querying for pets of the same status
petsFound = pets.findPetsByStatus(status = pet.status)
for otherPet in petsFound:
    print("Pet %d has status %s" % (otherPet.id, otherPet.status))

Python 3.4 generated this output:

Pet 3 has status pending
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
exec(codeObject, main.dict)
File "C:\Python34\Lib\site-packages\testPet\testPet.py", line 10, in
petsFound = pets.findPetsByStatus(status = pet.status)
File "C:\Python34\lib\site-packages\petstore\PetApi.py", line 318, in findPetsByStatus
responseObject = self.apiClient.deserialize(response, 'Array[Pet]')
File "C:\Python34\lib\site-packages\petstore\swagger.py", line 143, in deserialize
objClass = eval(objClass + '.' + objClass)
File "", line 1, in
NameError: name 'Array' is not defined

@fehguy fehguy added this to the v2.1.0-M1 milestone Dec 24, 2014
@fehguy fehguy closed this as completed Feb 16, 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