Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added documentation for GameServer API swagger #397

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")