Skip to content

Commit 118f5f9

Browse files
authored
Merge pull request #1429 from tdakkota/fix/uri-additional-properties-encoder
fix(gen): properly handle `ir.Map` when generating parameter encoders
2 parents 01652bd + e968f4e commit 118f5f9

File tree

6 files changed

+106
-3
lines changed

6 files changed

+106
-3
lines changed

gen/_template/uri.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{{- template "header" $ }}
44

55
{{- range $_, $t := $.Types }}
6-
{{- if and ($t.HasFeature "uri") $t.IsStruct }}
6+
{{- if and ($t.HasFeature "uri") (or $t.IsStruct $t.IsMap) }}
77
{{- template "uri/encoders" $t }}
88
{{- end }}
99
{{- end }}

gen/_template/uri/decode.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
return nil
7474
{{- else if $t.IsStruct }}
7575
return {{ $var }}.DecodeURI(d)
76+
{{- else if $t.IsMap }}
77+
return {{ $var }}.DecodeURI(d)
7678
{{- else }}
7779
{{ errorf "unexpected kind" $t.Kind }}
7880
{{- end }}

gen/_template/uri/encode.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
return nil
3939
{{- else if $t.IsStruct }}
4040
return {{ $var }}.EncodeURI(e)
41+
{{- else if $t.IsMap }}
42+
return {{ $var }}.EncodeURI(e)
4143
{{- else }}
4244
{{ errorf "unexpected kind %s" $t.Kind }}
4345
{{- end }}

gen/_template/uri/encoders_map.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (s *{{ $.Name }}) DecodeURI(d uri.Decoder) error {
3333
propertiesCount++
3434
{{- end }}
3535
{{- if $.MapPattern }}
36-
switch match, err := pattern.Match(k); {
36+
switch match, err := pattern.MatchString(k); {
3737
case err != nil:
3838
return errors.Wrap(err, "execute regex")
3939
case !match:

gen/write.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,6 @@ func (g *Generator) hasParams() bool {
385385

386386
func (g *Generator) hasURIObjectParams() bool {
387387
return g.hasAnyType(func(t *ir.Type) bool {
388-
return t.IsStruct() && t.HasFeature("uri")
388+
return (t.IsStruct() || t.IsMap()) && t.HasFeature("uri")
389389
})
390390
}

internal/integration/test_additionalpropertiespatternproperties/oas_uri_gen.go

Lines changed: 99 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)