Files
connexion/examples/methodresolver/app.py
Robbe Sneyders 073f0d446e Update examples for Connexion 3.0 (#1615)
This PR updates the examples for Connexion 3.0 and merges them for
OpenAPI and Swagger.

2 examples required some changes to make them work:
- The reverse proxy example required some fixes to the
SwaggerUIMiddleware to leverage the `root_path` correctly. This is
included in the PR.
- The enforced defaults example requires the json validator to adapt the
body and pass it on. We currently pass on the original body after
validation, and I'm not sure if we should change this. I'll submit a
separate PR to discuss this.
2022-12-30 20:34:19 +01:00

44 lines
1.0 KiB
Python
Executable File

import logging
from pathlib import Path
import connexion
from connexion.resolver import MethodViewResolver
logging.basicConfig(level=logging.INFO)
zoo = {
1: {
"id": 1,
"name": "giraffe",
"tags": ["africa", "yellow", "hoofs", "herbivore", "long neck"],
},
2: {
"id": 2,
"name": "lion",
"tags": ["africa", "yellow", "paws", "carnivore", "mane"],
},
}
app = connexion.FlaskApp(__name__, specification_dir="spec/", debug=True)
options = {"swagger_ui": True}
app.add_api(
"openapi.yaml",
options=options,
arguments={"title": "MethodViewResolver Example"},
resolver=MethodViewResolver(
"api",
# class params are entirely optional
# they allow to inject dependencies top down
# so that the app can be wired, in the entrypoint
class_arguments={"PetsView": {"kwargs": {"pets": zoo}}},
),
strict_validation=True,
validate_responses=True,
)
if __name__ == "__main__":
app.run(f"{Path(__file__).stem}:app", port=8080)