Skip to content

Commit

Permalink
update swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
Raajheer1 committed Aug 25, 2024
1 parent 3ce2657 commit 17ee073
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 53 deletions.
44 changes: 28 additions & 16 deletions external/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ const docTemplate = `{
{
"type": "string",
"description": "Facility ID",
"name": "facility",
"name": "FacilityID",
"in": "query"
}
],
Expand Down Expand Up @@ -290,7 +290,7 @@ const docTemplate = `{
{
"type": "string",
"description": "Facility ID",
"name": "facility",
"name": "FacilityID",
"in": "path",
"required": true
}
Expand Down Expand Up @@ -338,6 +338,13 @@ const docTemplate = `{
"in": "path",
"required": true
},
{
"type": "string",
"description": "Facility ID",
"name": "FacilityID",
"in": "path",
"required": true
},
{
"description": "FAQ",
"name": "faq",
Expand Down Expand Up @@ -394,6 +401,13 @@ const docTemplate = `{
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Facility ID",
"name": "FacilityID",
"in": "path",
"required": true
}
],
"responses": {
Expand Down Expand Up @@ -428,6 +442,13 @@ const docTemplate = `{
"in": "path",
"required": true
},
{
"type": "string",
"description": "Facility ID",
"name": "FacilityID",
"in": "path",
"required": true
},
{
"description": "FAQ",
"name": "faq",
Expand Down Expand Up @@ -754,12 +775,6 @@ const docTemplate = `{
"name": "FacilityID",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Facility ID",
"name": "facility",
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -1380,7 +1395,7 @@ const docTemplate = `{
}
},
"post": {
"description": "Create a new roster",
"description": "Adds a user to a roster",
"consumes": [
"application/json"
],
Expand All @@ -1390,7 +1405,7 @@ const docTemplate = `{
"tags": [
"roster"
],
"summary": "Create a new roster",
"summary": "Add user to roster",
"parameters": [
{
"type": "string",
Expand Down Expand Up @@ -4524,10 +4539,7 @@ const docTemplate = `{
"example": "Raaj"
},
"flags": {
"type": "array",
"items": {
"$ref": "#/definitions/models.UserFlag"
}
"$ref": "#/definitions/models.UserFlag"
},
"last_cert_sync": {
"type": "string",
Expand Down Expand Up @@ -4734,9 +4746,9 @@ const docTemplate = `{
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "0.1",
Host: "api.vatusa.net",
Host: "",
BasePath: "/v3",
Schemes: []string{"https"},
Schemes: []string{},
Title: "VATUSA API",
Description: "VATUSAs public API",
InfoInstanceName: "swagger",
Expand Down
44 changes: 26 additions & 18 deletions external/docs/swagger.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"schemes": [
"https"
],
"swagger": "2.0",
"info": {
"description": "VATUSAs public API",
Expand All @@ -18,7 +15,6 @@
},
"version": "0.1"
},
"host": "api.vatusa.net",
"basePath": "/v3",
"paths": {
"/facility": {
Expand Down Expand Up @@ -240,7 +236,7 @@
{
"type": "string",
"description": "Facility ID",
"name": "facility",
"name": "FacilityID",
"in": "query"
}
],
Expand Down Expand Up @@ -287,7 +283,7 @@
{
"type": "string",
"description": "Facility ID",
"name": "facility",
"name": "FacilityID",
"in": "path",
"required": true
}
Expand Down Expand Up @@ -335,6 +331,13 @@
"in": "path",
"required": true
},
{
"type": "string",
"description": "Facility ID",
"name": "FacilityID",
"in": "path",
"required": true
},
{
"description": "FAQ",
"name": "faq",
Expand Down Expand Up @@ -391,6 +394,13 @@
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Facility ID",
"name": "FacilityID",
"in": "path",
"required": true
}
],
"responses": {
Expand Down Expand Up @@ -425,6 +435,13 @@
"in": "path",
"required": true
},
{
"type": "string",
"description": "Facility ID",
"name": "FacilityID",
"in": "path",
"required": true
},
{
"description": "FAQ",
"name": "faq",
Expand Down Expand Up @@ -751,12 +768,6 @@
"name": "FacilityID",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Facility ID",
"name": "facility",
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -1377,7 +1388,7 @@
}
},
"post": {
"description": "Create a new roster",
"description": "Adds a user to a roster",
"consumes": [
"application/json"
],
Expand All @@ -1387,7 +1398,7 @@
"tags": [
"roster"
],
"summary": "Create a new roster",
"summary": "Add user to roster",
"parameters": [
{
"type": "string",
Expand Down Expand Up @@ -4521,10 +4532,7 @@
"example": "Raaj"
},
"flags": {
"type": "array",
"items": {
"$ref": "#/definitions/models.UserFlag"
}
"$ref": "#/definitions/models.UserFlag"
},
"last_cert_sync": {
"type": "string",
Expand Down
34 changes: 20 additions & 14 deletions external/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -816,9 +816,7 @@ definitions:
example: Raaj
type: string
flags:
items:
$ref: '#/definitions/models.UserFlag'
type: array
$ref: '#/definitions/models.UserFlag'
last_cert_sync:
example: "2021-01-01T00:00:00Z"
type: string
Expand Down Expand Up @@ -954,7 +952,6 @@ definitions:
description: user-level status message
type: string
type: object
host: api.vatusa.net
info:
contact:
email: [email protected]
Expand Down Expand Up @@ -1110,7 +1107,7 @@ paths:
parameters:
- description: Facility ID
in: query
name: facility
name: FacilityID
type: string
produces:
- application/json
Expand Down Expand Up @@ -1141,7 +1138,7 @@ paths:
$ref: '#/definitions/faq.Request'
- description: Facility ID
in: path
name: facility
name: FacilityID
required: true
type: string
produces:
Expand Down Expand Up @@ -1173,6 +1170,11 @@ paths:
name: id
required: true
type: string
- description: Facility ID
in: path
name: FacilityID
required: true
type: string
produces:
- application/json
responses:
Expand All @@ -1195,6 +1197,11 @@ paths:
name: id
required: true
type: string
- description: Facility ID
in: path
name: FacilityID
required: true
type: string
- description: FAQ
in: body
name: faq
Expand Down Expand Up @@ -1233,6 +1240,11 @@ paths:
name: id
required: true
type: string
- description: Facility ID
in: path
name: FacilityID
required: true
type: string
- description: FAQ
in: body
name: faq
Expand Down Expand Up @@ -1451,10 +1463,6 @@ paths:
name: FacilityID
required: true
type: string
- description: Facility ID
in: query
name: facility
type: string
produces:
- application/json
responses:
Expand Down Expand Up @@ -1874,7 +1882,7 @@ paths:
post:
consumes:
- application/json
description: Create a new roster
description: Adds a user to a roster
parameters:
- description: Facility ID
in: path
Expand Down Expand Up @@ -1902,7 +1910,7 @@ paths:
description: Internal Server Error
schema:
$ref: '#/definitions/utils.ErrResponse'
summary: Create a new roster
summary: Add user to roster
tags:
- roster
/facility/{FacilityID}/roster-request:
Expand Down Expand Up @@ -3220,6 +3228,4 @@ paths:
summary: Update a user flag
tags:
- user-flag
schemes:
- https
swagger: "2.0"
13 changes: 10 additions & 3 deletions external/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package external

import (
"fmt"
"github.com/VATUSA/primary-api/external/docs"
_ "github.com/VATUSA/primary-api/external/docs"
v3 "github.com/VATUSA/primary-api/external/v3"
"github.com/VATUSA/primary-api/pkg/config"
"github.com/go-chi/chi/v5"
httpSwagger "github.com/swaggo/http-swagger"
"strings"
)

// @title VATUSA API
Expand All @@ -21,15 +23,20 @@ import (
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @host api.vatusa.net
// @BasePath /v3
// @schemes https

func Router(r chi.Router, cfg *config.Config) {
v3.Router(r, cfg)

docs.SwaggerInfo.Host = cfg.API.BaseURL[strings.Index(cfg.API.BaseURL, "://")+3:]

if strings.Contains(cfg.API.BaseURL, "https") {
docs.SwaggerInfo.Schemes = []string{"https"}
} else {
docs.SwaggerInfo.Schemes = []string{"http"}
}

r.Get("/swagger/*", httpSwagger.Handler(
httpSwagger.URL(fmt.Sprintf("%s/swagger/doc.json", config.Cfg.API.BaseURL)),
))

}
Loading

0 comments on commit 17ee073

Please sign in to comment.