Skip to content

Commit 4b9844f

Browse files
skarimoci.datadog-api-spec
andauthored
Fix path constraints check (#1833)
* fix path constraints checking * pre-commit fixes Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 08b8829 commit 4b9844f

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

.generator/src/generator/templates/api.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func (a *{{ classname }}) {{ operation.operationId|untitle_case }}Execute(r api{
251251

252252
{%- for name, parameter in operation|parameters if parameter.required %}
253253
{%- set schema = parameter.get("schema") %}
254-
{%- set isPathParam = "*" if parameter.in == "path" else "" %}
254+
{%- set isPathParam = "*" if parameter.in == "path" and not parameter.required else "" %}
255255
{%- if parameter.in != "path" %}
256256
if r.{{ name|variable_name}} == nil {
257257
return {% if returnType %}localVarReturnValue, {% endif %}nil, {{ common_package_name }}.ReportError("{{ name|variable_name}} is required and must be specified")
@@ -268,12 +268,12 @@ func (a *{{ classname }}) {{ operation.operationId|untitle_case }}Execute(r api{
268268
}
269269
{%- endif %}
270270
{%- if schema.minLength is defined %}
271-
if strlen({{ isPathParam }}r.{{ name|variable_name}}) < {{ schema.minLength }} {
271+
if datadog.Strlen({{ isPathParam }}r.{{ name|variable_name}}) < {{ schema.minLength }} {
272272
return {% if returnType %}localVarReturnValue, {% endif %}nil, {{ common_package_name }}.ReportError("{{ name|variable_name}} must have at least {{ schema.minLength }} elements")
273273
}
274274
{%- endif %}
275275
{%- if schema.maxLength is defined %}
276-
if strlen({{ isPathParam }}r.{{ name|variable_name}}) > {{ schema.maxLength }} {
276+
if datadog.Strlen({{ isPathParam }}r.{{ name|variable_name}}) > {{ schema.maxLength }} {
277277
return {% if returnType %}localVarReturnValue, {% endif %}nil, {{ common_package_name }}.ReportError("{{ name|variable_name}} must have less than {{ schema.maxLength }} elements")
278278
}
279279
{%- endif %}

.generator/src/generator/templates/utils.j2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,3 +438,8 @@ func ContainsUnparsedObject(i interface{}) (bool, interface{}) {
438438
}
439439
return false, nil
440440
}
441+
442+
// Strlen returns number of runes in string
443+
func Strlen(s string) int {
444+
return utf8.RuneCountInString(s)
445+
}

api/datadog/utils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"reflect"
1010
"strings"
1111
"time"
12+
"unicode/utf8"
1213
)
1314

1415
// PtrBool is a helper routine that returns a pointer to given boolean value.
@@ -441,3 +442,8 @@ func ContainsUnparsedObject(i interface{}) (bool, interface{}) {
441442
}
442443
return false, nil
443444
}
445+
446+
// Strlen returns number of runes in string
447+
func Strlen(s string) int {
448+
return utf8.RuneCountInString(s)
449+
}

0 commit comments

Comments
 (0)