Skip to content
OpenSmartRoute
Skillv1.0.0

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.

by lzy18001500226(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from lzy18001500226/MoSim (References/Agent/Skills/AutoSkill/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/generate-pydantic-dtos-and-business-logic-class-from-fastapi-rou/SKILL.md). Install upstream with npx skills add lzy18001500226/MoSim --skill generate-pydantic-dtos-and-business-logic-class-from-fastapi-rou. Copyright stays with the author.

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

  1. DTO Generation: Create three DTO classes: EntityCreateDto, EntityReadDto, and EntityUpdateDto. They should inherit from BaseCreateDto, BaseReadDto, and BaseUpdateDto respectively, and the provided base model class.
  2. Business Logic Class: Create a class named EntityBizLogic (e.g., CityBizLogic, CountryBizLogic).
  3. CRUD Methods: Implement the following async methods in the class:
    • create_entity(obj: EntityCreateDto) -> EntityReadDto
    • read_all_entities() -> List[EntityReadDto]
    • read_entity(id: uuid.UUID) -> EntityReadDto
    • update_entity(id: uuid.UUID, obj: EntityUpdateDto) -> EntityReadDto
    • delete_entity(id: uuid.UUID) -> EntityReadDto
  4. Validation: In create and update methods, call obj.verify() before interacting with the database.
  5. Database Manager: Use postgresql_manager for all database operations (create, read_all, read, update, delete).
  6. Update Logic: For the update method, generate the updates dictionary using obj.dict(exclude_unset=True).
  7. 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

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/lzy18001500226-mosim-generate-pydantic-dtos-and-business-e48d9a/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

lzy18001500226-mosim-generate-pydantic-dtos-and-business-e48d9a.ocm.jsonjson
{
  "ocm": "1",
  "id": "lzy18001500226-mosim-generate-pydantic-dtos-and-business-e48d9a",
  "kind": "skill",
  "name": "Generate Pydantic DTOs and Business Logic Class from FastAPI Router",
  "description": "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.",
  "publisher": "lzy18001500226",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding"
    ],
    "tags": [
      "skill-md",
      "fastapi",
      "pydantic",
      "business-logic",
      "code-generation",
      "crud",
      "github"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "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."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "github",
      "repository": "https://github.com/lzy18001500226/MoSim",
      "path": "References/Agent/Skills/AutoSkill/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/generate-pydantic-dtos-and-business-logic-class-from-fastapi-rou/SKILL.md",
      "ref": "e0ec177d00f087cb04e90206b2f7d3aa2f5a1350",
      "url": "https://github.com/lzy18001500226/MoSim/blob/e0ec177d00f087cb04e90206b2f7d3aa2f5a1350/References/Agent/Skills/AutoSkill/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/generate-pydantic-dtos-and-business-logic-class-from-fastapi-rou/SKILL.md",
      "key": "lzy18001500226/MoSim/References/Agent/Skills/AutoSkill/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/generate-pydantic-dtos-and-business-logic-class-from-fastapi-rou/SKILL.md"
    }
  },
  "instructions": "# Generate Pydantic DTOs and Business Logic Class from FastAPI Router\n\nGenerates 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.\n\n## Prompt\n\n# Role & Objective\nYou 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.\n\n# Operational Rules & Constraints\n1. **DTO Generation**: Create three DTO classes",
  "cost": {
    "context_tokens": 526
  }
}

Fetch it by URL: GET /api/v1/registry/lzy18001500226-mosim-generate-pydantic-dtos-and-business-e48d9a/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.