Skip to content

Commit bbf0f92

Browse files
committed
add static sink
1 parent 6ed8e62 commit bbf0f92

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Overview
66

7-
Generate Flask/Tornado-RESTful/Falcon application code from a Swagger Specification doc.
7+
Generate Flask/Tornado/Falcon-RESTful application code from a Swagger Specification doc.
88

99
**Alpha version for now, it can not handle all validation properly.**
1010

@@ -88,7 +88,7 @@ Generate example-app from [apis.yml](https://github.com/guokr/swagger-py-codegen
8888
| |__ validators.py
8989
|__ requirements.txt
9090

91-
$ swagger_py_codegen -s api.yml example-app -p demo
91+
$ swagger_py_codegen -s api.yml example-app -p demo -tlp=falcon
9292
$ tree (falcon-demo)
9393
.
9494
|__ api.yml

swagger_py_codegen/templates/falcon/app.tpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, print_function
33

4+
import os
5+
import mimetypes
6+
47
import falcon
58
from wsgiref import simple_server
69

@@ -17,6 +20,17 @@ class NotFoundError(object):
1720
description)
1821

1922

23+
class StaticAdapter(object):
24+
25+
def __call__(self, req, resp, filename):
26+
file_path = os.path.join(os.path.dirname(__file__), "static/%s" % filename)
27+
file_type = mimetypes.guess_type(file_path)[0]
28+
resp.status = falcon.HTTP_200
29+
resp.content_type = file_type
30+
with open(file_path, 'r') as f:
31+
resp.body = f.read()
32+
33+
2034
def http_error_serializer(req, resp, exception):
2135
representation = None
2236
preferred = req.client_prefers(('application/x-yaml',
@@ -46,6 +60,8 @@ def register_routes(app):
4660
url = '{prefix}{base_url}'.format(prefix='{{base_path}}',
4761
base_url=route.pop('url'))
4862
app.add_route(url, route.pop('resource'))
63+
static = StaticAdapter()
64+
app.add_sink(static, r'/static/(?P<filename>.*)')
4965

5066

5167
if __name__ == '__main__':

0 commit comments

Comments
 (0)