Skip to content

Commit e12ddc5

Browse files
committed
sq
1 parent 3a15f2e commit e12ddc5

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

‎examples/generate/serverurls/gen.go‎

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

‎examples/generate/serverurls/gen_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestServerUrlTheProductionAPIServer(t *testing.T) {
1212
t.Run("when no values are provided, it does not error", func(t *testing.T) {
13-
serverUrl, err := ServerUrlTheProductionAPIServer("", "", "", "")
13+
serverUrl, err := NewServerUrlTheProductionAPIServer("", "", "", "")
1414
require.NoError(t, err)
1515

1616
assert.Equal(t, "https://.gigantic-server.com:/", serverUrl)
@@ -23,7 +23,7 @@ func TestServerUrlTheProductionAPIServer(t *testing.T) {
2323
// TODO:when we validate enums, this will need more testing
2424
t.Run("when values that are not part of the enum are provided, it does not error", func(t *testing.T) {
2525
invalidPort := ServerUrlTheProductionAPIServerPortVariable("12345")
26-
serverUrl, err := ServerUrlTheProductionAPIServer(
26+
serverUrl, err := NewServerUrlTheProductionAPIServer(
2727
ServerUrlTheProductionAPIServerBasePathVariableDefault,
2828
ServerUrlTheProductionAPIServerNoDefaultVariable(""),
2929
invalidPort,
@@ -35,7 +35,7 @@ func TestServerUrlTheProductionAPIServer(t *testing.T) {
3535
})
3636

3737
t.Run("when default values are provided, it does not error", func(t *testing.T) {
38-
serverUrl, err := ServerUrlTheProductionAPIServer(
38+
serverUrl, err := NewServerUrlTheProductionAPIServer(
3939
ServerUrlTheProductionAPIServerBasePathVariableDefault,
4040
ServerUrlTheProductionAPIServerNoDefaultVariable(""),
4141
ServerUrlTheProductionAPIServerPortVariableDefault,

‎pkg/codegen/templates/server-urls.tmpl‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ const {{ .GoName}} = "{{ .OAPISchema.URL }}"
2323

2424
{{ if $v.Default }}
2525
{{ if gt (len $v.Enum) 0 }}
26-
{{/* if we have an enum, we should use the type defined for it for its default value
27-
and reference the constant we've already defined for the value */}}
28-
{{/* TODO this may result in broken generated code if any of the `enum` values are the literal value `default` */}}
29-
{{/* TODO this may result in broken generated code if the `default` isn't found in `enum` (which is an issue with the spec) */}}
26+
{{/* if we have an enum, we should use the type defined for it for its default value
27+
and reference the constant we've already defined for the value */}}
28+
{{/* TODO this may result in broken generated code if any of the `enum` values are the literal value `default` */}}
29+
{{/* TODO this may result in broken generated code if the `default` isn't found in `enum` (which is an issue with the spec) */}}
3030
// {{ $prefix }}Default is the default choice, for the accepted values for the `{{ $k }}` variable for {{ $goName }}
3131
const {{ $prefix }}Default {{ $prefix }} = {{ $prefix }}{{ $v.Default | ucFirst }}
3232
{{ else }}
@@ -37,14 +37,14 @@ const {{ .GoName}} = "{{ .OAPISchema.URL }}"
3737
{{ end }}
3838

3939

40-
// {{ .GoName }} defines the Server URL for {{ .OAPISchema.Description }}, with the provided variables.
41-
func {{ .GoName }}({{ genServerURLWithVariablesFunctionParams .GoName .OAPISchema.Variables }}) (string, error) {
40+
// New{{ .GoName }} constructs the Server URL for {{ .OAPISchema.Description }}, with the provided variables.
41+
func New{{ .GoName }}({{ genServerURLWithVariablesFunctionParams .GoName .OAPISchema.Variables }}) (string, error) {
4242
u := "{{ .OAPISchema.URL }}"
4343

4444
{{ range $k, $v := .OAPISchema.Variables }}
4545
{{- $placeholder := printf "{%s}" $k -}}
46-
{{- if gt (len $v.Enum) 0 -}}
47-
// TODO in the future, this will validate that the value is part of the {{ printf "%s%sVariable" $goName ($k | ucFirst) }} enum
46+
{{- if gt (len $v.Enum) 0 -}}
47+
// TODO in the future, this will validate that the value is part of the {{ printf "%s%sVariable" $goName ($k | ucFirst) }} enum
4848
{{ end -}}
4949
u = strings.ReplaceAll(u, "{{ $placeholder }}", string({{ $k }}))
5050
{{ end }}

0 commit comments

Comments
 (0)