-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added documentation for GameServer API swagger (#397)
* added documentation for GameServer API swagger * fixes the main.go path
- Loading branch information
1 parent
a585b0f
commit 0cb7da2
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,37 @@ | ||
--- | ||
layout: default | ||
title: Swagger for GameServer API | ||
parent: GameServer API | ||
nav_order: 2 | ||
--- | ||
|
||
## Swagger for GameServer API | ||
|
||
The API uses [swag](https://github.com/swaggo/swag) and [gin-swagger](https://github.com/swaggo/gin-swagger) packages from Swaggo to generate Restful API documentation with Swagger 2.0. | ||
|
||
## How to use swag | ||
|
||
Swag parses the API annotations to generate Swagger 2.0 documentation. Whenever there is a change in API annotations, we need to re-generate swagger docs using below command - | ||
|
||
```bash | ||
swag init -g cmd/gameserverapi/main.go --parseDependency | ||
``` | ||
|
||
> **_NOTE_**: _--parseDependency_ is used to generate model definitions that inherit or depends on other type definitions. If the dependency depth is too high, use the _--parseDepth_ flag and set it to the required depth. | ||
Swagger Host and BasePath are set automatically using gin context during CORSMiddleware injection. To change this behavior, please refer to the code below in [main.go](https://github.com/PlayFab/thundernetes/blob/main/cmd/gameserverapi/main.go) | ||
|
||
```go | ||
func setSwaggerInfo(c *gin.Context) { | ||
// dynamically sets swagger host and base path | ||
docs.SwaggerInfo.Host = c.Request.Host | ||
docs.SwaggerInfo.BasePath = urlprefix | ||
} | ||
``` | ||
|
||
## Browse Swagger | ||
|
||
Run the code and browse the following URL to use swagger - | ||
<https://{$IP}:5001/swagger/index.html> or in case of localhost - <http://localhost:5001/swagger/index.html> | ||
|
||
!["GameServer API Swagger"](../assets/images/gameserverapi_swagger.png "GameServer API Swagger") |