Skip to content

Commit

Permalink
fix: properties:{} validate failed
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxiran committed Nov 3, 2020
1 parent f1d47ee commit 1741b19
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/internal/core/store/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"regexp"

"github.com/xeipuuv/gojsonschema"
"go.uber.org/zap/buffer"
Expand Down Expand Up @@ -231,6 +232,8 @@ func (v *APISIXJsonSchemaValidator) Validate(obj interface{}) error {

//check plugin json schema
plugins, schemaType := getPlugins(obj)
//fix lua json.encode transform lua{properties={}} to json{"properties":[]}
reg := regexp.MustCompile(`\"properties\":\[\]`)
if plugins != nil {
for pluginName, pluginConf := range plugins {
var schemaDef string
Expand All @@ -242,6 +245,7 @@ func (v *APISIXJsonSchemaValidator) Validate(obj interface{}) error {
return fmt.Errorf("scheme validate failed: schema not found, path: %s", "plugins."+pluginName)
}

schemaDef = reg.ReplaceAllString(schemaDef, `"properties":{}`)
s, err := gojsonschema.NewSchema(gojsonschema.NewStringLoader(schemaDef))
if err != nil {
return fmt.Errorf("scheme validate failed: %w", err)
Expand Down

0 comments on commit 1741b19

Please sign in to comment.