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 extensions does not support plural schema instances #71

Closed
deckar01 opened this issue Apr 29, 2016 · 1 comment

Comments

@deckar01
Copy link
Member

commented Apr 29, 2016

I expected

get:
  description: Get the list of pets.
  responses:
    200:
      description: A list of pet objects.
      schema:
        type: array
        items: PetSchema

to produce

"get": {
  "description": "Get the list of pets.",
  "responses": {
    "200": {
    "description": "A list of pet objects.",
    "schema": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/Pet"
      }
    }
  }
}

but got

"get": {
  "description": "Get the list of pets.",
  "responses": {
    "200": {
    "description": "A list of pet objects.",
    "schema": {
      "type": "array",
      "items": "PetSchema"
    }
  }
}

The issue is that apispec/ext/marshmallow/init.py#L77 only checks if many is set to true on the class, but the more common marshmallow pattern is to set many=True when constructing schema instances. This also fails for the reverse case when the class is set to many=True, but the instance used for the view is constructed with many=False (although this seems like an anti-pattern).

Since the instance parameter overrides the class attribute, it should probably be considered a default, which means that it should be ignored and the format I used above should be used instead.

@deckar01

This comment has been minimized.

Copy link
Member Author

commented May 1, 2016

Actually, after looking at the implementation, checking the many attribute is perfectly valid for nested schemas, so all that needs to be fixed is properly resolving the items attribute in the schema array pattern.

@deckar01 deckar01 referenced this issue May 1, 2016
3 of 3 tasks complete

@sloria sloria closed this in #72 May 2, 2016

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