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
12 changes: 8 additions & 4 deletions internal/test/strict-server/fiber/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions internal/test/strict-server/iris/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions pkg/codegen/templates/strict/strict-fiber-interface.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@
{{$fixedStatusCode := .HasFixedStatusCode -}}
{{$isRef := .IsRef -}}
{{$isExternalRef := .IsExternalRef -}}
{{$ref := .Ref | ucFirst -}}
{{$ref := .Ref | ucFirstWithPkgName -}}
{{$headers := .Headers -}}

{{if (and $hasHeaders (not $isRef)) -}}
type {{$opid}}{{$statusCode}}ResponseHeaders struct {
{{range .Headers -}}
{{.GoName}} {{.Schema.TypeDecl}}
{{.GoName}} {{.GoTypeDef}}
{{end -}}
}
Comment thread
mromaszewicz marked this conversation as resolved.
{{end}}

{{range .Contents}}
{{$receiverTypeName := printf "%s%s%s%s" $opid $statusCode .NameTagOrContentType "Response"}}
{{if and $fixedStatusCode $isRef -}}
{{ if and (not $hasHeaders) ($fixedStatusCode) (.IsSupported) (eq .NameTag "Multipart") -}}
{{ if and (not $hasHeaders) ($fixedStatusCode) (.IsSupported) (or (eq .NameTag "Multipart") (eq .NameTag "Text")) -}}
type {{$receiverTypeName}} {{$ref}}{{.NameTagOrContentType}}Response
{{else if $isExternalRef -}}
type {{$receiverTypeName}} struct { {{$ref}} }
Expand Down Expand Up @@ -82,7 +82,17 @@

func (response {{$receiverTypeName}}) Visit{{$opid}}Response(ctx *fiber.Ctx) error {
{{range $headers -}}
ctx.Response().Header.Set("{{.Name}}", fmt.Sprint(response.Headers.{{.GoName}}))
{{if .IsNullable -}}
if response.Headers.{{.GoName}}.IsSpecified() {
ctx.Response().Header.Set("{{.Name}}", fmt.Sprint(response.Headers.{{.GoName}}.MustGet()))
}
{{else if .IsOptional -}}
if response.Headers.{{.GoName}} != nil {
ctx.Response().Header.Set("{{.Name}}", fmt.Sprint(*response.Headers.{{.GoName}}))
}
{{else -}}
ctx.Response().Header.Set("{{.Name}}", fmt.Sprint(response.Headers.{{.GoName}}))
{{end -}}
{{end -}}
{{if eq .NameTag "Multipart" -}}
writer := multipart.NewWriter(ctx.Response().BodyWriter())
Expand Down
20 changes: 14 additions & 6 deletions pkg/codegen/templates/strict/strict-iris-interface.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@
{{if (and $hasHeaders (not $isRef)) -}}
type {{$opid}}{{$statusCode}}ResponseHeaders struct {
{{range .Headers -}}
{{.GoName}} {{.Schema.TypeDecl}}
{{.GoName}} {{.GoTypeDef}}
{{end -}}
}
{{end}}

{{range .Contents}}
{{$receiverTypeName := printf "%s%s%s%s" $opid $statusCode .NameTagOrContentType "Response"}}
{{if eq .NameTag "Text" -}}
type {{$receiverTypeName}} string
{{else if and $fixedStatusCode $isRef -}}
{{ if and (not $hasHeaders) ($fixedStatusCode) (.IsSupported) (eq .NameTag "Multipart") -}}
{{if and $fixedStatusCode $isRef -}}
{{ if and (not $hasHeaders) ($fixedStatusCode) (.IsSupported) (or (eq .NameTag "Multipart") (eq .NameTag "Text")) -}}
type {{$receiverTypeName}} {{$ref}}{{.NameTagOrContentType}}Response
{{else if $isExternalRef -}}
type {{$receiverTypeName}} struct { {{$ref}} }
Expand Down Expand Up @@ -84,7 +82,17 @@

func (response {{$receiverTypeName}}) Visit{{$opid}}Response(ctx iris.Context) error {
{{range $headers -}}
ctx.ResponseWriter().Header().Set("{{.Name}}", fmt.Sprint(response.Headers.{{.GoName}}))
{{if .IsNullable -}}
if response.Headers.{{.GoName}}.IsSpecified() {
ctx.ResponseWriter().Header().Set("{{.Name}}", fmt.Sprint(response.Headers.{{.GoName}}.MustGet()))
}
{{else if .IsOptional -}}
if response.Headers.{{.GoName}} != nil {
ctx.ResponseWriter().Header().Set("{{.Name}}", fmt.Sprint(*response.Headers.{{.GoName}}))
}
{{else -}}
ctx.ResponseWriter().Header().Set("{{.Name}}", fmt.Sprint(response.Headers.{{.GoName}}))
{{end -}}
{{end -}}
{{if eq .NameTag "Multipart" -}}
writer := multipart.NewWriter(ctx.ResponseWriter())
Expand Down
Loading