Skip to content

Commit

Permalink
imp: improved Tuple generation (#32)
Browse files Browse the repository at this point in the history
* imp: improved the tuple generation

* docs: added changelog and fixed license
  • Loading branch information
srdtrk committed Apr 22, 2024
1 parent 1a9d798 commit bd1814a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## v0.1.2 (2024-04-10)
## v0.1.3 (2024-04-22)

- Fixed issue [#30](https://github.com/srdtrk/go-codegen/issues/30)

## v0.1.2 (2024-04-19)

- Fixed issue [#26](https://github.com/srdtrk/go-codegen/issues/26)

Expand Down
30 changes: 14 additions & 16 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
Copyright 2024 go-codegen authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

===

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down Expand Up @@ -190,3 +174,17 @@
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

Copyright 2024 go-codegen authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
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 bd1814a

Please sign in to comment.