More Marshmallow argument updates

This commit is contained in:
Richard Bowman 2022-08-09 13:16:10 +01:00
parent e22f36b308
commit 9dbb083ee7
18 changed files with 102 additions and 87 deletions

View file

@ -46,7 +46,7 @@ class ExampleIdentifyView(View):
class ExampleRenameView(View):
# Expect a request parameter called "name", which is a string.
# Passed to the argument "args".
args = fields.String(required=True, example="My Example Microscope")
args = fields.String(required=True, metadata={"example": "My Example Microscope"})
def post(self, args):
# Look for our new name in the request body

View file

@ -49,7 +49,7 @@ class ExampleRenameView(View):
# Format our returned object using MicroscopeIdentifySchema
schema = MicroscopeIdentifySchema()
# Expect a request parameter called "name", which is a string. Pass to argument "args".
args = {"name": fields.String(required=True, example="My Example Microscope")}
args = {"name": fields.String(required=True, metadata={"example": "My Example Microscope"})}
def post(self, args):
# Look for our "name" parameter in the request arguments

View file

@ -53,7 +53,7 @@ class ExampleIdentifyView(PropertyView):
# We can use a single schema as the input and output will be formatted identically
# Eg. We always expect a "name" string argument, and always return a "name" string attribute
class ExampleRenameView(PropertyView):
schema = {"name": fields.String(required=True, example="My Example Microscope")}
schema = {"name": fields.String(required=True, metadata={"example": "My Example Microscope"})}
def get(self):
"""

View file

@ -56,7 +56,7 @@ class ExampleIdentifyView(PropertyView):
# We can use a single schema as the input and output will be formatted identically
# Eg. We always expect a "name" string argument, and always return a "name" string attribute
class ExampleRenameView(PropertyView):
schema = {"name": fields.String(required=True, example="My Example Microscope")}
schema = {"name": fields.String(required=True, metadata={"example": "My Example Microscope"})}
def get(self):
"""

View file

@ -66,10 +66,10 @@ class TimelapseAPIView(ActionView):
args = {
"n_images": fields.Integer(
required=True, example=5, description="Number of images"
required=True, metadata={"example": 5, "description": "Number of images"}
),
"t_between": fields.Number(
load_default=1, example=1, description="Time (seconds) between images"
load_default=1, metadata={"example": 1, "description": "Time (seconds) between images"}
),
}

View file

@ -99,10 +99,10 @@ class TimelapseAPIView(ActionView):
args = {
"n_images": fields.Integer(
required=True, example=5, description="Number of images"
required=True, metadata={"example": 5, "description": "Number of images"}
),
"t_between": fields.Number(
load_default=1, example=1, description="Time (seconds) between images"
load_default=1, metadata={"example": 1, "description": "Time (seconds) between images"}
),
}

View file

@ -23,7 +23,7 @@ A **field** describes the data type of a single parameter, as well as any other
.. code-block:: python
fields.String(required=False, load_default="Default value", example="Example value")
fields.String(required=False, load_default="Default value", metadata={"example: "Example value"})
A **schema** is a collection of keys and fields describing how an object should be serialized/deserialized. Schemas can be created in several ways, either by creating a ``Schema`` class, or by passing a dictionary of key-field pairs. Both methods will be discussed in the following examples.
@ -146,7 +146,7 @@ Our ``rename`` view class may now look like:
# Format our returned object using MicroscopeIdentifySchema
schema = MicroscopeIdentifySchema()
# Expect a request parameter called "name", which is a string. Pass to argument "args".
args = {"name": fields.String(required=True, example="My Example Microscope")}
args = {"name": fields.String(required=True, metadata={"example": "My Example Microscope"})}
def post(self, args):
# Look for our "name" parameter in the request arguments

View file

@ -78,7 +78,7 @@ We will implement the ``schema`` attribute in our ``ExampleRenameView`` view fro
# We can use a single schema as the input and output will be formatted identically
# Eg. We always expect a "name" string argument, and always return a "name" string attribute
class ExampleRenameView(PropertyView):
schema = {"name": fields.String(required=True, example="My Example Microscope")}
schema = {"name": fields.String(required=True, metadata={"example": "My Example Microscope"})}
def get(self):
"""