diff --git a/api/internal/core/store/validate.go b/api/internal/core/store/validate.go index ad3b9781a1..b868b5e291 100644 --- a/api/internal/core/store/validate.go +++ b/api/internal/core/store/validate.go @@ -87,19 +87,19 @@ func NewAPISIXJsonSchemaValidator(jsonPath string) (Validator, error) { }, nil } -func getPlugins(reqBody interface{}) map[string]interface{} { +func getPlugins(reqBody interface{}) (map[string]interface{}, string) { switch reqBody.(type) { case *entity.Route: route := reqBody.(*entity.Route) - return route.Plugins + return route.Plugins, "schema" case *entity.Service: service := reqBody.(*entity.Service) - return service.Plugins + return service.Plugins, "schema" case *entity.Consumer: consumer := reqBody.(*entity.Consumer) - return consumer.Plugins + return consumer.Plugins, "consumer_schema" } - return nil + return nil, "" } func cHashKeySchemaCheck(upstream *entity.UpstreamDef) error { @@ -230,10 +230,14 @@ func (v *APISIXJsonSchemaValidator) Validate(obj interface{}) error { } //check plugin json schema - plugins := getPlugins(obj) + plugins, schemaType := getPlugins(obj) if plugins != nil { for pluginName, pluginConf := range plugins { - schemaDef := conf.Schema.Get("plugins." + pluginName).String() + var schemaDef string + schemaDef = conf.Schema.Get("plugins." + pluginName + "." +schemaType).String() + if (schemaDef == "" && schemaType == "consumer_schema") { + schemaDef = conf.Schema.Get("plugins." + pluginName + ".schema").String() + } if schemaDef == "" { return fmt.Errorf("scheme validate failed: schema not found, path: %s", "plugins."+pluginName) }