Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .generator/src/generator/templates/api.j2
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (a *{{ classname }}) {{ operation.operationId|untitle_case }}Execute(r api{

{%- for name, parameter in operation|parameters if parameter.required %}
{%- set schema = parameter.get("schema") %}
{%- set isPathParam = "*" if parameter.in == "path" else "" %}
{%- set isPathParam = "*" if parameter.in == "path" and not parameter.required else "" %}
{%- if parameter.in != "path" %}
if r.{{ name|variable_name}} == nil {
return {% if returnType %}localVarReturnValue, {% endif %}nil, {{ common_package_name }}.ReportError("{{ name|variable_name}} is required and must be specified")
Expand All @@ -268,12 +268,12 @@ func (a *{{ classname }}) {{ operation.operationId|untitle_case }}Execute(r api{
}
{%- endif %}
{%- if schema.minLength is defined %}
if strlen({{ isPathParam }}r.{{ name|variable_name}}) < {{ schema.minLength }} {
if datadog.Strlen({{ isPathParam }}r.{{ name|variable_name}}) < {{ schema.minLength }} {
return {% if returnType %}localVarReturnValue, {% endif %}nil, {{ common_package_name }}.ReportError("{{ name|variable_name}} must have at least {{ schema.minLength }} elements")
}
{%- endif %}
{%- if schema.maxLength is defined %}
if strlen({{ isPathParam }}r.{{ name|variable_name}}) > {{ schema.maxLength }} {
if datadog.Strlen({{ isPathParam }}r.{{ name|variable_name}}) > {{ schema.maxLength }} {
return {% if returnType %}localVarReturnValue, {% endif %}nil, {{ common_package_name }}.ReportError("{{ name|variable_name}} must have less than {{ schema.maxLength }} elements")
}
{%- endif %}
Expand Down
5 changes: 5 additions & 0 deletions .generator/src/generator/templates/utils.j2
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,8 @@ func ContainsUnparsedObject(i interface{}) (bool, interface{}) {
}
return false, nil
}

// Strlen returns number of runes in string
func Strlen(s string) int {
return utf8.RuneCountInString(s)
}
6 changes: 6 additions & 0 deletions api/datadog/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"reflect"
"strings"
"time"
"unicode/utf8"
)

// PtrBool is a helper routine that returns a pointer to given boolean value.
Expand Down Expand Up @@ -441,3 +442,8 @@ func ContainsUnparsedObject(i interface{}) (bool, interface{}) {
}
return false, nil
}

// Strlen returns number of runes in string
func Strlen(s string) int {
return utf8.RuneCountInString(s)
}