Skip to content
Draft
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
1 change: 1 addition & 0 deletions internal/common_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type OpenAPIParam struct {

Required bool
Nullable bool
Enum []any
}

// CommonContext is a base context shared by all adaptors (net/http, gin, echo, etc...)
Expand Down
7 changes: 7 additions & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ func buildParam(name string, options ...ParamOption) (OpenAPIParam, *openapi3.Pa
if param.Required {
openapiParam.Required = param.Required
}

// construct enum
for _, enumValue := range param.Enum {
panicsIfNotCorrectType(openapiParam, enumValue)
}
openapiParam.Schema.Value.Enum = param.Enum

for name, exampleValue := range param.Examples {
if openapiParam.Examples == nil {
openapiParam.Examples = make(openapi3.Examples)
Expand Down
7 changes: 7 additions & 0 deletions param.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ func ParamExample(exampleName string, value any) ParamOption {
}
}

// ParamEnum sets the allowed values for the parameter.
func ParamEnum(values ...any) ParamOption {
return func(param *OpenAPIParam) {
param.Enum = values
}
}

// ParamStatusCodes sets the status codes for which this parameter is required.
// Only used for response parameters.
// If empty, it is required for 200 status codes.
Expand Down
3 changes: 3 additions & 0 deletions param/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ var Default = fuego.ParamDefault
// Example adds an example to the parameter. As per the OpenAPI 3.0 standard, the example must be given a name.
var Example = fuego.ParamExample

// Enum sets the allowed values for the parameter.
var Enum = fuego.ParamEnum

// StatusCodes sets the status codes for which this parameter is required.
// Only used for response parameters.
// If empty, it is required for 200 status codes.
Expand Down
Loading