Skip to content

Commit

Permalink
Merge pull request #4 from aalises/generate_docs
Browse files Browse the repository at this point in the history
Generate docs
  • Loading branch information
aalises committed Nov 8, 2018
2 parents d2f8718 + d3d0556 commit 757fdc7
Show file tree
Hide file tree
Showing 10 changed files with 502 additions and 26 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.com/aalises/age-of-empires-II-api.svg?branch=master)](https://travis-ci.com/aalises/age-of-empires-II-api)
[![Coverage Status](https://coveralls.io/repos/github/aalises/age-of-empires-II-api/badge.svg?branch=master)](https://coveralls.io/github/aalises/age-of-empires-II-api?branch=master)

- `WIP. TODO:` Docs, Deployment
- `WIP. TODO:` Deployment

Age of Empires II API created with `Flask + FlaskRESTful` using SQLite as a DB and `SQLAlchemy` as ORM, which allows you to retrieve information about the civilizations, technologies, units and structures. To run you can use Docker, for example:

Expand All @@ -11,7 +11,9 @@ docker build -t aoe2api:v1 .
docker run --name aoe2api -p 8080:80 -d aoe2api:v1
```

And navigate to `localhost:8080/api/v1`
The routes are:
- Main API route: `localhost:8080/api/v1`
- Docs Route: `localhost:8080/docs`

To test using `pytest`, just run

Expand Down
8 changes: 6 additions & 2 deletions api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from api.resources.unit import Unit, UnitList
from api.resources.structure import Structure, StructureList
from api.resources.technology import Technology, TechnologyList
from config import API_PREFIX
from config import API_PREFIX, SWAGGER_CONFIG
from db import db
from flasgger import Swagger

def create_app(cfg):
app = Flask(__name__)
Expand All @@ -15,7 +16,7 @@ def create_app(cfg):
api = Api(api_blueprint, prefix=API_PREFIX)

add_routes(api)

add_docs(app, SWAGGER_CONFIG, '../data/apispecs.yaml')
app.register_blueprint(api_blueprint)
db.init_app(app)

Expand All @@ -31,3 +32,6 @@ def add_routes(api):
api.add_resource(StructureList, '/structures')
api.add_resource(Technology, '/technology/<string:_id>')
api.add_resource(TechnologyList, '/technologies')

def add_docs(app, cfg, template):
Swagger(app, config=cfg, template_file=template)
12 changes: 6 additions & 6 deletions api/models/civilization.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class CivilizationModel(db.Model):

_id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), nullable=False, unique=False)
expansion = db.Column(db.String(80))
army_type = db.Column(db.String(80))
unique_unit = db.Column(db.String(80), db.ForeignKey('units.name'))
unique_tech = db.Column(db.String(80), db.ForeignKey('technologies.name'))
team_bonus = db.Column(db.String(200))
civilization_bonus = db.Column(db.Text)
expansion = db.Column(db.String(80), nullable=False)
army_type = db.Column(db.String(80), nullable=False)
unique_unit = db.Column(db.String(80), db.ForeignKey('units.name'), nullable=False)
unique_tech = db.Column(db.String(80), db.ForeignKey('technologies.name'), nullable=False)
team_bonus = db.Column(db.String(200), nullable=False)
civilization_bonus = db.Column(db.Text, nullable=False)

unit = db.relationship('UnitModel', lazy='dynamic', uselist=True)
technology = db.relationship('TechnologyModel', lazy='dynamic', uselist=True)
Expand Down
12 changes: 6 additions & 6 deletions api/models/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class StructureModel(db.Model):
_id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), nullable=False)
expansion = db.Column(db.String(80), nullable=False)
age = db.Column(db.String(80))
cost = db.Column(db.String(80))
build_time = db.Column(db.Integer)
hit_points = db.Column(db.Integer)
line_of_sight = db.Column(db.Integer)
armor = db.Column(db.String(5))
age = db.Column(db.String(80), nullable=False)
cost = db.Column(db.String(80), nullable=False)
build_time = db.Column(db.Integer, nullable=False)
hit_points = db.Column(db.Integer, nullable=False)
line_of_sight = db.Column(db.Integer, nullable=False)
armor = db.Column(db.String(5), nullable=False)
range = db.Column(db.String(80), nullable=True)
reload_time = db.Column(db.Float, nullable=True)
attack = db.Column(db.Integer, nullable=True)
Expand Down
12 changes: 6 additions & 6 deletions api/models/technology.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class TechnologyModel(db.Model):

_id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), nullable=False)
description = db.Column(db.String(80))
expansion = db.Column(db.String(80))
age = db.Column(db.String(80))
develops_in = db.Column(db.String(80), db.ForeignKey("structures.name"))
cost = db.Column(db.String(80))
build_time = db.Column(db.Integer)
description = db.Column(db.String(80), nullable=True)
expansion = db.Column(db.String(80), nullable=False)
age = db.Column(db.String(80), nullable=False)
develops_in = db.Column(db.String(80), db.ForeignKey("structures.name"), nullable=False)
cost = db.Column(db.String(80), nullable=False)
build_time = db.Column(db.Integer, nullable=False)
applies_to = db.Column(db.String(80), nullable=True)

structure = db.relationship('StructureModel', lazy='dynamic', uselist=True)
Expand Down
2 changes: 1 addition & 1 deletion api/models/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class UnitModel(db.Model):

_id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), nullable=False)
description = db.Column(db.String(200), nullable=False)
description = db.Column(db.String(200), nullable=True)
expansion = db.Column(db.String(80), nullable=False)
age = db.Column(db.String(80), nullable=False)
created_in = db.Column(db.String(80), db.ForeignKey("structures.name"))
Expand Down
20 changes: 19 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,23 @@
'SQLALCHEMY_TRACK_MODIFICATIONS': False,
'PROPAGATE_EXCEPTIONS': True,
'JSONIFY_PRETTYPRINT_REGULAR': True,
'JSON_SORT_KEYS': False
'JSON_SORT_KEYS': False,
'SWAGGER': {
'title': 'Age of Empires II API',
'uiversion': 3
}
}

SWAGGER_CONFIG = {
"headers": [
],
"specs": [
{
"endpoint": 'apispec',
"route": '/apispec.json'
}
],
"static_url_path": "/flasgger_static",
"swagger_ui": True,
"specs_route": "/docs/"
}
Loading

0 comments on commit 757fdc7

Please sign in to comment.