From a0a10701f8b9dffa4eb81bed3c7103993768ff84 Mon Sep 17 00:00:00 2001 From: Serge Smertin Date: Wed, 10 May 2023 12:57:51 +0200 Subject: [PATCH] Added `in` codegen function --- openapi/code/tmpl_util_funcs.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/openapi/code/tmpl_util_funcs.go b/openapi/code/tmpl_util_funcs.go index 0ab62dbae..b70a9808c 100644 --- a/openapi/code/tmpl_util_funcs.go +++ b/openapi/code/tmpl_util_funcs.go @@ -51,6 +51,14 @@ var HelperFuncs = template.FuncMap{ "list": func(l ...any) []any { return l }, + "in": func(haystack []any, needle string) bool { + for _, v := range haystack { + if needle == fmt.Sprint(v) { + return true + } + } + return false + }, "dict": func(args ...any) map[string]any { if len(args)%2 != 0 { panic("number of arguments to dict is not even")