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

Openapi 3.0.X support for shcemas in paramters in marshmallow extension #217

Merged
merged 3 commits into from
May 29, 2018

Conversation

fMeow
Copy link
Contributor

@fMeow fMeow commented May 27, 2018

Currently, marshmallow extension only partially supports openapi 3.0.X . In my case, I would like to assign marshmallow schema object in parameters.

The code below is a demonstration for my case.

from marshmallow import Schema, fields

class PetSchema(Schema):
    id = fields.Int(dump_only=True)
    name = fields.Str()
    age = fields.Int()

def pet_view():
    """Not much to see here.
    ---
    get:
        parameters:
            - in: query
              schema: PetSchema
    """
    return '...'

The expected result in Openapi Specification 3.0.X is as below:

get:
  parameters:
  - in: query
    name: name
    required: false
    schema: 
      type: string
  - in: query
    name: age
    required: false
    schema: 
      format: int32
      type: integer

In short, format and type field must be inside schema object. A parameter object do not allow format field nor type field.

However, current result is as follow:

get:
  parameters:
  - in: query
    name: name
    required: false
    type: string
  - in: query
    name: age
    required: false
    format: int32
    type: integer

Thus, I modify the code to fix this behavior. Also, I notice that collectionFormat field is now deprecated in Openapi 3.0.X . Instead, an equivalent of collection set to multi is that style set to form, with explode set to true.
See style values. Below is some important description or examples copied directly from openapi specification.

style explode empty string array object
form true color= color=blue color=blue&color=black&color=brown R=100&G=200&B=150
name: id
in: query
description: ID of the object to fetch
required: false
schema:
  type: array
  items:
    type: string
style: form
explode: true

@sloria
Copy link
Member

sloria commented May 29, 2018

This looks great. Thanks!

@sloria sloria merged commit 6c6e29e into marshmallow-code:dev May 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants