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

Typecasting? #104

Closed
kleijnweb opened this issue Dec 4, 2015 · 12 comments
Closed

Typecasting? #104

kleijnweb opened this issue Dec 4, 2015 · 12 comments
Assignees

Comments

@kleijnweb
Copy link
Contributor

connexxion seems to pass Swagger integers as unicode strings. At least a note in the docs would be a start.

@hjacobs
Copy link
Contributor

hjacobs commented Dec 5, 2015

Depends on what you mean, type casting "partly" works, see e.g. https://github.com/hjacobs/connexion-example

Can you describe your situation / use case where it fails?

@kleijnweb
Copy link
Contributor Author

To reproduce:

swagger.yml:

swagger: '2.0'
host: localhost
paths:
  '/foo/{id}':
    get:
      operationId: api.get
      parameters:
        - in: path
          name: id
          type: integer
          format: int64

api.py:

#!/usr/bin/env python2.7
import connexion

def get(id):
    return str(type(id))

app = connexion.App(__name__)
app.add_api('swagger.yml')
application = app.app

if __name__ == '__main__':
    app.run(port=8080)
http http://localhost:8080/foo/1

Actual:

HTTP/1.0 200 OK
Content-Length: 18
Content-Type: application/json
Date: Sat, 05 Dec 2015 17:53:49 GMT
Server: Werkzeug/0.11.2 Python/2.7.6

"<type 'unicode'>"

Expected:

HTTP/1.0 200 OK
Content-Length: 18
Content-Type: application/json
Date: Sat, 05 Dec 2015 17:53:49 GMT
Server: Werkzeug/0.11.2 Python/2.7.6

"<type 'int'>"

@kleijnweb
Copy link
Contributor Author

Sidenote, this also works ("<type 'unicode'>"):

swagger: '2.0'
host: localhost
paths:
  '/foo/{id}':
    get:
      operationId: api.get
      parameters:
        - in: path
          name: id
          type: fantasia

It would be nice if connexion was a little more defensive, this way typos can lead to hard to track bugs.

@hjacobs
Copy link
Contributor

hjacobs commented Dec 5, 2015

True, that's a missing feature: Flask route converters should be supported http://flask.pocoo.org/docs/0.10/api/#url-route-registrations

@kleijnweb
Copy link
Contributor Author

In the mean time, a small note in the README might save new users some time. I myself was baffled when a pymongo.find_one() operation did not yield any results because the argument was not an integer. Naive, perhaps, but still.

@hjacobs
Copy link
Contributor

hjacobs commented Dec 5, 2015

@kleijnweb my personal recommendation (off topic): stay away from MongoDB 😏 (we replaced a 5 node MongoDB cluster with a single node PostgreSQL 🐘)

@hjacobs
Copy link
Contributor

hjacobs commented Dec 5, 2015

In general we need more documentation and tutorials for Connexion...

@kleijnweb
Copy link
Contributor Author

It's only a dummy backend for an AngularJS app, so yeah, not worried about that.

Far as docs go, a simple example in the README with a note about how the arguments are passed (including type coercion -- or lack thereof) would go long way.

@hjacobs
Copy link
Contributor

hjacobs commented Dec 5, 2015

@kleijnweb you can check my pull request #105 which adds type casting for int and float path parameters using Flask path converters

@hjacobs hjacobs self-assigned this Dec 5, 2015
@hjacobs
Copy link
Contributor

hjacobs commented Dec 8, 2015

changes now released in https://github.com/zalando/connexion/releases/tag/1.0.25

@kleijnweb
Copy link
Contributor Author

@hjacobs What about arrays/dicts? Difficult?

@hjacobs
Copy link
Contributor

hjacobs commented Dec 10, 2015

@kleijnweb Flask supports custom "converts" in the path, so I don't think it's difficult --- I'm not sure what the semantics are for other types in "path" parameters (need to check Swagger spec)

rafaelcaricio added a commit to rafaelcaricio/connexion that referenced this issue Mar 4, 2016
rafaelcaricio added a commit to rafaelcaricio/connexion that referenced this issue Mar 4, 2016
@jmcs jmcs assigned rafaelcaricio and unassigned hjacobs Mar 4, 2016
@jmcs jmcs closed this as completed in #172 Mar 7, 2016
@jmcs jmcs removed the in progress label Mar 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants