Skip to content
Closed
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
3 changes: 3 additions & 0 deletions pkg/codegen/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ type OutputOptions struct {

// ClientResponseBytesFunction decides whether to enable the generation of a `Bytes()` method on response objects for `ClientWithResponses`
ClientResponseBytesFunction bool `yaml:"client-response-bytes-function,omitempty"`

// DefaultNumberFormat is the default format to use for numbers when no format is specified in the OpenAPI schema. If not specified or empty, the default format is `float`.
DefaultNumberFormat string `yaml:"default-number-format,omitempty"`
}

func (oo OutputOptions) Validate() map[string]string {
Expand Down
11 changes: 9 additions & 2 deletions pkg/codegen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,17 @@ func oapiSchemaToGoType(schema *openapi3.Schema, path []string, outSchema *Schem
}
outSchema.DefineViaAlias = true
} else if t.Is("number") {
// We default to float for "number"
// We default to float for "number", unless overridden by config
if f == "" {
if globalState.options.OutputOptions.DefaultNumberFormat != "" {
f = globalState.options.OutputOptions.DefaultNumberFormat
} else {
f = "float"
}
}
if f == "double" {
outSchema.GoType = "float64"
} else if f == "float" || f == "" {
} else if f == "float" {
outSchema.GoType = "float32"
} else {
return fmt.Errorf("invalid number format: %s", f)
Expand Down