Skip to content

Commit

Permalink
Merge pull request #10 from tokamak-network/OR-1101-titond-backend-ad…
Browse files Browse the repository at this point in the history
…d-swagger-and-ci-for-checking-if-the-swagger-doc-is-updated

Or 1101 titond backend add swagger and ci for checking if the swagger doc is updated
  • Loading branch information
nguyenzung authored Nov 29, 2023
2 parents dc8720a + f204e8b commit 7ac5f40
Show file tree
Hide file tree
Showing 13 changed files with 971 additions and 32 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/swagger-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Check swagger
on: push

jobs:
image:
name: Check swagger docs for titond-backend
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Check swagger
run: |
go run ./cmd/titond/main.go check-swagger
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ go.work
# Build file
/build
client.http
.env
.env*
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
FROM --platform=$BUILDPLATFORM golang:1.20-alpine AS builder

RUN apk add --no-cache make gcc musl-dev linux-headers git
RUN apk add --no-cache make gcc musl-dev linux-headers git curl

WORKDIR /app

COPY . .

RUN go install github.com/swaggo/swag/cmd/swag@latest

ARG TARGETOS TARGETARCH
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make titond

FROM alpine
FROM alpine:3.18.4
RUN apk add --no-cache aws-cli ca-certificates jq

RUN apk add --no-cache ca-certificates jq curl
COPY --from=builder /app/api /root/api
COPY --from=builder /app/deployments /root/deployments
COPY --from=builder /app/build/bin/titond /usr/local/bin/

WORKDIR /usr/local/bin/
WORKDIR /root
ENTRYPOINT ["titond"]
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@ TARGET=./build/bin/titond
all: run

run: $(TARGET)
$(TARGET)
$<

$(TARGET): build

check:
swag init -g cmd/titond/main.go -o api
CGO_ENABLED=0 GOOS=linux go build -o ./build/bin/titond ./cmd/titond/main.go
./build/bin/titond check-swagger

build:
swag init -g cmd/titond/main.go -o api
CGO_ENABLED=0 GOOS=linux go build -o ./build/bin/titond ./cmd/titond/main.go
@echo "Done building"
@echo "Run \"./build/bin/titond\" to launch titond backend."

titond:
swag init -g cmd/titond/main.go -o api
CGO_ENABLED=0 GOOS=linux go build -o ./build/bin/titond ./cmd/titond/main.go
@echo "Done building"
@echo "Run \"./build/bin/titond\" to launch titond backend."
Expand All @@ -28,6 +35,6 @@ image-amd:
image-arm:
docker build --build-arg TARGETARCH=arm64 --build-arg TARGETOS=linux -t titond-backend .


clean:
rm -rf $(TARGET)
rm -rf docs
283 changes: 283 additions & 0 deletions api/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
// Package api Code generated by swaggo/swag. DO NOT EDIT
package api

import "github.com/swaggo/swag"

const docTemplate = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/api/components": {
"get": {
"description": "Get Component By Type",
"summary": "GetComponentByType",
"operationId": "get-component-by-type",
"parameters": [
{
"type": "string",
"description": "Component type (e.g., l2geth)",
"name": "type",
"in": "query",
"required": true
},
{
"type": "integer",
"description": "Network ID",
"name": "network_id",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"400": {
"description": "Bad Request"
},
"500": {
"description": "Internal Server Error"
}
}
},
"post": {
"description": "Create a new component",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "CreateComponent",
"operationId": "create-component",
"parameters": [
{
"description": "Component data to create",
"name": "input",
"in": "body",
"required": true,
"schema": {
"type": "object"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.Component"
}
},
"400": {
"description": "Bad Request"
},
"500": {
"description": "Internal Server Error"
}
}
}
},
"/api/components/{id}": {
"get": {
"description": "Get Component By ID",
"summary": "GetComponentByID",
"operationId": "get-component-by-id",
"parameters": [
{
"type": "integer",
"description": "Component ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"400": {
"description": "Bad Request"
},
"500": {
"description": "Internal Server Error"
}
}
},
"delete": {
"description": "Delete Component By Id",
"summary": "DeleteComponentById",
"operationId": "delete-component-by-id",
"parameters": [
{
"type": "integer",
"description": "Component ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"400": {
"description": "Bad Request"
},
"500": {
"description": "Internal Server Error"
}
}
}
},
"/api/networks": {
"post": {
"description": "Create a new network",
"produces": [
"application/json"
],
"summary": "CreateNetwork",
"operationId": "create-network",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.Network"
}
},
"500": {
"description": "Internal Server Error"
}
}
}
},
"/api/networks/{id}": {
"delete": {
"description": "Delete a network by id",
"produces": [
"application/json"
],
"summary": "DeleteNetwork",
"operationId": "delete-network",
"parameters": [
{
"type": "integer",
"description": "Network ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"400": {
"description": "Bad Request"
},
"404": {
"description": "Not Found"
},
"500": {
"description": "Internal Server Error"
}
}
}
}
},
"definitions": {
"model.Component": {
"type": "object",
"required": [
"network_id",
"type"
],
"properties": {
"created_at": {
"type": "integer"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"network_id": {
"type": "integer"
},
"public_url": {
"type": "string"
},
"status": {
"type": "boolean"
},
"type": {
"type": "string"
},
"updated_at": {
"type": "integer"
}
}
},
"model.Network": {
"type": "object",
"properties": {
"contract_address_url": {
"type": "string"
},
"created_at": {
"type": "integer"
},
"id": {
"type": "integer"
},
"state_dump_url": {
"type": "string"
},
"status": {
"type": "boolean"
},
"updated_at": {
"type": "integer"
}
}
}
}
}`

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "1.0",
Host: "localhost:8080",
BasePath: "",
Schemes: []string{},
Title: "Titond",
Description: "Titond-backend application",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}
Loading

0 comments on commit 7ac5f40

Please sign in to comment.