mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-25 01:35:18 -06:00
45a3d8ee70
This commit addresses issues around vendoring the 3rd party GraphQL parser library, `vektah/gqlparser`, which is used by our GraphQL builtins. By directly depending on the library, we accidentally forced all of our library users to have to match `gqlparser` versions, which could cause problems if they wanted to use downstream GraphQL libraries. To fix this version clash problem, this PR internalizes `vektah/gqlparser` v2.4.8 into the `internal/gqlparser` package (we can update to v2.5.0 later). Scripts are included to automate some of the internalizing process if we wish to update the library in the future. Fixes: #5065 Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
40 lines
746 B
Go
40 lines
746 B
Go
package validator
|
|
|
|
import "bytes"
|
|
|
|
// Given [ A, B, C ] return '"A", "B", or "C"'.
|
|
func QuotedOrList(items ...string) string {
|
|
itemsQuoted := make([]string, len(items))
|
|
for i, item := range items {
|
|
itemsQuoted[i] = `"` + item + `"`
|
|
}
|
|
return OrList(itemsQuoted...)
|
|
}
|
|
|
|
// Given [ A, B, C ] return 'A, B, or C'.
|
|
func OrList(items ...string) string {
|
|
var buf bytes.Buffer
|
|
|
|
if len(items) > 5 {
|
|
items = items[:5]
|
|
}
|
|
if len(items) == 2 {
|
|
buf.WriteString(items[0])
|
|
buf.WriteString(" or ")
|
|
buf.WriteString(items[1])
|
|
return buf.String()
|
|
}
|
|
|
|
for i, item := range items {
|
|
if i != 0 {
|
|
if i == len(items)-1 {
|
|
buf.WriteString(", or ")
|
|
} else {
|
|
buf.WriteString(", ")
|
|
}
|
|
}
|
|
buf.WriteString(item)
|
|
}
|
|
return buf.String()
|
|
}
|