forked from loafle/openapi-generator-original
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
#!/usr/bin/env python
|
|
|
|
import connexion
|
|
from connexion.decorators import produces
|
|
from six import iteritems
|
|
from models.base_model_ import Model
|
|
|
|
|
|
class JSONEncoder(produces.JSONEncoder):
|
|
include_nulls = False
|
|
|
|
def default(self, o):
|
|
if isinstance(o, Model):
|
|
dikt = {}
|
|
for attr, _ in iteritems(o.swagger_types):
|
|
value = getattr(o, attr)
|
|
if value is None and not self.include_nulls:
|
|
continue
|
|
attr = o.attribute_map[attr]
|
|
dikt[attr] = value
|
|
return dikt
|
|
return produces.JSONEncoder.default(self, o)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app = connexion.App(__name__, specification_dir='./swagger/')
|
|
app.app.json_encoder = JSONEncoder
|
|
app.add_api('swagger.yaml', arguments={'title': 'This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.'})
|
|
app.run(port=8080)
|