Skip to content

Commit

Permalink
fix: update validate to support schematype
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxiran committed Nov 3, 2020
1 parent 921a6dc commit f1d47ee
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions api/internal/core/store/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit f1d47ee

Please sign in to comment.