Skip to content

Commit

Permalink
[docs] include Swagger into app
Browse files Browse the repository at this point in the history
  • Loading branch information
capcom6 committed Jun 4, 2024
1 parent c828b8c commit d96ff66
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ docker-dev:

api-docs:
swag fmt -g ./cmd/$(project_name)/main.go \
&& swag init -g ./cmd/$(project_name)/main.go -o ./api
&& swag init --parseDependency -g ./cmd/$(project_name)/main.go -o ./api

view-docs:
php -S 127.0.0.1:8080 -t ./api
Expand Down
4 changes: 2 additions & 2 deletions api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
],
"swagger": "2.0",
"info": {
"description": "End-user authentication key",
"description": "Provides an API for (Android) SMS Gateway",
"title": "SMS Gateway - API",
"contact": {
"name": "Aleksandr Soloshenko",
"email": "[email protected]"
},
"version": "1.0.0"
"version": "{APP_VERSION}"
},
"host": "sms.capcom.me",
"basePath": "/api",
Expand Down
4 changes: 2 additions & 2 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ info:
contact:
email: [email protected]
name: Aleksandr Soloshenko
description: End-user authentication key
description: Provides an API for (Android) SMS Gateway
title: SMS Gateway - API
version: 1.0.0
version: '{APP_VERSION}'
paths:
/3rdparty/v1/device:
get:
Expand Down
10 changes: 10 additions & 0 deletions build/package/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ ARG APP_VERSION=1.0.0
ARG APP_RELEASE_ID=1
WORKDIR /go/src

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

# Copy go.mod and go.sum
COPY go.* ./

Expand All @@ -15,6 +18,12 @@ RUN go mod download
# Copy all the Code and stuff to compile everything
COPY . .

# Replace {APP_VERSION} with the actual version
RUN sed -i "s/{APP_VERSION}/${APP_VERSION}/g" ./cmd/${APP}/main.go

# Generate swagger docs
RUN swag init --parseDependency -g ./cmd/${APP}/main.go -o ./api

# Builds the application as a staticly linked one, to allow it to run on alpine
# RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o app .
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags="-w -s -X github.com/capcom6/${APP}/internal/version.AppVersion=${APP_VERSION} -X github.com/capcom6/${APP}/internal/version.AppRelease=${APP_RELEASE_ID}" -o app ./cmd/${APP}/main.go
Expand All @@ -28,6 +37,7 @@ RUN apk add --no-cache tzdata

COPY scripts/docker-entrypoint.sh /docker-entrypoint.sh

COPY --from=build /go/src/api /app/api
COPY --from=build /go/src/app /app

# Exposes port 3000 because our program listens on that port
Expand Down
16 changes: 7 additions & 9 deletions cmd/sms-gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ import (
smsgateway "github.com/capcom6/sms-gateway/internal/sms-gateway"
)

// @title SMS Gateway - API
// @version 1.0.0
// @description Provides API for (Android) SMS Gateway

// @contact.name Aleksandr Soloshenko
// @contact.email [email protected]
// @securitydefinitions.basic ApiAuth

// @securitydefinitions.apikey MobileToken
// @in header
// @name Authorization
// @description Mobile device token

// @securitydefinitions.basic ApiAuth
// @in header
// @description End-user authentication key
// @title SMS Gateway - API
// @version {APP_VERSION}
// @description Provides an API for (Android) SMS Gateway

// @contact.name Aleksandr Soloshenko
// @contact.email [email protected]

// @host localhost:3000
// @host sms.capcom.me
Expand Down
1 change: 1 addition & 0 deletions internal/sms-gateway/handlers/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type rootHandler struct {

func (h *rootHandler) Register(app *fiber.App) {
h.healthHandler.Register(app)
app.Static("/api", "api")
}

func newRootHandler(healthHandler *healthHandler) *rootHandler {
Expand Down

0 comments on commit d96ff66

Please sign in to comment.