Skip to content

Commit

Permalink
imp: improved the tuple generation
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Apr 22, 2024
1 parent 1a9d798 commit 90b8fb0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions pkg/codegen/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,9 @@ func generateDefinitionType(f *jen.File, name string, schema *schemas.JSONSchema
)
case schemas.TypeNameArray:
switch {
case schema.MaxItems != nil && schema.MinItems != nil && *schema.MaxItems == *schema.MinItems && len(schema.Items) == *schema.MaxItems:
err := generateDefinitionTuple(f, name, schema)
if err != nil {
return err
}
case len(schema.Items) > 1 && !slices.ContainsFunc(schema.Items, func(s schemas.JSONSchema) bool { return len(s.Type) != 1 || s.Type[0] != schema.Items[0].Type[0] }):
// This case means that all items have the same type. This is similar to having an array of a single item.
fallthrough
case len(schema.Items) == 1 && schema.MaxItems == nil && schema.MinItems == nil:
item := &schema.Items[0]
itemName, err := getType(name, item, nil, "")
Expand All @@ -173,6 +171,11 @@ func generateDefinitionType(f *jen.File, name string, schema *schemas.JSONSchema
f.Type().Id(name).Index().Id(itemName)

RegisterDefinition(itemName, item)
case schema.MaxItems != nil && schema.MinItems != nil && *schema.MaxItems == *schema.MinItems && len(schema.Items) == *schema.MaxItems:
err := generateDefinitionTuple(f, name, schema)
if err != nil {
return err
}
default:
return fmt.Errorf("unsupported array definition %s", name)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package types

// Version is the current version of the package
const Version = "0.1.1"
const Version = "0.1.3"

0 comments on commit 90b8fb0

Please sign in to comment.