-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate API specs to OpenAPI 3.1.0 ♻️ (#12)
* chore(docs): some comments and nicer descriptions in commands * refactor: separate entry files into dev and prod build tags ♻️ * refactor: use go generate instead of multiple entry points * feat: add graphql code generation to gen.go ✨ * chore: remove unused .vscode configs 🔥 * fix: exclude gen.go from build ignore * refactor: make everything compatible with openapi 3 ♻️ * fix(test): registered routes ✅
- Loading branch information
1 parent
f621bea
commit dfecb91
Showing
13 changed files
with
346 additions
and
871 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
build: | ||
@go build -o bin/ | ||
build_prod: | ||
@go build -o bin/ -ldflags "-w -s" | ||
run: build | ||
@./bin/meta-x.exe --help | ||
run: | ||
@air | ||
|
||
# make sure to run docker first | ||
# WARNING: make sure to run docker first | ||
test: | ||
@go test ./... -race | ||
swag: | ||
@swag fmt | ||
@swag init | ||
graphql: | ||
@go run github.com/99designs/gqlgen generate | ||
generate: | ||
@go generate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"io/fs" | ||
"log" | ||
|
||
graphqlAPI "github.com/99designs/gqlgen/api" | ||
graphqlConfig "github.com/99designs/gqlgen/codegen/config" | ||
"github.com/swaggo/swag/v2/format" | ||
"github.com/swaggo/swag/v2/gen" | ||
) | ||
|
||
func main() { | ||
log.Println("Formatting swagger comments...") | ||
err := format.New().Build(&format.Config{ | ||
SearchDir: "./", | ||
Excludes: "cmd,.vscode,.github,docs", | ||
}) | ||
if err != nil { | ||
log.Fatalf("Error formatting swagger comments: %v", err) | ||
} | ||
|
||
config := &gen.Config{ | ||
OutputDir: "./docs", | ||
OutputTypes: []string{"json", "yaml"}, | ||
MainAPIFile: "./main.go", | ||
SearchDir: "./", | ||
PropNamingStrategy: "camelcase", | ||
GenerateOpenAPI3Doc: true, | ||
} | ||
|
||
err = gen.New().Build(config) | ||
if err != nil { | ||
log.Fatalf("Error generating swagger docs: %v", err) | ||
} | ||
|
||
log.Println("Swagger documentation generated successfully!") | ||
|
||
cfg, err := graphqlConfig.LoadConfigFromDefaultLocations() | ||
if errors.Is(err, fs.ErrNotExist) { | ||
cfg, err = graphqlConfig.LoadDefaultConfig() | ||
} | ||
if err != nil { | ||
log.Fatalf("Error while loading GraphQL config: %v", err) | ||
return | ||
} | ||
|
||
log.Println("Generating GraphQL code...") | ||
|
||
err = graphqlAPI.Generate(cfg) | ||
if err != nil { | ||
log.Fatalf("Error while generating GraphQL code: %v", err) | ||
return | ||
} | ||
|
||
log.Println("Successfully generated GraphQL code!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.