mirror of
https://github.com/LukeHagar/connexion.git
synced 2025-12-06 20:37:47 +00:00
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.
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
from sqlalchemy import Column, DateTime, String, create_engine
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import scoped_session, sessionmaker
|
|
|
|
Base = declarative_base()
|
|
|
|
|
|
class Pet(Base):
|
|
__tablename__ = "pets"
|
|
id = Column(String(20), primary_key=True)
|
|
name = Column(String(100))
|
|
animal_type = Column(String(20))
|
|
created = Column(DateTime())
|
|
|
|
def update(self, id=None, name=None, animal_type=None, tags=None, created=None):
|
|
if name is not None:
|
|
self.name = name
|
|
if animal_type is not None:
|
|
self.animal_type = animal_type
|
|
if created is not None:
|
|
self.created = created
|
|
|
|
def dump(self):
|
|
return {k: v for k, v in vars(self).items() if not k.startswith("_")}
|
|
|
|
|
|
def init_db(uri):
|
|
engine = create_engine(uri, convert_unicode=True)
|
|
db_session = scoped_session(
|
|
sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
)
|
|
Base.query = db_session.query_property()
|
|
Base.metadata.create_all(bind=engine)
|
|
return db_session
|