How to use add_schema method in pandera

Best Python code snippet using pandera_python

models.py

Source:models.py Github

copy

Full Screen

1# coding: utf-82from sqlalchemy import Column, Date, Index, String, text, ForeignKey3from sqlalchemy.dialects.mysql import BIGINT, INTEGER, LONGTEXT4from .extensions import db, ma5def add_schema(cls):6 class Schema(ma.ModelSchema):7 class Meta:8 model = cls9 cls.Schema = Schema10 return cls11@add_schema12class ActionCategory(db.Model):13 __tablename__ = 'action_category'14 __table_args__ = (15 Index('unique_action_category', 'action_id', 'category_id', unique=True),16 )17 id = Column(BIGINT(20), primary_key=True)18 action_id = Column(BIGINT(20), nullable=False)19 category_id = Column(INTEGER(11))...

Full Screen

Full Screen

openapis.py

Source:openapis.py Github

copy

Full Screen

...3with (Path(__file__).parent / "config/openapis.yml").open() as f:4 OPENAPI = yaml.safe_load(f.read())5with (Path(__file__).parent / "config/schema.yml").open() as f:6 SCHEMA = yaml.safe_load(f.read())7def add_schema(name, data=None):8 if data is None:9 data = SCHEMA[name]10 schema_keys = [11 "type",12 "format",13 "description",14 "nullable",15 "enum",16 "pattern",17 "items",18 ]19 properties = {}20 required = []21 for key, props in data.items():22 if props.get("required"):23 required.append(key)24 if "type" not in props:25 # A foreign key.26 add_schema(key, props)27 # Allow the foreign key to be null (eg. financement.organisme).28 properties[key] = {29 "allOf": [{"$ref": f"#/components/schemas/{key}"}],30 "nullable": True,31 }32 continue33 if not props.get("public"):34 continue35 properties[key] = {}36 for subkey in schema_keys:37 if subkey in props:38 value = props[subkey]39 if subkey == "enum":40 value = value.keys()41 properties[key][subkey] = value42 schema = {"properties": properties}43 if required:44 schema["required"] = required45 OPENAPI["components"]["schemas"][name] = schema46add_schema("beneficiaire")47add_schema("formation")48add_schema("financement")49add_schema("remuneration")...

Full Screen

Full Screen

responses.py

Source:responses.py Github

copy

Full Screen

2from typing import Optional, List3from marshmallow_dataclass import add_schema4from api_smart_link.entities import Base, BaseEntity5# Don't use word 'schema' in naming.6@add_schema(base_schema=Base)7@dataclass8class ResponseInternalError(BaseEntity):9 error: str = field(metadata=dict(description="Error description", example="Everything is bad"))10@add_schema(base_schema=Base)11@dataclass12class ResponseSuccess(BaseEntity):13 success: bool = field(metadata=dict(description="Success status", example=True))14 message: Optional[str] = field(metadata=dict(description="Explanatory message", example="Everything is okay"))15@add_schema(base_schema=Base)16@dataclass17class ResponseSuccessData(BaseEntity):18 data: ResponseSuccess = field()19@add_schema(base_schema=Base)20@dataclass21class ResponsePage(BaseEntity):22 id: int = field()23 content: dict = field()24@add_schema(base_schema=Base)25@dataclass26class ResponsePageData(BaseEntity):27 data: ResponsePage = field()28@add_schema(base_schema=Base)29@dataclass30class ResponsePageListData(BaseEntity):31 data: List[ResponsePage] = field()32 offset: int = field()33 limit: int = field()34 total: int = field()35@add_schema(base_schema=Base)36@dataclass37class ResponseUser(BaseEntity):38 id: int = field()39 name: str = field()40 email: str = field()41@add_schema(base_schema=Base)42@dataclass43class ResponseUserData(BaseEntity):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pandera automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful