Skip to content

Commit

Permalink
Merge pull request #497 from Clever/INFRANG-6383-fix-composite-key-bug
Browse files Browse the repository at this point in the history
[INFRANG-6383] Fix composite key bug, remove auto test generation
  • Loading branch information
andruwm authored Nov 12, 2024
2 parents 615b131 + 1eb4fa7 commit d7d4bc7
Show file tree
Hide file tree
Showing 43 changed files with 723 additions and 97 deletions.
4 changes: 3 additions & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
v9.4.2
v9.5.0

v9.5.0 Bugfix composite keys in a GSI with no range key. Also, generated tests are only added when opted in via a new flag, instead of by default.

v9.4.2 Add updated clientconfig to release

Expand Down
13 changes: 6 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type config struct {
clientLanguage *string
clientOnly *bool
dynamoOnly *bool
withTests *bool
outputPath *string
versionFlag *bool
swaggerFile *string
Expand All @@ -52,7 +53,6 @@ type config struct {
var version string

func main() {

conf := config{
swaggerFile: flag.String("file", "swagger.yml", "the spec file to use"),
goPackageName: flag.String("go-package", "", "package of the generated go code"),
Expand All @@ -63,6 +63,7 @@ func main() {
clientLanguage: flag.String("client-language", "", "generate client code in specific language [go|js]"),
dynamoOnly: flag.Bool("dynamo-only", false, "only generate dynamo code"),
relativeDynamoPath: flag.String("dynamo-path", "", "path to generate dynamo code relative to go package path"),
withTests: flag.Bool("with-tests", false, "generate tests for the generated db code"),
}
flag.Parse()
if *conf.versionFlag {
Expand Down Expand Up @@ -110,7 +111,7 @@ func main() {
}

if conf.generateDynamo {
if err := generateDynamo(conf.dynamoPath, *conf.goPackageName, conf.goAbsolutePackagePath, *conf.relativeDynamoPath, *conf.outputPath, swaggerSpec); err != nil {
if err := generateDynamo(conf.dynamoPath, *conf.goPackageName, conf.goAbsolutePackagePath, *conf.relativeDynamoPath, *conf.outputPath, *conf.withTests, swaggerSpec); err != nil {
log.Fatal(err.Error())
}
}
Expand All @@ -133,7 +134,6 @@ func generateGoModels(packageName, basePath, outputPath string, swaggerSpec spec
return err
}
if err := models.Generate(packageName, basePath, outputPath, swaggerSpec); err != nil {

return fmt.Errorf("Error generating models: %s", err)
}
return nil
Expand All @@ -157,7 +157,6 @@ func generateServer(goPackageName, basePath, outputPath string, swaggerSpec spec

func generateTracing(basePath, outputPath string) error {
if err := prepareDir(filepath.Join(basePath, "servertracing")); err != nil {

return err
}

Expand All @@ -170,11 +169,11 @@ func generateTracing(basePath, outputPath string) error {
return nil
}

func generateDynamo(dynamoPath, goPackageName, basePath, relativeDynamoPath, OutputPath string, swaggerSpec spec.Swagger) error {
func generateDynamo(dynamoPath, goPackageName, basePath, relativeDynamoPath, OutputPath string, withTests bool, swaggerSpec spec.Swagger) error {
if err := prepareDir(dynamoPath); err != nil {
return err
}
if err := gendb.GenerateDB(goPackageName, basePath, OutputPath, &swaggerSpec, relativeDynamoPath); err != nil {
if err := gendb.GenerateDB(goPackageName, basePath, OutputPath, withTests, &swaggerSpec, relativeDynamoPath); err != nil {
return fmt.Errorf("Failed to generate database: %s", err)
}
return nil
Expand Down Expand Up @@ -210,7 +209,7 @@ func prepareDir(dir string) error {
return fmt.Errorf("Could not remove directory: %s, error :%s", dir, err)
}

if err := os.MkdirAll(dir, 0700); err != nil {
if err := os.MkdirAll(dir, 0o700); err != nil {
if !os.IsExist(err.(*os.PathError)) {
return fmt.Errorf("Could not create directory: %s, error: %s", dir, err)
}
Expand Down
20 changes: 10 additions & 10 deletions samples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ TEST_DB_PKG := "./gen-go-db/server/db/dynamodb"
generate:
@echo $(TEST_PKGS) $(TEST_DB_PKG)

../bin/wag -file ./swagger.yml -output-path ./gen-go-basic -js-path ./gen-js
../bin/wag -with-tests -file ./swagger.yml -output-path ./gen-go-basic -js-path ./gen-js
cd ./gen-js && jsdoc2md index.js types.js > ./README.md
go generate -mod=mod ./gen-go-basic...

../bin/wag -file ./deprecated.yml -output-path ./gen-go-deprecated -js-path ./gen-js-deprecated
../bin/wag -with-tests -file ./deprecated.yml -output-path ./gen-go-deprecated -js-path ./gen-js-deprecated
cd ./gen-js-deprecated && jsdoc2md index.js types.js > ./README.md
go generate -mod=mod ./gen-go-deprecated...
../bin/wag -file ./errors.yml -output-path ./gen-go-errors -js-path ./gen-js-errors
../bin/wag -with-tests -file ./errors.yml -output-path ./gen-go-errors -js-path ./gen-js-errors
cd ./gen-js-errors && jsdoc2md index.js types.js > ./README.md
go generate -mod=mod ./gen-go-errors...
../bin/wag -file ./nils.yml -output-path ./gen-go-nils -js-path ./gen-js-nils
../bin/wag -with-tests -file ./nils.yml -output-path ./gen-go-nils -js-path ./gen-js-nils
cd ./gen-js-nils && jsdoc2md index.js types.js > ./README.md
go generate -mod=mod ./gen-go-nils...
../bin/wag -file ./strings.yml -output-path ./gen-go-strings -js-path ./gen-js-strings
../bin/wag -with-tests -file ./strings.yml -output-path ./gen-go-strings -js-path ./gen-js-strings
cd ./gen-js-strings && jsdoc2md index.js types.js > ./README.md
go generate -mod=mod ./gen-go-strings...
../bin/wag -file ./blog.yml -output-path ./gen-go-blog -js-path ./gen-js-blog
../bin/wag -with-tests -file ./blog.yml -output-path ./gen-go-blog -js-path ./gen-js-blog
cd ./gen-js-blog && jsdoc2md index.js types.js > ./README.md
go generate -mod=mod ./gen-go-nils...
../bin/wag -file ./db.yml -output-path ./gen-go-db -js-path ./gen-js-db
../bin/wag -with-tests -file ./db.yml -output-path ./gen-go-db -js-path ./gen-js-db
cd ./gen-js-db && jsdoc2md index.js types.js > ./README.md
go generate -mod=mod ./gen-go-db...
../bin/wag -file ./swagger.yml -output-path ./gen-go-client-only -js-path ./gen-js-client-only --client-only
../bin/wag -with-tests -file ./swagger.yml -output-path ./gen-go-client-only -js-path ./gen-js-client-only --client-only
cd ./gen-js-client-only && jsdoc2md index.js types.js > ./README.md
go generate -mod=mod ./gen-go-client-only...
../bin/wag -file ./db.yml -output-path ./gen-go-db-only -dynamo-only
../bin/wag -with-tests -file ./db.yml -output-path ./gen-go-db-only -dynamo-only
go generate -mod=mod ./gen-go-db-only...
../bin/wag -file ./db.yml -output-path ./gen-go-db-custom-path -js-path ./gen-js-db-custom-path -dynamo-path db
../bin/wag -with-tests -file ./db.yml -output-path ./gen-go-db-custom-path -js-path ./gen-js-db-custom-path -dynamo-path db
cd ./gen-js-db-custom-path && jsdoc2md index.js types.js > ./README.md
go generate -mod=mod ./gen-go-db-custom-path...

Expand Down
13 changes: 13 additions & 0 deletions samples/db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ definitions:
- AttributeName: name_version
Properties: [ name, version ]
Separator: ":"
# 3 part composite in a GSI
- AttributeName: name_branch_commit
Properties: [ name, branch, commit ]
Separator: "--"
DynamoDB:
KeySchema:
- AttributeName: name_branch
Expand All @@ -480,16 +484,25 @@ definitions:
KeyType: HASH
- AttributeName: date
KeyType: RANGE
- IndexName: nameBranchCommit
Projection:
ProjectionType: ALL
KeySchema:
- AttributeName: name_branch_commit
KeyType: HASH
type: object
required:
- name
- branch
- date
- commit
properties:
name:
type: string
branch:
type: string
commit:
type: string
version:
type: integer
date:
Expand Down
32 changes: 16 additions & 16 deletions samples/gen-go-basic/server/mock_controller.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion samples/gen-go-db-custom-path/db/dynamodb/deployment.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions samples/gen-go-db-custom-path/db/dynamodb/dynamodb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d7d4bc7

Please sign in to comment.