Skip to content

Commit

Permalink
comments and enum
Browse files Browse the repository at this point in the history
Signed-off-by: hfuss <hayden.fuss@kaleido.io>
  • Loading branch information
onelapahead committed Feb 13, 2024
1 parent 270aa06 commit 000de75
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/ffapi/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (as *apiServer[T]) routeHandler(hf *HandlerFactory, route *Route) http.Hand
// We extend the base ffapi functionality, with standardized DB filter support for all core resources.
// We also pass the Orchestrator context through
ext := route.Extensions.(*APIServerRouteExt[T])
if route.OutputType == "stream" && ext.StreamHandler != nil {
if route.OutputType == RouteOutputTypeStream && ext.StreamHandler != nil {
route.StreamHandler = func(r *APIRequest) (output io.ReadCloser, err error) {
er, err := as.EnrichRequest(r)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ffapi/openapi3.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func CheckObjectDocumented(example interface{}) {

func (sg *SwaggerGen) addOutput(ctx context.Context, doc *openapi3.T, route *Route, op *openapi3.Operation) {
s := i18n.Expand(ctx, i18n.APISuccessResponse)
if route.OutputType == "stream" {
if route.OutputType == RouteOutputTypeStream {
contentType := "application/octet-stream"
if route.StreamOutputContentType != "" {
contentType = route.StreamOutputContentType
Expand Down
18 changes: 12 additions & 6 deletions pkg/ffapi/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,13 @@ type Route struct {
// JSONHandler is a function for handling JSON content type input. Input/Output objects are returned by JSONInputValue/JSONOutputValue funcs
JSONHandler func(r *APIRequest) (output interface{}, err error)
// FormUploadHandler takes a single file upload, and returns a JSON object
FormUploadHandler func(r *APIRequest) (output interface{}, err error)
FormUploadHandler func(r *APIRequest) (output interface{}, err error)
// StreamOutputContentType allows for overriding the default binary (application/octet-stream) with a custom MIME type
StreamOutputContentType string
// StreamHandler allows for custom request handling and non-JSON responses
// StreamHandler allows for custom request handling with explicit stream (io.ReadCloser) responses
StreamHandler func(r *APIRequest) (output io.ReadCloser, err error)

// json or stream
OutputType string

// OutputType for OpenAPI generation, either 'json' or 'stream'. Defaults to 'json' if none is provided
OutputType RouteOutputType
// Deprecated whether this route is deprecated
Deprecated bool
// Tag a category identifier for this route in the generated OpenAPI spec
Expand All @@ -83,6 +82,13 @@ type Route struct {
Extensions interface{}
}

type RouteOutputType string

const (
RouteOutputTypeJSON RouteOutputType = "json"
RouteOutputTypeStream RouteOutputType = "stream"
)

// PathParam is a description of a path parameter
type PathParam struct {
// Name is the name of the parameter, from the Gorilla path mux
Expand Down

0 comments on commit 000de75

Please sign in to comment.