Skip to content

Commit

Permalink
feat: add Swagger OpenAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
belajarqywok committed Jul 10, 2024
1 parent d3c13b7 commit d43569c
Show file tree
Hide file tree
Showing 11 changed files with 392 additions and 14 deletions.
27 changes: 24 additions & 3 deletions .github/workflows/proxy_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
SPACE_NAME: tebakaja_proxy_space-0
HF_USERNAME: qywok
ENDPOINT: qywok-tebakaja-proxy-space-0.hf.space

steps:
- name: Set global directory
Expand All @@ -58,10 +59,16 @@ jobs:
git pull https://$HF_USERNAME:[email protected]/spaces/$HF_USERNAME/$SPACE_NAME main || \
(git merge --strategy-option theirs)
- name: Change Endpoint
run: |
sed -i 's/192.168.137.1:7860/$ENDPOINT/g' docs/docs.go
sed -i 's/192.168.137.1:7860/$ENDPOINT/g' docs/swagger.json
sed -i 's/192.168.137.1:7860/$ENDPOINT/g' docs/swagger.yaml
- name: Add and commit changes
run: |
git add -A
git diff-index --quiet HEAD || git commit -m "tebakaja_proxy_space-0"
git diff-index --quiet HEAD || git commit -m "$SPACE_NAME"
- name: Push to Hugging Face
run: |
Expand All @@ -78,6 +85,7 @@ jobs:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
SPACE_NAME: tebakaja_proxy_space-1
HF_USERNAME: qywok
ENDPOINT: qywok-tebakaja-proxy-space-1.hf.space

steps:
- name: Set global directory
Expand All @@ -101,10 +109,16 @@ jobs:
git pull https://$HF_USERNAME:[email protected]/spaces/$HF_USERNAME/$SPACE_NAME main || \
(git merge --strategy-option theirs)
- name: Change Endpoint
run: |
sed -i 's/192.168.137.1:7860/$ENDPOINT/g' docs/docs.go
sed -i 's/192.168.137.1:7860/$ENDPOINT/g' docs/swagger.json
sed -i 's/192.168.137.1:7860/$ENDPOINT/g' docs/swagger.yaml
- name: Add and commit changes
run: |
git add -A
git diff-index --quiet HEAD || git commit -m "tebakaja_proxy_space-1"
git diff-index --quiet HEAD || git commit -m "$SPACE_NAME"
- name: Push to Hugging Face
run: |
Expand All @@ -121,6 +135,7 @@ jobs:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
SPACE_NAME: tebakaja_proxy_space-2
HF_USERNAME: qywok
ENDPOINT: qywok-tebakaja-proxy-space-2.hf.space

steps:
- name: Set global directory
Expand All @@ -144,10 +159,16 @@ jobs:
git pull https://$HF_USERNAME:[email protected]/spaces/$HF_USERNAME/$SPACE_NAME main || \
(git merge --strategy-option theirs)
- name: Change Endpoint
run: |
sed -i 's/192.168.137.1:7860/$ENDPOINT/g' docs/docs.go
sed -i 's/192.168.137.1:7860/$ENDPOINT/g' docs/swagger.json
sed -i 's/192.168.137.1:7860/$ENDPOINT/g' docs/swagger.yaml
- name: Add and commit changes
run: |
git add -A
git diff-index --quiet HEAD || git commit -m "tebakaja_proxy_space-2"
git diff-index --quiet HEAD || git commit -m "$SPACE_NAME"
- name: Push to Hugging Face
run: |
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ PROD_ENDPOINT_0=https://qywok-tebakaja-proxy-space-0.hf.space
PROD_ENDPOINT_1=https://qywok-tebakaja-proxy-space-1.hf.space
PROD_ENDPOINT_2=https://qywok-tebakaja-proxy-space-2.hf.space

start:
svc:
swag init
go run main.go

swag:
swag init

haproxy-test:
haproxy -f ./haproxy/haproxy.cfg

Expand All @@ -30,6 +34,9 @@ endpoints_check:
# --- Development Testing ---
#

swag-test:
curl -X GET $(DEV_ENDPOINT)/swagger/index.html

stock-list-test:
curl -X GET $(DEV_ENDPOINT)/stock/lists

Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ services:
proxy:
build:
context: .
shm_size : 536870912
dockerfile: Dockerfile
labels :
role : "proxy service"

ports:
- "7860:7860"

81 changes: 81 additions & 0 deletions docs/docs.go

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

55 changes: 55 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"swagger": "2.0",
"info": {
"description": "TebakAja REST API Service",
"title": "TebakAja",
"termsOfService": "https://swagger.io/terms/",
"contact": {
"name": "Si Mimin",
"url": "https://www.tebakaja.com",
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0"
},
"host": "192.168.137.1:7860",
"paths": {
"/crypto/lists": {
"get": {
"description": "Cryptocurrency List",
"produces": [
"application/json"
],
"tags": [
"Cryptocurrency Forecasting"
],
"summary": "Cryptocurrency List",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/crypto.ApiResponse"
}
}
}
}
}
},
"definitions": {
"crypto.ApiResponse": {
"type": "object",
"properties": {
"data": {},
"message": {
"type": "string"
},
"status_code": {
"type": "integer"
}
}
}
}
}
37 changes: 37 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
definitions:
crypto.ApiResponse:
properties:
data: {}
message:
type: string
status_code:
type: integer
type: object
host: 192.168.137.1:7860
info:
contact:
email: [email protected]
name: Si Mimin
url: https://www.tebakaja.com
description: TebakAja REST API Service
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
termsOfService: https://swagger.io/terms/
title: TebakAja
version: "1.0"
paths:
/crypto/lists:
get:
description: Cryptocurrency List
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/crypto.ApiResponse'
summary: Cryptocurrency List
tags:
- Cryptocurrency Forecasting
swagger: "2.0"
22 changes: 22 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,40 @@ module tebakaja_lb_proxy
go 1.20

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.2.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gofiber/fiber/v2 v2.52.5 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/swaggo/fiber-swagger v1.3.0 // indirect
github.com/swaggo/files v1.0.1 // indirect
github.com/swaggo/swag v1.16.3 // indirect
github.com/tinylib/msgp v1.1.8 // indirect
github.com/urfave/cli/v2 v2.3.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.23.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit d43569c

Please sign in to comment.