add swagger
parent
80e7f76e49
commit
a58aa7306c
20
main.go
20
main.go
|
@ -1,11 +1,11 @@
|
|||
// Golang Microservice API
|
||||
// App-Idea Rest-API Documentation
|
||||
//
|
||||
// Example Swagger spec.
|
||||
//
|
||||
// Schemes: [http, https]
|
||||
// BasePath: /
|
||||
// BasePath: /api/v1/
|
||||
// Version: 0.0.1
|
||||
// Contact: Matthias Sommer<admin@matthiassommer.it>
|
||||
// Contact: Alex<alex@roese.dev>
|
||||
//
|
||||
// Consumes:
|
||||
// - application/json
|
||||
|
@ -28,11 +28,17 @@ import (
|
|||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
|
||||
app.Use(cors.New(cors.Config{
|
||||
AllowOrigins: "*",
|
||||
AllowHeaders: "Origin, Content-Type, Accept",
|
||||
}))
|
||||
|
||||
router.SetupRoutes(app)
|
||||
|
||||
config.LoadConfig()
|
||||
|
@ -40,3 +46,11 @@ func main() {
|
|||
|
||||
app.Listen(config.GetConfig().Server.Host)
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
swagger generate spec -o ./swagger.yaml
|
||||
|
||||
sudo docker run -p 80:8080 -e SWAGGER_JSON=/api.yaml -v ~/Documents/coding/go/rest-api/swagger.yaml:/api.yaml swaggerapi/swagger-ui
|
||||
|
||||
*/
|
||||
|
|
|
@ -13,7 +13,40 @@ import (
|
|||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
// NewUser
|
||||
func NewUser(c *fiber.Ctx) error {
|
||||
// swagger:operation POST /users user usersNewUser
|
||||
// ---
|
||||
// summary: Create new user
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: username
|
||||
// in: query
|
||||
// description: username of the user (length 3-30)
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: email
|
||||
// in: query
|
||||
// description: email of the user (length max 200)
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: password
|
||||
// in: query
|
||||
// description: password of the user (length 6-256)
|
||||
// type: string
|
||||
// required: true
|
||||
// responses:
|
||||
// '200':
|
||||
// description: user created
|
||||
// schema:
|
||||
// type: object
|
||||
// example:
|
||||
// user_hastag: XVLBZG
|
||||
// default:
|
||||
// description: unexpected error
|
||||
// schema:
|
||||
// "$ref": "#/definitions/errorModel"
|
||||
type LoginInput struct {
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
basePath: /api/v1/
|
||||
consumes:
|
||||
- application/json
|
||||
info:
|
||||
contact:
|
||||
email: alex@roese.dev
|
||||
name: Alex
|
||||
description: |-
|
||||
Example Swagger spec.
|
||||
|
||||
Schemes: [http, https]
|
||||
title: App-Idea Rest-API Documentation
|
||||
version: 0.0.1
|
||||
paths:
|
||||
/users:
|
||||
post:
|
||||
operationId: usersNewUser
|
||||
parameters:
|
||||
- description: username of the user (length 3-30)
|
||||
in: query
|
||||
name: username
|
||||
required: true
|
||||
type: string
|
||||
- description: email of the user (length max 200)
|
||||
in: query
|
||||
name: email
|
||||
required: true
|
||||
type: string
|
||||
- description: password of the user (length 6-256)
|
||||
in: query
|
||||
name: password
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: user created
|
||||
schema:
|
||||
example:
|
||||
user_hastag: XVLBZG
|
||||
type: object
|
||||
default:
|
||||
description: unexpected error
|
||||
schema:
|
||||
$ref: '#/definitions/errorModel'
|
||||
summary: Create new user
|
||||
tags:
|
||||
- user
|
||||
produces:
|
||||
- application/json
|
||||
securityDefinitions:
|
||||
api_key:
|
||||
in: header
|
||||
name: Authorization
|
||||
type: apiKey
|
||||
swagger: "2.0"
|
Loading…
Reference in New Issue