Renamed Resource to View, and allow custom root links

This commit is contained in:
Joel Collins 2020-01-14 11:41:56 +00:00
parent 234ebc1cbb
commit a329b9197b
18 changed files with 90 additions and 67 deletions

View file

@ -2,14 +2,14 @@ from flask import abort, url_for, jsonify, render_template, Blueprint, current_a
from openflexure_microscope.common.labthings_core.utilities import get_docstring
from ...resource import Resource
from ...view import View
from ...find import current_labthing
from ...spec import rule_to_path, rule_to_params
import os
class APISpecResource(Resource):
class APISpecView(View):
"""
OpenAPI v3 documentation
"""
@ -21,7 +21,7 @@ class APISpecResource(Resource):
return jsonify(current_labthing().spec.to_dict())
class SwaggerUIResource(Resource):
class SwaggerUIView(View):
"""
Swagger UI documentation
"""
@ -30,7 +30,7 @@ class SwaggerUIResource(Resource):
return render_template("swagger-ui.html")
class W3CThingDescriptionResource(Resource):
class W3CThingDescriptionView(View):
"""
W3C-style Thing Description
"""
@ -103,11 +103,11 @@ docs_blueprint = Blueprint(
)
docs_blueprint.add_url_rule(
"/swagger", view_func=APISpecResource.as_view("swagger_json")
"/swagger", view_func=APISpecView.as_view("swagger_json")
)
docs_blueprint.add_url_rule(
"/swagger-ui", view_func=SwaggerUIResource.as_view("swagger_ui")
"/swagger-ui", view_func=SwaggerUIView.as_view("swagger_ui")
)
docs_blueprint.add_url_rule(
"/td", view_func=W3CThingDescriptionResource.as_view("w3c_td")
"/td", view_func=W3CThingDescriptionView.as_view("w3c_td")
)

View file

@ -1,14 +1,14 @@
"""
Top-level representation of attached and enabled Extensions
"""
from ..resource import Resource
from ..view import View
from ..find import registered_extensions
from ..schema import ExtensionSchema
from ..decorators import marshal_with, ThingProperty
@ThingProperty
class ExtensionList(Resource):
class ExtensionList(View):
"""
List and basic documentation for all enabled Extensions
"""

View file

@ -1,7 +1,7 @@
from flask import abort, url_for
from ..decorators import marshal_with, ThingProperty, Tag
from ..resource import Resource
from ..view import View
from ..schema import TaskSchema
from openflexure_microscope.common.labthings_core import tasks
@ -9,7 +9,7 @@ from openflexure_microscope.common.labthings_core import tasks
@ThingProperty
@Tag("tasks")
class TaskList(Resource):
class TaskList(View):
@marshal_with(TaskSchema(many=True))
def get(self):
"""
@ -19,7 +19,7 @@ class TaskList(Resource):
@Tag(["properties", "tasks"])
class TaskResource(Resource):
class TaskView(View):
@marshal_with(TaskSchema())
def get(self, id):
"""