Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marshmallow-schema'd body parameters lose 'required' and 'description' field spec #168

dlopuch opened this issue Nov 9, 2017 · 1 comment


Copy link

commented Nov 9, 2017

Consider this code:

from marshmallow import Schema, fields
from apispec import APISpec

spec = APISpec(

class SomeBodyParam(Schema):
    name = fields.String(required=True)
    city = fields.String()
    age = fields.Integer()

        'post': {
            'parameters': [
                { 'name': 'some body param',
                  'in': 'body',
                  'schema': SomeBodyParam(),
                  'description': 'Description disapears and so does required',
                  'required': True


The output is:

{'definitions': {},
 'info': {'title': 'bug', 'version': '0.0.1'},
 'parameters': {},
 'paths': OrderedDict([('foo/',
               {'post': {'parameters': [{'in': 'body',
                   'name': 'body',
                   'required': False,
                   'schema': {'properties': {'name': {'type': 'string'}, 'city': {'type': 'string'}, 'age': {'type': 'integer', 'format': 'int32'}},
                    'required': ['name'],
                    'type': 'object'}}]}})]),
 'swagger': '2.0',
 'tags': []}


  • The required field switched from True to False
  • The description field got lost

The name parameter also gets renamed, but I believe this is per-spec.

I believe the cause is here:

Adding a , required=parameter['required'] if 'required' in parameter else False ought to fix the required bit. Do something similar for description, but need to add it to signature and include it in the dict constructor in there.

That sound like a reasonable approach?


This comment has been minimized.

Copy link

commented Nov 10, 2017

@dlopuch I am grateful for the clear bug report.

I am worried that the current implementation of fields2parameters is already complicated,
but I have no idea about other ways. Could you try the fix in that way?


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.