Skip to content

Commit

Permalink
formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rwb27 committed Jul 21, 2021
1 parent 7ba0950 commit e27e904
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 25 deletions.
23 changes: 13 additions & 10 deletions src/labthings/apispec/plugins.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/labthings/apispec/utilities.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
10 changes: 7 additions & 3 deletions src/labthings/default_views/docs/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
"""

Expand All @@ -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"""

Expand All @@ -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")
)
Expand Down
2 changes: 1 addition & 1 deletion src/labthings/extensions.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/labthings/labthing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/labthings/marshalling/args.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/labthings/marshalling/marshalling.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 2 additions & 7 deletions src/labthings/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
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
from ..deque import Deque
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"]
Expand Down
1 change: 1 addition & 0 deletions src/labthings/views/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Type

from flask import abort, send_file

from . import View, described_operation


Expand Down

0 comments on commit e27e904

Please sign in to comment.