Add API documentation for other resources on xway

This commit is contained in:
David Eder 2021-06-17 19:05:26 +02:00
parent 4a38a3a4a7
commit 1f2bddf2f5
2 changed files with 46 additions and 35 deletions

View File

@ -18,7 +18,7 @@ export class RestService {
} }
getCarEvents(vin) { getCarEvents(vin) {
return this.http.get(this.currentLocation + 'car_events/?vin=' + vin, {observe: 'response'}); return this.http.get(this.currentLocation + 'car_events?vin=' + vin, {observe: 'response'});
} }
getTrafficLights() { getTrafficLights() {

View File

@ -9,23 +9,22 @@ import json;
app = Flask(__name__) app = Flask(__name__)
CORS(app) CORS(app)
api_bp = flask.Blueprint("api", __name__, url_prefix="/api/v1/resources") api_bp = flask.Blueprint("api", __name__, url_prefix="/api/v1")
API = flask_restx.Api(api_bp) API = flask_restx.Api(api_bp)
app.register_blueprint(api_bp) app.register_blueprint(api_bp)
NAMESPACE = API.namespace("resources")
NAMESPACE = API.namespace("car_events")
ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/' ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/'
EVENT_STORE_URL = 'http://eventstore:5001/api/keys/' EVENT_STORE_URL = 'http://eventstore:5001/api/keys/'
@NAMESPACE.route('/') @NAMESPACE.route('/car_events', doc={'description': 'Get most current car event for specific car'})
class CarsEvents(flask_restx.Resource): class CarsEvents(flask_restx.Resource):
@NAMESPACE.doc(params={'vin': {'description': 'Vehicle Identifier Number of car', @NAMESPACE.doc(params={'vin': {'description': 'Vehicle Identifier Number of car',
'type': 'String', 'default': '5GZCZ43D13S812715'}}) 'type': 'String', 'default': '5GZCZ43D13S812715'}})
@NAMESPACE.response(200, 'Success')
def get(self): def get(self):
vin = request.args.get('vin') vin = request.args.get('vin')
@ -40,8 +39,13 @@ class CarsEvents(flask_restx.Resource):
return jsonify(cars) return jsonify(cars)
@app.route('/api/v1/resources/traffic_light_events', methods=['GET']) @NAMESPACE.route('/traffic_light_events', doc={'description': 'Get most current traffic light event'
def get_traffic_light_events(): 'for specific traffic light'})
class TrafficLightEvents(flask_restx.Resource):
@NAMESPACE.doc(params={'id': {'description': 'Unique ID of traffic light',
'type': 'int', 'default': '1'}})
@NAMESPACE.response(200, 'Success')
def get(self):
id = request.args.get('id') id = request.args.get('id')
try: try:
@ -52,11 +56,14 @@ def get_traffic_light_events():
print("Is the EVENT_STORE_URL running and reachable?") print("Is the EVENT_STORE_URL running and reachable?")
raise e raise e
return json_util.dumps(traffic_lights) return jsonify(traffic_lights)
@app.route('/api/v1/resources/cars', methods=['GET']) @NAMESPACE.route('/cars', doc={'description': 'Get entity details for all cars'})
def get_cars(): class Car(flask_restx.Resource):
@NAMESPACE.response(200, 'Success')
def get(self):
try: try:
response = requests.get(ENTITY_IDENT_URL + 'cars') response = requests.get(ENTITY_IDENT_URL + 'cars')
cars = response.json()['cursor'] cars = response.json()['cursor']
@ -65,11 +72,15 @@ def get_cars():
print("Is the entity_ident_server running and reachable?") print("Is the entity_ident_server running and reachable?")
raise e raise e
return json_util.dumps(cars) return jsonify(cars)
@app.route('/api/v1/resources/traffic_lights', methods=['GET']) @NAMESPACE.route('/traffic_lights', doc={'description': 'Get entity details for all traffic lights'})
def get_traffic_lights(): class TrafficLights(flask_restx.Resource):
@NAMESPACE.response(200, 'Success')
def get(self):
try: try:
response = requests.get(ENTITY_IDENT_URL + 'traffic_lights') response = requests.get(ENTITY_IDENT_URL + 'traffic_lights')
traffic_lights = response.json()['cursor'] traffic_lights = response.json()['cursor']
@ -78,7 +89,7 @@ def get_traffic_lights():
print("Is the entity_ident_server running and reachable?") print("Is the entity_ident_server running and reachable?")
raise e raise e
return json_util.dumps(traffic_lights) return jsonify(traffic_lights)
if __name__ == '__main__': if __name__ == '__main__':