Skip to content

Commit

Permalink
📝 Update Swagger doc
Browse files Browse the repository at this point in the history
  • Loading branch information
smolgroot committed Feb 25, 2024
1 parent be241ad commit aadc944
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 16 deletions.
11 changes: 7 additions & 4 deletions cmd/skypier-vpn-node/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"log"
"strconv"

docs "github.com/SkyPierIO/skypier-vpn/pkg/docs"
Expand All @@ -14,11 +15,11 @@ import (
"github.com/gin-gonic/gin"
)

// @title Swagger Skypier API
// @version 1.0
// @description This is a Skypier VPN REST API.
// @title Skypier
// @version 0.0.1
// @description Skypier - Embark securely on web3

// @contact.name Skypier info
// @contact.name Skypier
// @contact.url http://skypier.io/
// @contact.email [email protected]

Expand Down Expand Up @@ -57,6 +58,7 @@ func main() {
if config.SwaggerEnabled {
docs.SwaggerInfo.BasePath = "/api/v0"
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
log.Println("Swagger UI available at http://127.0.0.1:8081/swagger/index.html")
}

api := router.Group("/api/v0")
Expand All @@ -67,6 +69,7 @@ func main() {
c.String(200, "pong")
})
api.GET("/getConfig", utils.GetConfiguration)
api.GET("/id", vpn.GetPeerId)

// Run with HTTP
router.Run("0.0.0.0:" + strconv.FormatUint(uint64(innerConfig.Port), 10))
Expand Down
34 changes: 30 additions & 4 deletions pkg/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const docTemplate = `{
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {
"name": "Skypier info",
"name": "Skypier",
"url": "http://skypier.io/",
"email": "[email protected]"
},
Expand Down Expand Up @@ -48,6 +48,32 @@ const docTemplate = `{
}
}
}
},
"/id": {
"get": {
"description": "Get the local libp2p peer ID (this is the identity of your node on the Skypier Network)",
"produces": [
"application/json"
],
"tags": [
"P2P"
],
"summary": "Get the local peer ID",
"responses": {
"200": {
"description": "OK"
},
"400": {
"description": "Bad Request"
},
"404": {
"description": "Not Found"
},
"500": {
"description": "Internal Server Error"
}
}
}
}
},
"externalDocs": {
Expand All @@ -58,12 +84,12 @@ const docTemplate = `{

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "1.0",
Version: "0.0.1",
Host: "localhost:8081",
BasePath: "/api/v0",
Schemes: []string{},
Title: "Swagger Skypier API",
Description: "This is a Skypier VPN REST API.",
Title: "Skypier",
Description: "Skypier - Embark securely on web3",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
Expand Down
34 changes: 30 additions & 4 deletions pkg/docs/swagger.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"swagger": "2.0",
"info": {
"description": "This is a Skypier VPN REST API.",
"title": "Swagger Skypier API",
"description": "Skypier - Embark securely on web3",
"title": "Skypier",
"contact": {
"name": "Skypier info",
"name": "Skypier",
"url": "http://skypier.io/",
"email": "[email protected]"
},
"license": {
"name": "MIT",
"url": "https://choosealicense.com/licenses/mit/"
},
"version": "1.0"
"version": "0.0.1"
},
"host": "localhost:8081",
"basePath": "/api/v0",
Expand Down Expand Up @@ -42,6 +42,32 @@
}
}
}
},
"/id": {
"get": {
"description": "Get the local libp2p peer ID (this is the identity of your node on the Skypier Network)",
"produces": [
"application/json"
],
"tags": [
"P2P"
],
"summary": "Get the local peer ID",
"responses": {
"200": {
"description": "OK"
},
"400": {
"description": "Bad Request"
},
"404": {
"description": "Not Found"
},
"500": {
"description": "Internal Server Error"
}
}
}
}
},
"externalDocs": {
Expand Down
26 changes: 22 additions & 4 deletions pkg/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ host: localhost:8081
info:
contact:
email: [email protected]
name: Skypier info
name: Skypier
url: http://skypier.io/
description: This is a Skypier VPN REST API.
description: Skypier - Embark securely on web3
license:
name: MIT
url: https://choosealicense.com/licenses/mit/
title: Swagger Skypier API
version: "1.0"
title: Skypier
version: 0.0.1
paths:
/getConfig:
get:
Expand All @@ -32,4 +32,22 @@ paths:
summary: Get the configuration
tags:
- config
/id:
get:
description: Get the local libp2p peer ID (this is the identity of your node
on the Skypier Network)
produces:
- application/json
responses:
"200":
description: OK
"400":
description: Bad Request
"404":
description: Not Found
"500":
description: Internal Server Error
summary: Get the local peer ID
tags:
- P2P
swagger: "2.0"
11 changes: 11 additions & 0 deletions pkg/vpn/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
b64 "encoding/base64"

"github.com/SkyPierIO/skypier-vpn/pkg/utils"
"github.com/gin-gonic/gin"
"github.com/ipfs/go-datastore"
"github.com/libp2p/go-libp2p"
dht "github.com/libp2p/go-libp2p-kad-dht"
Expand Down Expand Up @@ -55,6 +56,16 @@ func loadPrivateKey() (crypto.PrivKey, error) {
}
}

// GetPeerId godoc
// @Summary Get the local peer ID
// @Description Get the local libp2p peer ID (this is the identity of your node on the Skypier Network)
// @Tags P2P
// @Produce json
// @Router /id [get]
func GetPeerId(c *gin.Context) {
c.IndentedJSON(200, "Hello")
}

func displayNodeInfo(node host.Host, dht *dht.IpfsDHT) {
// print node ID
log.Println("───────────────────────────────────────────────────")
Expand Down
26 changes: 26 additions & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -e

pushd ./pkg
echo -e "\n[+]\tGenerating swagger doc..."
swag init --dir ../cmd/skypier-vpn-node/,../pkg/ui/,../pkg/vpn/,../pkg/utils/
popd

echo -e "\n[+]\tGo build..."
go build -o build/skypier-vpn-node cmd/skypier-vpn-node/main.go
echo -e "\n[+]\tRun..."
sudo ./build/skypier-vpn-node













0 comments on commit aadc944

Please sign in to comment.