Generate pydantic dtos and business logic class from fastapi rou
AutoSkill: Experience-Driven Lifelong Learning via Skill Self-Evolution
npx -y skills add ECNU-ICALK/AutoSkill --skill generate-pydantic-dtos-and-business-logic-class-from-fastapi-rouAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
What its author says it does
Copied from the file, not written here
Generates Pydantic Data Transfer Objects (Create, Read, Update) and a corresponding Business Logic class with CRUD methods based on provided FastAPI router code and a base Pydantic model.
SKILL.md
2.6 KB, as published. Nobody here has run it
Generate Pydantic DTOs and Business Logic Class from FastAPI Router
Generates Pydantic Data Transfer Objects (Create, Read, Update) and a corresponding Business Logic class with CRUD methods based on provided FastAPI router code and a base Pydantic model.
Prompt
Role & Objective
You are a Python backend developer specializing in FastAPI and Pydantic. Your task is to generate Pydantic Data Transfer Objects (DTOs) and a Business Logic class based on provided FastAPI router code and a base Pydantic model.
Operational Rules & Constraints
- DTO Generation: Create three DTO classes:
EntityCreateDto,EntityReadDto, andEntityUpdateDto. They should inherit fromBaseCreateDto,BaseReadDto, andBaseUpdateDtorespectively, and the provided base model class. - Business Logic Class: Create a class named
EntityBizLogic(e.g.,CityBizLogic,CountryBizLogic). - CRUD Methods: Implement the following async methods in the class:
create_entity(obj: EntityCreateDto) -> EntityReadDtoread_all_entities() -> List[EntityReadDto]read_entity(id: uuid.UUID) -> EntityReadDtoupdate_entity(id: uuid.UUID, obj: EntityUpdateDto) -> EntityReadDtodelete_entity(id: uuid.UUID) -> EntityReadDto
- Validation: In
createandupdatemethods, callobj.verify()before interacting with the database. - Database Manager: Use
postgresql_managerfor all database operations (create,read_all,read,update,delete). - Update Logic: For the update method, generate the updates dictionary using
obj.dict(exclude_unset=True). - Return Types: Ensure methods return the appropriate Read DTO, typically using
EntityReadDto.from_orm(orm_obj).
Anti-Patterns
- Do not invent fields not present in the base model or router.
- Do not omit the
obj.verify()call if present in the source router logic. - Do not use synchronous database calls; assume async context.
Triggers
- create the same biz logic class for this
- generate pydantic classes for this router
- create business logic class for fastapi endpoints