Skip to content

Wildcard field contains an extra nested level in docs #57

@anthiras

Description

@anthiras

This might be related to the recent wildcard field changes, e.g. #24.

When using a wildcard field with nested models, the resulting documentation contains three levels: *, <*>, and the nested model, where I would expect just two: The key <*> and the nested model. Example values in the doc also contains an extra nested level.

Please note, the actual output of the marshaled model in get is correct, only the swagger doc is wrong.

Code

from flask import Flask
from flask_restx import Resource, Api, fields

app = Flask(__name__)
api = Api(app)

nested_model = api.model('Nested model', {'nested_string': fields.String()})
wild = fields.Wildcard(fields.Nested(nested_model))
wildcard_model = api.model('Wildcard model', {'*': wild})

@api.route('/hello')
class HelloWorld(Resource):
    @api.marshal_with(wildcard_model)
    def get(self):
        return {
            'foo': {
                'nested_string': 'foo'
            },
            'bar': {
                'nested_string': 'bar'
            }
        }

if __name__ == '__main__':
    app.run(debug=True)

Repro Steps (if applicable)

  1. Run example above
  2. View documentation at http://localhost:5000

Actual model doc

wildcard-model

Expected model doc

Only one level of *, not two.

Actual example value doc

{
  "*": {
    "additionalProp1": {
      "nested_string": "string"
    },
    "additionalProp2": {
      "nested_string": "string"
    },
    "additionalProp3": {
      "nested_string": "string"
    }
  }
}

Expected example value doc

{
  "additionalProp1": {
    "nested_string": "string"
  },
  "additionalProp2": {
    "nested_string": "string"
  },
  "additionalProp3": {
    "nested_string": "string"
  }
}

or

{
  "*": {
    "nested_string": "string"
  }
}

Actual output of get (correct)

{
  "bar": {
    "nested_string": "bar"
  },
  "foo": {
    "nested_string": "foo"
  }
}

Environment

  • Python 3.7
  • Flask 1.1.1
  • Flask-RESTX 0.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions