Skip to content

Api(..., ordered=True) and Nested models → error in Swagger UI #128

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

Open
arkady opened this issue May 5, 2020 · 0 comments
Open

Api(..., ordered=True) and Nested models → error in Swagger UI #128

arkady opened this issue May 5, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@arkady
Copy link

arkady commented May 5, 2020

When ordered=True is passed to Api (or a namespace), having Nested models causes an error in the Swagger UI

Example Code

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

app = Flask(__name__)
api = Api(app, ordered=True)  ## ← Changing this to False removes error

AddressModel = api.model('Address', {'street': fields.String(required=True),
                                     'city': fields.String(required=True)
                                     })

PersonModel = api.model('Person', {'name': fields.String(required=True),
                                   'address': fields.Nested(AddressModel)})

@api.route('/hello')
class Hello(Resource):
    @api.expect(PersonModel, validate=True)
    @api.marshal_with(PersonModel)
    def put(self):
        return request.json

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

Repro Steps (if applicable)

  1. Run the code above (Python 2.7.12)
  2. Navigate to localhost:5000
  3. Click on the default namespace to expand it
  4. Click on `/hello' endpoint

Expected Behavior

Should see Example Value and Model reflecting the nested models defined in code:

{
  "name": "string",
  "address": {
    "city": "string",
    "street": "string"
  }
}

Actual Behavior

The Example Value is missing the Nested Address model:

{
  "name": "string"
}

Also, an error pops up at the top of the Swagger UI page:

Resolver error at paths./hello.put.parameters.0.schema.properties.address.$ref
Could not resolve reference: Could not resolve pointer: /definitions/Address does not exist in document

Error Messages/Stack Trace

If applicable, add the stack trace produced by the error

Environment

  • Python version: 2.7.12
  • Flask version: 0.12.2
  • Flask-RESTX version: 0.2.0
  • Other installed Flask extensions: n/a
@arkady arkady added the bug Something isn't working label May 5, 2020
@arkady arkady changed the title ordered=True and Nested models → error in Swagger UI Api(..., ordered=True) and Nested models → error in Swagger UI May 5, 2020
@arkady arkady changed the title Api(..., ordered=True) and Nested models → error in Swagger UI Api(..., ordered=True) and Nested models → error in Swagger UI May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant