Skip to content
Closed
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
34 changes: 28 additions & 6 deletions pkg/codegen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Schema struct {

SkipOptionalPointer bool // Some types don't need a * in front when they're optional

ForceCodeAsString bool //Some non string types need to encode/decode as string

Description string // The description of the element

UnionElements []UnionElement // Possible elements of oneOf/anyOf union
Expand Down Expand Up @@ -559,6 +561,18 @@ func oapiSchemaToGoType(schema *openapi3.Schema, path []string, outSchema *Schem
case "string":
// Special case string formats here.
switch f {
case "int64":
outSchema.GoType = "int64"
outSchema.ForceCodeAsString = true
case "uint64":
outSchema.GoType = "uint64"
outSchema.ForceCodeAsString = true
case "double":
outSchema.GoType = "float64"
outSchema.ForceCodeAsString = true
case "float":
outSchema.GoType = "float32"
outSchema.ForceCodeAsString = true
case "byte":
outSchema.GoType = "[]byte"
case "email":
Expand Down Expand Up @@ -651,15 +665,23 @@ func GenFieldsFromProperties(props []Property) []string {

fieldTags := make(map[string]string)

if !omitEmpty {
fieldTags["json"] = p.JsonFieldName

fieldTags["json"] = p.JsonFieldName
if p.NeedsFormTag {
fieldTags["form"] = p.JsonFieldName
}

if omitEmpty {
fieldTags["json"] = fieldTags["json"] + ",omitempty"
if p.NeedsFormTag {
fieldTags["form"] = p.JsonFieldName
fieldTags["form"] = fieldTags["form"] + ",omitempty"
}
} else {
fieldTags["json"] = p.JsonFieldName + ",omitempty"
}

if p.Schema.ForceCodeAsString {
fieldTags["json"] = fieldTags["json"] + ",string"
if p.NeedsFormTag {
fieldTags["form"] = p.JsonFieldName + ",omitempty"
fieldTags["form"] = fieldTags["form"] + ",string"
}
}

Expand Down