Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: migrate API specs to OpenAPI 3.1.0 ♻️ #12

Merged
merged 8 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions Makefile
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
58 changes: 58 additions & 0 deletions cmd/gen/main.go
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!")
}
2 changes: 1 addition & 1 deletion cmd/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var mysqlCommand = &cobra.Command{
Use: "mysql",
Short: "use mysql as the database provider",
Short: "Use MySQL as the database provider",
RunE: func(cmd *cobra.Command, args []string) error {
var mysqlConfig *utils.MySQLConfig

Expand Down
3 changes: 2 additions & 1 deletion cmd/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (

var pgCommand = &cobra.Command{
Use: "pg",
Short: "use postgres as the database provider",
Short: "Use Postgres as the database provider",
RunE: func(cmd *cobra.Command, args []string) error {
var pgConfig *utils.PgConfig

// Not handling the error because port always has a default value, `5522`.
port, _ := cmd.Flags().GetInt("port")

connUrl, _ := cmd.Flags().GetString("url")
Expand Down
9 changes: 4 additions & 5 deletions cmd/sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ import (

var sqlite3Command = &cobra.Command{
Use: "sqlite3",
Short: "use sqlite as the database provider",
Short: "Use SQLite as the database provider",
RunE: func(cmd *cobra.Command, args []string) error {
filePath, err := cmd.Flags().GetString("file")
if err != nil {
return err
}
port, err := cmd.Flags().GetInt("port")
if err != nil {
return err
}
// Not handling the error because port always has a default value, `5522`.
port, _ := cmd.Flags().GetInt("port")

sqliteConfig := utils.NewSQLiteConfig(filePath)

conn, err := db.InitDBConn(lib.SQLITE3, sqliteConfig)
Expand Down
Loading
Loading