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

Nested fields are not rendered in model's schema #736

Open
alvarolopez opened this issue Oct 16, 2019 · 0 comments
Open

Nested fields are not rendered in model's schema #736

alvarolopez opened this issue Oct 16, 2019 · 0 comments
Labels

Comments

@alvarolopez
Copy link

In current HEAD (9b9ad42) the model's schema is not generated correctly if it contains nested models.

Taking into account the following model definition, where I have a nested model defined:

model_links = ns.model('Location', {                                               
    "rel": fields.String(),                                                        
    "href": fields.Url()                                                           
})                                                                                 
                                                                                   
model_meta = ns.model('Model', {                                                   
    'id': fields.String(),                                                         
    'name': fields.String(),                                                       
    'links': fields.List(fields.Nested(model_links))                               
}) 

If I access the model's schema, I get the following:

{'properties': {'id': {'type': 'string'},
                'links': {'items': {'$ref': '#/definitions/Location'},
                          'type': 'array'},
                'name': {'type': 'string'}},
 'type': 'object'}

As you can see, the nested models are not defined, resulting in an invalid schema. What I would expect is the following:

{'definitions': {'Location': {'properties': {'href': {'type': 'string'},
                                             'rel': {'type': 'string'}},
                              'type': 'object'}},
 'properties': {'id': {'type': 'string'},
                'links': {'items': {'$ref': '#/definitions/Location'},
                          'type': 'array'},
                'name': {'type': 'string'}},
 'type': u'object'}

This is basically because the schema is not generated recursively (in models.RawModel._schema()). However, in the swagger.json this is done recursively and it is rendered correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant