You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/12/02 07:59:10 UTC

[GitHub] [apisix-dashboard] idbeta commented on a change in pull request #904: feat: support disable property for json schema according to APISIX's change

idbeta commented on a change in pull request #904:
URL: https://github.com/apache/apisix-dashboard/pull/904#discussion_r533962675



##########
File path: api/internal/core/store/validate.go
##########
@@ -238,22 +238,37 @@ func (v *APISIXJsonSchemaValidator) Validate(obj interface{}) error {
 		return err
 	}
 
+	pluginDisableSchema := map[string]map[string]interface{}{
+		"disable": {"type": "boolean"},
+	}
 	plugins, schemaType := getPlugins(obj)
-	//fix lua json.encode transform lua{properties={}} to json{"properties":[]}
-	reg := regexp.MustCompile(`\"properties\":\[\]`)
 	for pluginName, pluginConf := range plugins {
-		var schemaDef string
-		schemaDef = conf.Schema.Get("plugins." + pluginName + "." + schemaType).String()
-		if schemaDef == "" && schemaType == "consumer_schema" {
-			schemaDef = conf.Schema.Get("plugins." + pluginName + ".schema").String()
+		schemaValue := conf.Schema.Get("plugins." + pluginName + "." + schemaType).Value()
+		if schemaValue == nil && schemaType == "consumer_schema" {
+			schemaValue = conf.Schema.Get("plugins." + pluginName + ".schema").Value()
 		}
-		if schemaDef == "" {
-			log.Warnf("schema validate failed: schema not found, path: %s", "plugins."+pluginName)
+		if schemaValue == nil {
+			log.Warnf("schema validate failed: schema not found,  %s, %s", "plugins."+pluginName, schemaType)
 			return fmt.Errorf("schema validate failed: schema not found, path: %s", "plugins."+pluginName)
 		}
+		schemaMap := schemaValue.(map[string]interface{})
+		if schemaMap["type"] != nil && schemaMap["type"].(string) == "object" {
+			if properties, ok := schemaMap["properties"]; ok {
+				propertiesMap := properties.(map[string]interface{})
+				if len(propertiesMap) == 0 {
+					schemaMap["properties"] = pluginDisableSchema
+				}
+			} else {
+				schemaMap["properties"] = pluginDisableSchema
+			}
+		}
+		schemaByte, err := json.Marshal(schemaMap)
+		if err != nil {
+			log.Warnf("scheme validate failed: schema not found, path: %s, %w", "plugins."+pluginName, err)

Review comment:
       `scheme` -> `schema`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org