Skip to content

bug: the script field in Route is limited to map, instead of string #1275

Closed
@imjoey

Description

@imjoey

Bug report

Describe the bug

In APISIX, we can see the script field in Route is of type string.
https://github.com/apache/apisix/blob/3e19b06293463f52c8d26f0958542fc475ff0fcd/apisix/schema_def.lua#L456

While as creating a Route in manager-api, we forcibly cast the script to map[string]interface{}.

input.Script, err = generateLuaCode(input.Script.(map[string]interface{}))

So if sending a request to manager-api as below,

curl http://127.0.0.1:8000/apisix/admin/routes -X POST -H "Authorization: auth-header" -d '{"uri":"/hello","script":"local _M = {} \n function _M.access(api_ctx) \n ngx.log(ngx.INFO,\"hit access phase\") \n end \nreturn _M","upstream":{"type":"roundrobin","nodes":{"127.0.0.1:1980":1}}}'

manager-api will always complain with the following error:

err; interface conversion: interface {} is string, not map[string]interface {}
[Recovery] 2021/01/12 - 14:23:53 panic recovered:

interface conversion: interface {} is string, not map[string]interface {}
/usr/local/opt/go/libexec/src/runtime/iface.go:261 (0x100cd6e)
	panicdottypeE: panic(&TypeAssertionError{iface, have, want, ""})
/Users/imjoey/Work/apache-apisix/apisix-dashboard/api/internal/handler/route/route.go:332 (0x193d9fe)

As a contrast, the similar request can be successfully processed by APISIX Admin API.

Is such situation mentioned above as expected? Much appreciated.

Expected behavior

manager-api could also accept the script field of string type.

System information

  • OS: macOS
  • Version: latest in master branch

Additional

This issue is also related to #1085, put here for tracking.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions