Skip to content

Commit

Permalink
Create Swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Mar 12, 2024
1 parent a10d96e commit 4d87ba0
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 0 deletions.
128 changes: 128 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
from flask import Flask, abort, request, jsonify
from flasgger import Swagger

import markdown

from protocols import MasterServer, BeamMP, Factorio, Palworld, Scum
from version import __version__

app = Flask(__name__)

swagger_config = {
"headers": [],
"specs": [
{
"endpoint": 'apispec_1',
"route": '/apispec_1.json',
"rule_filter": lambda rule: True, # all in
"model_filter": lambda tag: True, # all in
}
],
"title": "OpenGSQ Master Server Search API",
"version": __version__,
"description": "Powered By OpenGSQ",
"termsOfService": "/terms",
"static_url_path": "/flasgger_static",
"swagger_ui": True,
"specs_route": "/"
}
swagger = Swagger(app, config=swagger_config)


def search(args: dict, master_server: MasterServer):
host = args.get('host')
Expand All @@ -29,23 +53,127 @@ def search(args: dict, master_server: MasterServer):

@app.route('/beammp/search', methods=['GET'])
def beammp_search():
"""
BeamMP Search
This endpoint allows you to search for a BeamMP server using its host and port.
---
tags:
- Search EndPoint
parameters:
- name: host
in: query
type: string
required: true
- name: port
in: query
type: integer
required: true
responses:
200:
description: Success
400:
description: Invalid parameters were supplied. 'host' and 'port' must be provided, and 'port' must be an integer.
404:
description: No server was found with the provided host and port.
"""
return search(request.args, BeamMP())


@app.route('/factorio/search', methods=['GET'])
def factorio_search():
"""
Factorio Search
This endpoint allows you to search for a Factorio server using its host and port.
---
tags:
- Search EndPoint
parameters:
- name: host
in: query
type: string
required: true
- name: port
in: query
type: integer
required: true
responses:
200:
description: Success
400:
description: Invalid parameters were supplied. 'host' and 'port' must be provided, and 'port' must be an integer.
404:
description: No server was found with the provided host and port.
"""
return search(request.args, Factorio())


@app.route('/palworld/search', methods=['GET'])
def palworld_search():
"""
Palworld Search
This endpoint allows you to search for a Palworld server using its host and port.
---
tags:
- Search EndPoint
parameters:
- name: host
in: query
type: string
required: true
- name: port
in: query
type: integer
required: true
responses:
200:
description: Success
400:
description: Invalid parameters were supplied. 'host' and 'port' must be provided, and 'port' must be an integer.
404:
description: No server was found with the provided host and port.
"""
return search(request.args, Palworld())


@app.route('/scum/search', methods=['GET'])
def scum_search():
"""
SCUM Search
This endpoint allows you to search for a SCUM server using its host and port.
---
tags:
- Search EndPoint
parameters:
- name: host
in: query
type: string
required: true
- name: port
in: query
type: integer
required: true
responses:
200:
description: Success
400:
description: Invalid parameters were supplied. 'host' and 'port' must be provided, and 'port' must be an integer.
404:
description: No server was found with the provided host and port.
"""
return search(request.args, Scum())


@app.route("/terms")
def render_terms():
# Read the contents of terms.md
with open("terms.md", "r") as terms_file:
md_content = terms_file.read()

# Convert Markdown to HTML
html_content = markdown.markdown(md_content)

return html_content


if __name__ == '__main__':
app.run(debug=True)
10 changes: 10 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
attrs==23.2.0
blinker==1.7.0
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
dnspython==2.6.1
flasgger==0.9.7.1
Flask==3.0.2
gunicorn==21.2.0
idna==3.6
itsdangerous==2.1.2
Jinja2==3.1.3
jsonschema==4.21.1
jsonschema-specifications==2023.12.1
Markdown==3.5.2
MarkupSafe==2.1.5
mistune==3.0.2
packaging==24.0
pymongo==4.6.2
python-dotenv==1.0.1
PyYAML==6.0.1
referencing==0.33.0
requests==2.31.0
rpds-py==0.18.0
schedule==1.2.1
six==1.16.0
tqdm==4.66.2
urllib3==2.2.1
Werkzeug==3.0.1
27 changes: 27 additions & 0 deletions terms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# OpenGSQ APIs Terms of Service

## 1. Acceptance of Terms

By accessing and using the **OpenGSQ Master Server Search API**, you agree to comply with these terms and conditions. If you do not agree with any part of these terms, please refrain from using the API.

## 2. Use of the API

- You may use the API for legitimate purposes related to **server search and retrieval**.
- You must not misuse the API, including but not limited to:
- Attempting to gain unauthorized access to the API or its data.
- Introducing malicious code or interfering with the API's functionality.
- Violating any applicable laws or regulations.

## 3. Disclaimer of Warranties

- The API is provided "as is" without any warranties, express or implied.
- We do not guarantee the accuracy, reliability, or availability of the API.

## 4. Limitation of Liability

- **OpenGSQ** shall not be liable for any direct, indirect, incidental, special, or consequential damages arising from API use.
- You assume all risks associated with API usage.

## 5. Changes to the TOS

- We reserve the right to modify these terms at any time. Changes will be effective upon posting on our website.
1 change: 1 addition & 0 deletions version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '1.0.0'

0 comments on commit 4d87ba0

Please sign in to comment.