-
Notifications
You must be signed in to change notification settings - Fork 505
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
fix missing definition of nested ordered model #616
base: master
Are you sure you want to change the base?
Conversation
Example UI error message: ``` Could not resolve pointer: /definitions/XXX does not exist in document ```
2 similar comments
Thank you for contributing! Is there an issue that goes along with this PR? If not, could please include some steps to reproduce the issue and to demonstrate the fix? |
Minimal example: import json
from flask import Flask
from flask_restplus import fields, Api, Swagger, Resource
app = Flask(__name__)
app.config['SERVER_NAME'] = "localhost"
api = Api(app, ordered=True)
simple = api.model('Simple', [
('foo', fields.String),
])
composite = api.model('Composite', [
('simple', fields.Nested(model=simple)),
('bar', fields.String),
])
@api.route('/')
class Composite(Resource):
@api.marshal_with(composite)
def get(self):
pass
with app.app_context():
swagger_json = Swagger(api).as_dict()
print(json.dumps(swagger_json, indent=2, sort_keys=True)) generates the following {
"basePath": "http://localhost",
"consumes": [
"application/json"
],
"definitions": {
"Composite": {
"properties": {
"bar": {
"type": "string"
},
"simple": {
"$ref": "#/definitions/Simple"
}
},
"type": "object"
}
},
"host": "localhost",
"info": {
"title": "API",
"version": "1.0"
},
"paths": {
"/": {
"get": {
"operationId": "get_composite",
"parameters": [
{
"description": "An optional fields mask",
"format": "mask",
"in": "header",
"name": "X-Fields",
"type": "string"
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/Composite"
}
}
},
"tags": [
"default"
]
}
}
},
"produces": [
"application/json"
],
"responses": {
"MaskError": {
"description": "When any error occurs on mask"
},
"ParseError": {
"description": "When a mask can't be parsed"
}
},
"swagger": "2.0",
"tags": [
{
"description": "Default namespace",
"name": "default"
}
]
} which is lacking the definition of the type ...
"Simple": {
"properties": {
"foo": {
"type": "string"
}
},
"type": "object"
}
... the commits in the PR fix this |
Can confirm that I'm having this problem too and have had to monkeypatch flask_restplus |
Going to check this and also check against cases listed in pr #640 and the issues linked there. It seems to have similar characteristics, though with the wide variety of symptoms we're seeing against nested schema, it's making it hard to focus it down. |
Was able to reproduce specific issue regarding Ordered. Also confirm this patch fixes the specific problem of ordered APIs and using api.model schema style generation. This doesn't help with JSON schema related issues. Being said, definitely worth bringing in for fixing ordered APIs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a test case for Ordered models, just so we have the extra coverage. However, not blocking
This also addresses some cases found in issues #643 . We should pull this in and ensure it goes out in our upcoming release |
Hi. Any idea when this will get merged? |
Example UI error message: