Generate client code based on the Swagger > OpenApi document #13

Merged
jtom38 merged 4 commits from features/generate-client-api into main 2024-07-17 22:04:35 -07:00
4 changed files with 3772 additions and 3 deletions
Showing only changes of commit 3cf6afb39c - Show all commits

2
.gitignore vendored
View File

@ -3,6 +3,7 @@ dev.session.sql
__debug_bin __debug_bin
server server
.vscode .vscode
openapi.json
# Binaries for programs and plugins # Binaries for programs and plugins
*.exe *.exe
@ -12,6 +13,7 @@ server
*.dylib *.dylib
collector collector
newsbot.db newsbot.db
tmp/
# Test binary, built with `go test -c` # Test binary, built with `go test -c`
*.test *.test

3756
api/api.gen.go Normal file

File diff suppressed because it is too large Load Diff

6
api/client.yaml Normal file
View File

@ -0,0 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/deepmap/oapi-codegen/HEAD/configuration-schema.json
package: api
output: api.gen.go
generate:
models: true
client: true

View File

@ -19,8 +19,13 @@ migrate-dev-down: ## revert sql migrations to dev db
goose -dir "./internal/database/migrations" sqlite3 ./cmd/newsbot.db down goose -dir "./internal/database/migrations" sqlite3 ./cmd/newsbot.db down
swag: ## Generates the swagger documentation with the swag tool swag: ## Generates the swagger documentation with the swag tool
~/go/bin/swag f ~/go/bin/swag f -g cmd/server.go
~/go/bin/swag init -g cmd/server.go ~/go/bin/swag init -g cmd/server.go
go run tools/swaggertoopenapi/main.go
oapi-codegen -config api/client.yaml docs/openapi.json
mv api.gen.go api/
gensql: ## Generates SQL code with sqlc install-tools: ## Installs the required tools for this project
sqlc generate go install github.com/swaggo/swag/cmd/swag@v1.8.1
go install github.com/pressly/goose/v3/cmd/goose@latest
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.3.0