Skip to content

Commit

Permalink
Add parsing for max and min length for response body
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Shulga committed Nov 4, 2023
1 parent a508fe1 commit 996128f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Binary file added main
Binary file not shown.
2 changes: 2 additions & 0 deletions openApi3Schema/oas.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ type SchemaObject struct {
Deprecated bool `json:"deprecated,omitempty"`
Ref string `json:"$ref,omitempty"` // Ref is used when SchemaObject is as a ReferenceObject
Enum interface{} `json:"enum,omitempty"`
MaxLength uint `json:"maxLength,omitempty"`
MinLength uint `json:"minLength,omitempty"`

// Title
// MultipleOf
Expand Down
26 changes: 26 additions & 0 deletions parser/schema/custom_type_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ astFieldsLoop:
if enumValues := astFieldTag.Get("enum"); enumValues != "" {
fieldSchema.Enum = parseEnumValues(enumValues)
}

if maxLength := astFieldTag.Get("maxLength"); maxLength != "" {
fieldSchema.MaxLength = parseMaxLength(maxLength)
}

if minLength := astFieldTag.Get("minLength"); minLength != "" {
fieldSchema.MinLength = parseMinLength(minLength)
}
}

structSchema.Properties.Set(name, fieldSchema)
Expand Down Expand Up @@ -452,6 +460,24 @@ func parseEnumValues(enumString string) interface{} {
return result
}

func parseMaxLength(maxLengthString string) uint {
value, err := strconv.ParseUint(maxLengthString, 10, 64)
if err != nil {
value = 0
}

return uint(value)
}

func parseMinLength(minLengthString string) uint {
value, err := strconv.ParseUint(minLengthString, 10, 64)
if err != nil {
value = 0
}

return uint(value)
}

type DECL struct {
Type struct {
Name string
Expand Down

0 comments on commit 996128f

Please sign in to comment.