示例#1
0
func oneOfMessage(serviceMap RawServiceMap, schema map[string]interface{}, err, nextErr gojsonschema.ResultError) string {
	switch nextErr.Type() {
	case "additional_property_not_allowed":
		property := nextErr.Details()["property"]

		return fmt.Sprintf("contains unsupported option: '%s'", property)
	case "invalid_type":
		if containsTypeError(nextErr) {
			expectedType := addArticle(nextErr.Details()["expected"].(string))

			return fmt.Sprintf("contains %s, which is an invalid type, it should be %s", getValue(serviceMap, nextErr.Context().String()), expectedType)
		}

		validTypes := parseValidTypesFromSchema(schema, err.Context().String())

		validTypesMsg := addArticle(strings.Join(validTypes, " or "))

		return fmt.Sprintf("contains an invalid type, it should be %s", validTypesMsg)
	case "unique":
		contextWithDuplicates := getValue(serviceMap, nextErr.Context().String())

		return fmt.Sprintf("contains non unique items, please remove duplicates from %s", contextWithDuplicates)
	}

	return ""
}
示例#2
0
文件: schema.go 项目: docker/docker
func getDescription(err gojsonschema.ResultError) string {
	if err.Type() == "invalid_type" {
		if expectedType, ok := err.Details()["expected"].(string); ok {
			return fmt.Sprintf("must be a %s", humanReadableType(expectedType))
		}
	}

	return err.Description()
}
示例#3
0
func invalidTypeMessage(service, key string, err gojsonschema.ResultError) string {
	expectedTypesString := err.Details()["expected"].(string)
	var expectedTypes []string

	if strings.Contains(expectedTypesString, ",") {
		expectedTypes = strings.Split(expectedTypesString[1:len(expectedTypesString)-1], ",")
	} else {
		expectedTypes = []string{expectedTypesString}
	}

	validTypesMsg := addArticle(strings.Join(expectedTypes, " or "))

	return fmt.Sprintf("Service '%s' configuration key '%s' contains an invalid type, it should be %s.", service, key, validTypesMsg)
}