pksunkara / alpaca

Given a web API, Generate client libraries in node, php, python, ruby
Mozilla Public License 2.0
2.45k stars 89 forks source link

Error on generate api #72

Open m33ch opened 9 years ago

m33ch commented 9 years ago

Hi,

thank you for this package.

I got an error when i try to generate a php api. This is error

panic: interface conversion: interface is nil, not map[string]interface {}

goroutine 1 [running]:
runtime.panic(0x6ff260, 0xc210086dc0)
    /usr/local/lib/gvm/gos/go1.2/src/pkg/runtime/panic.c:266 +0xb6
github.com/pksunkara/alpaca/alpaca.WritePhp(0xc2100b1b40)
    /usr/local/lib/gvm/pkgsets/go1.2/global/src/github.com/pksunkara/alpaca/alpaca/langs_php.go:37 +0x535
github.com/pksunkara/alpaca/alpaca.WriteLibraries(0xc21000a938)
    /usr/local/lib/gvm/pkgsets/go1.2/global/src/github.com/pksunkara/alpaca/alpaca/alpaca.go:66 +0x88
main.main()
    /usr/local/lib/gvm/pkgsets/go1.2/global/src/github.com/pksunkara/alpaca/main.go:52 +0x21a

goroutine 5 [finalizer wait]:
runtime.park(0x40adc0, 0xaf4450, 0xaf1c68)
    /usr/local/lib/gvm/gos/go1.2/src/pkg/runtime/proc.c:1342 +0x66
runfinq()
    /usr/local/lib/gvm/gos/go1.2/src/pkg/runtime/mgc0.c:2276 +0x84
runtime.goexit()
    /usr/local/lib/gvm/gos/go1.2/src/pkg/runtime/proc.c:1394

Thank you

pksunkara commented 8 years ago

Hey @m33ch, Unfortunately, you are missing something in the doc.json which is being incompatible with the api.json. I am planning to improve the error handling though.

m33ch commented 8 years ago

Hi @pksunkara,

thank you for your reply.

This is my api.json

{
    "base":"http://local.dev",
    "version":"1",
    "authorization":{
        "need_auth":true,
        "header":true
    },
    "request":{
        "formats":{
            "default":"json",
            "form":false,
            "json":true
        }
    },
    "response":{
        "formats":{
            "default":"json",
            "json":true
        },
        "suffix":true
    },
    "error":{
        "message":"error"
    },
    "classes":[
        {
            "name":"discounts",
            "args":[
                "id"
            ],
            "functions":[
                {
                    "name":"index",
                    "method":"get",
                    "path":"/discounts"
                },
                {
                    "name":"show",
                    "method":"get",
                    "path":"/discounts/:id"
                },
                {
                    "name":"store",
                    "path":"/discounts/",
                    "method":"post",
                    "params":[
                        {
                            "name":"name",
                            "required":true
                        },
                        {
                            "name":"value"
                        },
                        {
                            "name":"value_type"
                        },
                        {
                            "name":"status"
                        }
                    ]
                },
                {
                    "name":"update",
                    "path":"/discounts/:id",
                    "method":"post",
                    "params":[
                        {
                            "name":"name",
                            "required":true
                        },
                        {
                            "name":"value"
                        },
                        {
                            "name":"value_type"
                        },
                        {
                            "name":"status"
                        }
                    ]
                },
                {
                    "name":"destroy",
                    "method":"delete",
                    "path":"/discounts/:id"
                }
            ]
        }
    ]
}

And this is doc.json

{
    "discounts":{
        "title":"Discount",
        "desc":"Returns discount api instance",
        "args":{
            "id":{
                "desc":"Id of discount",
                "value":"1"
            }
        },
        "functions" : {
            "index":{
                "title":"Get user discounts",
                "desc":"Retrieve created user discounts"
            },
            "store":{
                "title":"Create new discount",
                "desc":"Create new discount",
                "params":{
                    "name":{
                        "desc":"Name on discount",
                        "value":"Sold Out 50%!"
                    },
                    "value":{
                        "desc":"Value of discount",
                        "value":"20"
                    },
                    "value_type":{
                        "desc":"Type of discount : absolute or percentage",
                        "value":"absolute"
                    },
                    "status":{
                        "desc":"Active discount? (enabled, disabled)",
                        "value":"disabled"
                    }
                }
            },
            "show":{
                "title":"Get a user discount",
                "desc":"Retrieve one discount"
            },
            "destroy":{
                "title":"Delete a user discount",
                "desc":"Delete one discount"
            }
        }
    }
}

That json files are created based on your example.

Thank you very much!

JadedEvan commented 8 years ago

Also having this same issue with both of the examples provided in this repo.

alpaca ~/alpaca/examples/helpful/
panic: interface conversion: interface is nil, not map[string]interface {}

goroutine 1 [running]:
runtime.panic(0x6ff260, 0xc2100bcac0)
        /usr/local/lib/gvm/gos/go1.2/src/pkg/runtime/panic.c:266 +0xb6