Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

tnweiss
Copy link

@tnweiss tnweiss commented Sep 30, 2019

Below is a request parser for a simple hello world server.

parser = reqparse.RequestParser()
parser.add_argument('test', type=int, location='json')
parser.add_argument('test1', location='json')

The resulting swagger JSON for these parameters is

"parameters": [
    {
         "name": "test",
          "in": "body",
          "type": "integer"
     },
     {
          "name": "test1",
           "in": "body",
           "type": "string"
       }
]

The result should be something similar to when a user provides a model with api.expect()

"parameters": [
    {
        "name": "payload",
        "required": true,
        "in": "body",
        "schema": {
            "properties": {
                "test": {
                    "type": "integer"
                },
                "test1": {
                    "type": "string"
                }
            }
        }
    }
]

These changes fix that bug.

@coveralls
Copy link

coveralls commented Sep 30, 2019

Coverage Status

Coverage decreased (-0.009%) to 96.896% when pulling 1ad9969 on tnweiss:master into a7e363a on noirbizarre:master.

@wood-j
Copy link

wood-j commented Nov 11, 2020

Great job, Thanks
While it's not avaliable at 2020/11, I just use your commit as a monkey patch so solve my problem.
Thanks aloooooooooooooooot!

By the way, I found that 'type': 'object' should be inside of schema for version 0.13.0

def rparser_to_swagger_body_param(request_parser):
    """
    If any parameters are in the request body then return the swagger representation for the requests json body
    :param request_parser: The request parser containing params for the request
    :return:
    """
    json_body_list = [p for p in request_parser.__schema__ if p['in'] == 'body']
    if not json_body_list:
        return

    properties = {}
    for param in json_body_list:
        properties[param['name']] = {
            'type': 'string' if 'type' not in param else param['type']
        }

    return {
        'name': 'payload',
        'required': True,
        'in': 'body',
        'schema': {
            'type': 'object',
            'properties': properties
        }
    }

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.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.