diff --git a/src/labthings/apispec/plugins.py b/src/labthings/apispec/plugins.py index 6e24998..474b781 100644 --- a/src/labthings/apispec/plugins.py +++ b/src/labthings/apispec/plugins.py @@ -1,20 +1,17 @@ import re - -from apispec import BasePlugin from copy import deepcopy -from apispec.ext.marshmallow import ( - MarshmallowPlugin as _MarshmallowPlugin, -) +from apispec import BasePlugin +from apispec.ext.marshmallow import MarshmallowPlugin as _MarshmallowPlugin from apispec.ext.marshmallow import OpenAPIConverter from flask.views import http_method_funcs from .. import fields from ..json.schemas import schema_to_json -from ..schema import EventSchema, ActionSchema +from ..schema import ActionSchema, EventSchema from ..utilities import get_docstring, get_summary, merge -from .utilities import ensure_schema, get_marshamallow_plugin from ..views import ActionView, EventView, PropertyView, View +from .utilities import ensure_schema, get_marshamallow_plugin class ExtendedOpenAPIConverter(OpenAPIConverter): @@ -102,11 +99,17 @@ def spec_for_interaction(cls, interaction): "parameters": [], } # Allow custom responses from the class, overridden by the method - d[method]["responses"].update(deepcopy(getattr(interaction, "responses", {}))) + d[method]["responses"].update( + deepcopy(getattr(interaction, "responses", {})) + ) d[method]["responses"].update(deepcopy(getattr(prop, "responses", {}))) # Allow custom parameters from the class & method - d[method]["parameters"].extend(deepcopy(getattr(interaction, "parameters", {}))) - d[method]["parameters"].extend(deepcopy(getattr(prop, "parameters", {}))) + d[method]["parameters"].extend( + deepcopy(getattr(interaction, "parameters", {})) + ) + d[method]["parameters"].extend( + deepcopy(getattr(prop, "parameters", {})) + ) return d @classmethod diff --git a/src/labthings/apispec/utilities.py b/src/labthings/apispec/utilities.py index 38814cb..3acc709 100644 --- a/src/labthings/apispec/utilities.py +++ b/src/labthings/apispec/utilities.py @@ -1,7 +1,9 @@ +from typing import Dict, Union + from apispec.ext.marshmallow import MarshmallowPlugin from apispec.ext.marshmallow.field_converter import FieldConverterMixin from marshmallow import Schema -from typing import Dict, Union + from .. import fields diff --git a/src/labthings/default_views/docs/__init__.py b/src/labthings/default_views/docs/__init__.py index cd8ea83..8e4067d 100644 --- a/src/labthings/default_views/docs/__init__.py +++ b/src/labthings/default_views/docs/__init__.py @@ -1,4 +1,4 @@ -from flask import Blueprint, make_response, render_template, Response +from flask import Blueprint, Response, make_response, render_template from ...find import current_labthing from ...views import View @@ -18,9 +18,10 @@ def get(self): """OpenAPI v3 documentation""" return current_labthing().spec.to_dict() + class APISpecYAMLView(View): """OpenAPI v3 documentation - + A YAML document containing an API description in OpenAPI format """ @@ -34,6 +35,7 @@ class APISpecYAMLView(View): def get(self): return Response(current_labthing().spec.to_yaml(), mimetype="text/yaml") + class SwaggerUIView(View): """Swagger UI documentation""" @@ -49,7 +51,9 @@ def get(self): docs_blueprint.add_url_rule("/swagger", view_func=APISpecView.as_view("swagger_json")) docs_blueprint.add_url_rule("/openapi", endpoint="swagger_json") docs_blueprint.add_url_rule("/openapi.json", endpoint="swagger_json") -docs_blueprint.add_url_rule("/openapi.yaml", view_func=APISpecYAMLView.as_view("openapi_yaml")) +docs_blueprint.add_url_rule( + "/openapi.yaml", view_func=APISpecYAMLView.as_view("openapi_yaml") +) docs_blueprint.add_url_rule( "/swagger-ui", view_func=SwaggerUIView.as_view("swagger_ui") ) diff --git a/src/labthings/extensions.py b/src/labthings/extensions.py index 4861f99..46f7443 100644 --- a/src/labthings/extensions.py +++ b/src/labthings/extensions.py @@ -1,9 +1,9 @@ import glob +import inspect import logging import os import sys import traceback -import inspect from importlib import util from typing import Callable, Dict, List, Union diff --git a/src/labthings/labthing.py b/src/labthings/labthing.py index 7ca9dcb..d5beead 100644 --- a/src/labthings/labthing.py +++ b/src/labthings/labthing.py @@ -6,7 +6,7 @@ from apispec import APISpec from apispec_webframeworks.flask import FlaskPlugin -from flask import url_for, Flask +from flask import Flask, url_for from .actions.pool import Pool from .apispec import FlaskLabThingsPlugin, MarshmallowPlugin diff --git a/src/labthings/marshalling/args.py b/src/labthings/marshalling/args.py index df543d7..e2b31bf 100644 --- a/src/labthings/marshalling/args.py +++ b/src/labthings/marshalling/args.py @@ -1,6 +1,6 @@ import logging from functools import update_wrapper, wraps -from typing import Callable, Union, Mapping +from typing import Callable, Mapping, Union from flask import abort, request from marshmallow.exceptions import ValidationError diff --git a/src/labthings/marshalling/marshalling.py b/src/labthings/marshalling/marshalling.py index 697a72d..5a2d15f 100644 --- a/src/labthings/marshalling/marshalling.py +++ b/src/labthings/marshalling/marshalling.py @@ -1,6 +1,6 @@ from collections.abc import Mapping from functools import wraps -from typing import Callable, Dict, Tuple, Union, Optional +from typing import Callable, Dict, Optional, Tuple, Union from marshmallow import Schema as _Schema from werkzeug.wrappers import Response as ResponseBase diff --git a/src/labthings/views/__init__.py b/src/labthings/views/__init__.py index 8770c42..80658bc 100644 --- a/src/labthings/views/__init__.py +++ b/src/labthings/views/__init__.py @@ -1,10 +1,10 @@ import datetime from collections import OrderedDict from typing import Callable, Dict, List, Optional, Set, cast -from typing_extensions import Protocol from flask import request from flask.views import MethodView +from typing_extensions import Protocol from werkzeug.wrappers import Response as ResponseBase from ..actions.pool import Pool @@ -12,12 +12,7 @@ from ..find import current_labthing, find_extension from ..marshalling import marshal_with, use_args from ..representations import DEFAULT_REPRESENTATIONS -from ..schema import ( - ActionSchema, - EventSchema, - FuzzySchemaType, - build_action_schema, -) +from ..schema import ActionSchema, EventSchema, FuzzySchemaType, build_action_schema from ..utilities import unpack __all__ = ["MethodView", "View", "ActionView", "PropertyView", "op", "builder"] diff --git a/src/labthings/views/builder.py b/src/labthings/views/builder.py index 74e3023..48b3dca 100644 --- a/src/labthings/views/builder.py +++ b/src/labthings/views/builder.py @@ -4,6 +4,7 @@ from typing import Type from flask import abort, send_file + from . import View, described_operation