Skip to content

Commit

Permalink
Added documentation for GameServer API swagger (#397)
Browse files Browse the repository at this point in the history
* added documentation for GameServer API swagger

* fixes the main.go path
  • Loading branch information
ShrayRastogi committed Sep 19, 2022
1 parent a585b0f commit 0cb7da2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Binary file added docs/assets/images/gameserverapi_swagger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions docs/gameserverapi/gameserverapi_swagger.md
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")

0 comments on commit 0cb7da2

Please sign in to comment.