-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
792 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2021 BlockDev AG | ||
// This source code is licensed under the MIT license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
|
||
package swagger | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/fatih/color" | ||
"github.com/magefile/mage/mg" | ||
"github.com/magefile/mage/sh" | ||
"github.com/mysteriumnetwork/go-ci/util" | ||
) | ||
|
||
// Installs the swag generation tool | ||
func swagInstall() error { | ||
err := sh.RunV("go", "get", "-u", "github.com/swaggo/swag/cmd/swag") | ||
if err != nil { | ||
color.Red("Could not go get swag") | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// Swag generates the swagger documents | ||
func Swag() error { | ||
mg.Deps(swagInstall) | ||
swag, err := util.GetGoBinaryPath("swag") | ||
if err != nil { | ||
color.Red("Could not find swag") | ||
return err | ||
} | ||
|
||
color.Cyan("Removing old docs") | ||
err = os.RemoveAll("./docs") | ||
if err != nil { | ||
return err | ||
} | ||
color.Cyan("Old docs removed") | ||
|
||
color.Cyan("Generating swagger docs with %s", swag) | ||
err = sh.RunV( | ||
swag, "init", | ||
"--generalInfo", "main.go", | ||
"--dir", "cmd", | ||
"--parseDependency", | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
color.Green("Generating docs DONE!") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,242 @@ | ||
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT | ||
// This file was generated by swaggo/swag | ||
|
||
package docs | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"strings" | ||
|
||
"github.com/alecthomas/template" | ||
"github.com/swaggo/swag" | ||
) | ||
|
||
var doc = `{ | ||
"schemes": {{ marshal .Schemes }}, | ||
"swagger": "2.0", | ||
"info": { | ||
"description": "{{.Description}}", | ||
"title": "{{.Title}}", | ||
"contact": {}, | ||
"version": "{{.Version}}" | ||
}, | ||
"host": "{{.Host}}", | ||
"basePath": "{{.BasePath}}", | ||
"paths": { | ||
"/ping": { | ||
"get": { | ||
"description": "Ping", | ||
"consumes": [ | ||
"application/json" | ||
], | ||
"produces": [ | ||
"application/json" | ||
], | ||
"summary": "Ping", | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"$ref": "#/definitions/proposal.PingResponse" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/proposals": { | ||
"get": { | ||
"description": "List proposals", | ||
"consumes": [ | ||
"application/json" | ||
], | ||
"summary": "List proposals", | ||
"parameters": [ | ||
{ | ||
"type": "string", | ||
"description": "Consumer country", | ||
"name": "from", | ||
"in": "query" | ||
}, | ||
{ | ||
"type": "string", | ||
"description": "Service type", | ||
"name": "service_type", | ||
"in": "query" | ||
}, | ||
{ | ||
"type": "string", | ||
"description": "Provider country", | ||
"name": "country", | ||
"in": "query" | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/v2.Proposal" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"proposal.PingResponse": { | ||
"type": "object", | ||
"properties": { | ||
"message": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"v2.AccessPolicy": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "string" | ||
}, | ||
"source": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"v2.Contact": { | ||
"type": "object", | ||
"properties": { | ||
"definition": { | ||
"type": "object" | ||
}, | ||
"type": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"v2.Location": { | ||
"type": "object", | ||
"properties": { | ||
"asn": { | ||
"type": "integer" | ||
}, | ||
"city": { | ||
"type": "string" | ||
}, | ||
"continent": { | ||
"type": "string" | ||
}, | ||
"country": { | ||
"type": "string" | ||
}, | ||
"ip_type": { | ||
"type": "string" | ||
}, | ||
"isp": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"v2.Price": { | ||
"type": "object", | ||
"properties": { | ||
"currency": { | ||
"type": "string" | ||
}, | ||
"per_gib": { | ||
"type": "integer" | ||
}, | ||
"per_hour": { | ||
"type": "integer" | ||
} | ||
} | ||
}, | ||
"v2.Proposal": { | ||
"type": "object", | ||
"properties": { | ||
"access_policies": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/v2.AccessPolicy" | ||
} | ||
}, | ||
"compatibility": { | ||
"type": "integer" | ||
}, | ||
"contacts": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/v2.Contact" | ||
} | ||
}, | ||
"format": { | ||
"type": "string" | ||
}, | ||
"location": { | ||
"$ref": "#/definitions/v2.Location" | ||
}, | ||
"price": { | ||
"$ref": "#/definitions/v2.Price" | ||
}, | ||
"provider_id": { | ||
"type": "string" | ||
}, | ||
"quality": { | ||
"type": "number" | ||
}, | ||
"service_type": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
}` | ||
|
||
type swaggerInfo struct { | ||
Version string | ||
Host string | ||
BasePath string | ||
Schemes []string | ||
Title string | ||
Description string | ||
} | ||
|
||
// SwaggerInfo holds exported Swagger Info so clients can modify it | ||
var SwaggerInfo = swaggerInfo{ | ||
Version: "3.0", | ||
Host: "", | ||
BasePath: "/api/v3", | ||
Schemes: []string{}, | ||
Title: "Discovery API", | ||
Description: "Discovery API for Mysterium Network", | ||
} | ||
|
||
type s struct{} | ||
|
||
func (s *s) ReadDoc() string { | ||
sInfo := SwaggerInfo | ||
sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1) | ||
|
||
t, err := template.New("swagger_info").Funcs(template.FuncMap{ | ||
"marshal": func(v interface{}) string { | ||
a, _ := json.Marshal(v) | ||
return string(a) | ||
}, | ||
}).Parse(doc) | ||
if err != nil { | ||
return doc | ||
} | ||
|
||
var tpl bytes.Buffer | ||
if err := t.Execute(&tpl, sInfo); err != nil { | ||
return doc | ||
} | ||
|
||
return tpl.String() | ||
} | ||
|
||
func init() { | ||
swag.Register(swag.Name, &s{}) | ||
} |
Oops, something went wrong.