diff --git a/examples/pserve_ini_app/app.py b/examples/pserve_ini_app/app.py new file mode 100644 index 0000000..e007220 --- /dev/null +++ b/examples/pserve_ini_app/app.py @@ -0,0 +1,42 @@ +import os +import sys + +from pyramid.config import Configurator +from pyramid.request import Request +from pyramid.scripts.pserve import main +from pyramid.view import view_config + +APP_FOLDER = os.path.dirname(__file__) + + +@view_config(route_name="version", renderer="json", request_method="GET", openapi=True) +def get(request: Request): + """Get the app's version.""" + return {"Version": "0.0.1"} + + +def wsgi_app(global_config, **settings): + """Prepare a Pyramid app.""" + with Configurator() as config: + config.include("pyramid_openapi3") + config.pyramid_openapi3_spec( + os.path.join(APP_FOLDER, "openapi.yaml") + ) + config.pyramid_openapi3_add_explorer() + config.add_route("version", "/version") + config.scan(".") + + return config.make_wsgi_app() + + +if __name__ == '__main__': + # The normal way of starting an app would be `pserve server.ini` + # we replicate this here by adding a sys.argv + + # normally you'd have an egg or a proper package, but this app is simpler. + # This way can only work when the working directory is the same as where app.py is + # because of the hardcoded app:wsgi_app in server.ini + os.chdir(APP_FOLDER) + config_file = os.path.join(APP_FOLDER, 'server.ini') + sys.argv.append(config_file) + sys.exit(main()) diff --git a/examples/pserve_ini_app/openapi.yaml b/examples/pserve_ini_app/openapi.yaml new file mode 100644 index 0000000..41de942 --- /dev/null +++ b/examples/pserve_ini_app/openapi.yaml @@ -0,0 +1,37 @@ +openapi: "3.0.0" + +servers: + - url: '/v' + +info: + version: "1.0.0" + title: A simple Todo app API + +paths: + /version: + get: + summary: version + description: version + tags: + - version + responses: + "200": + description: version + content: + application/json: + schema: + $ref: "#/components/schemas/Item" + + +components: + + schemas: + + Item: + type: object + required: + - title + properties: + title: + type: string + maxLength: 40 diff --git a/examples/pserve_ini_app/server.ini b/examples/pserve_ini_app/server.ini new file mode 100644 index 0000000..7de8515 --- /dev/null +++ b/examples/pserve_ini_app/server.ini @@ -0,0 +1,20 @@ +###### +# app configuration +# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html +###### +[app:test-app] +paste.app_factory = app:wsgi_app + +[filter:paste_prefix] +use = egg:PasteDeploy#prefix +prefix = /v + +[pipeline:main] +pipeline = + paste_prefix + test-app + +[server:main] +use = egg:waitress#main +host = 0.0.0.0 +port = 6543