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
2 changes: 1 addition & 1 deletion cfg/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (f FileInput) Merge(from FileInput) FileInput {
return from
}

// MergeTypesMaps Merge merges all properties from an ancestor TypeMap.
// MergeTypesMaps merges all properties from an ancestor TypeMap.
func MergeTypesMaps(maps ...stringlist.StringMap) stringlist.StringMap {
result := stringlist.StringMap{}

Expand Down
12 changes: 8 additions & 4 deletions foji/openapi/handler.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
{{ goToken (camel $param.Value.Name) -}}
{{- if $.ParamIsOptionalType $param }} *{{ end }} {{ $.GetType $package $typeName $param.Value.Schema }},
{{- end -}}
{{- if isNotNil $body}}
{{- $type := $.GetType $package (print $op.OperationID " Request") $body.Schema }} body {{ $type -}}
{{- if $.OpHasExtension $op "x-raw-body" -}}
body io.ReadCloser
{{- else if not (empty $body) -}}
body {{ $.GetType $package (print $op.OperationID " Request") $body.Schema }}
{{- end -}}
) (
{{- $response := $.GetOpHappyResponseType $package .RuntimeParams.op}}
Expand Down Expand Up @@ -357,8 +359,10 @@ func (h OpenAPIHandlers) {{ pascal $op.OperationID}}(w http.ResponseWriter, r *h
}
{{- end}}

{{- $hasBody := not (empty $opBody)}}
{{- if $hasBody }}
{{- $hasBody := or (not (empty $opBody)) ($.OpHasExtension $op "x-raw-body" ) }}
{{- if $.OpHasExtension $op "x-raw-body" }}
Comment thread
leclark marked this conversation as resolved.
body := r.Body
{{- else if not (empty $opBody) }}
{{- $bodyType := $.GetType $package (print $op.OperationID " Request") $opBody.Schema}}
{{- if $opBody.IsJson }}

Expand Down
2 changes: 1 addition & 1 deletion runtime/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func ToSlice(vv ...any) any {
return ss
}

// Numbers numbers returns a slice of strings of the numbers start to end (inclusive).
// Numbers returns a slice of strings of the numbers start to end (inclusive).
func Numbers(start, end int) stringlist.Strings {
var ss stringlist.Strings

Expand Down
20 changes: 20 additions & 0 deletions tests/example/http_handler_gen.go

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

16 changes: 16 additions & 0 deletions tests/example/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,22 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Example"
/examples/rawBody:
get:
operationId: getRawBody
x-raw-body: true
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Foo'
responses:
Comment thread
leclark marked this conversation as resolved.
"200":
description: 'Example'
content:
application/json:
schema:
$ref: "#/components/schemas/Example"
/examples/rawResponse:
get:
operationId: getRawResponse
Expand Down
5 changes: 5 additions & 0 deletions tests/example/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package example

import (
"context"
"io"
"net/http"
"time"

Expand Down Expand Up @@ -74,6 +75,10 @@ func (s *Service) GetRawRequest(r *http.Request, vehicle GetRawRequestVehicle) (
return nil, nil
}

func (s *Service) GetRawBody(ctx context.Context, body io.ReadCloser) (*Example, error) {
return nil, nil
}

func (s *Service) GetRawResponse(ctx context.Context, w http.ResponseWriter, vehicle GetRawResponseVehicle) (*Example, error) {
return nil, nil
}
Expand Down