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

fix missing definition of nested ordered model #616

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

illes
Copy link

@illes illes commented Mar 30, 2019

Example UI error message:

Could not resolve pointer: /definitions/XXX does not exist in document

Example UI error message:
```
Could not resolve pointer: /definitions/XXX does not exist in document
```
@coveralls
Copy link

Coverage Status

Coverage remained the same at 96.845% when pulling 6b386ea on illes:patch-1 into a8f3582 on noirbizarre:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 96.845% when pulling 6b386ea on illes:patch-1 into a8f3582 on noirbizarre:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 96.845% when pulling 6b386ea on illes:patch-1 into a8f3582 on noirbizarre:master.

@SteadBytes
Copy link
Collaborator

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?

@SteadBytes SteadBytes added the Needed: Feedback Feedback needed from the author label Mar 30, 2019
@illes
Copy link
Author

illes commented Apr 2, 2019

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 swagger.json :

{
  "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 which is an OrderedModel and only appears in a nested field:

...
    "Simple": {
      "properties": {
        "foo": {
          "type": "string"
        }
      },
      "type": "object"
    }
...

the commits in the PR fix this

@arabidopsis
Copy link

Can confirm that I'm having this problem too and have had to monkeypatch flask_restplus
with basically this pull request.

@j5awry
Copy link
Collaborator

j5awry commented Jun 7, 2019

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.

@j5awry
Copy link
Collaborator

j5awry commented Jun 10, 2019

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.

@j5awry j5awry self-requested a review June 10, 2019 12:51
Copy link
Collaborator

@j5awry j5awry left a 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

@j5awry
Copy link
Collaborator

j5awry commented Jun 12, 2019

This also addresses some cases found in issues #643 . We should pull this in and ensure it goes out in our upcoming release

@j5awry j5awry added bug and removed Needed: Feedback Feedback needed from the author labels Jun 12, 2019
@alvarolopez
Copy link

Hi.

Any idea when this will get merged?

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

Successfully merging this pull request may close these issues.

None yet

6 participants