Convert OpenAPI 3 & Swagger specs (YAML/JSON) to Python Pydantic models
Generate clean Python Pydantic v1 and v2 BaseModel classes directly from OpenAPI 3.x and Swagger 2.0 specifications in YAML or JSON. Supports type hints, optional nulls, field aliases, and enum types.
Keywords: openapi, swagger, pydantic, python, fastapi, pydantic v2, baseModel, types
Tags: openapi, swagger, pydantic, python, fastapi, codegen, api, schemas
OpenAPI to Pydantic is also known as: swagger to pydantic, openapi to python, openapi to pydantic v2, swagger to pydantic models, openapi pydantic generator.
Paste your OpenAPI 3.x or Swagger 2.0 specification in YAML or JSON format into the editor.
Select your target Pydantic version: Pydantic v2 (recommended for modern FastAPI) or Pydantic v1.
Toggle Field Aliases if your API spec uses camelCase or kebab-case keys that should map to Python snake_case attributes.
Optionally set a class name prefix (e.g., Api) to namespace generated models.
Copy the generated Python code or download models.py directly for use in your FastAPI, Celery, or Django projects.
Full OpenAPI 3.x & Swagger 2.0 Support: Seamlessly parses components.schemas and legacy definitions blocks in both YAML and JSON.
Pydantic v2 & v1 Native: Generates modern BaseModel classes with ConfigDict, model_config, and Field validation.
Automatic Pythonic Naming: Converts camelCase and hyphenated properties to PEP 8 snake_case with Field(alias="...") mapping.
Nested Object & Array Handling: Automatically extracts inline schemas into clean referenced child models.
Type Hints & Nullability: Accurately maps JSON Schema types to Python typing: str, int, float, bool, List[T], Dict[str, Any], and Optional[T].
Zero Telemetry Guarantee: Conversion runs 100% in your browser using client-side JavaScript. Private internal API contracts are never uploaded.
Chain OpenAPI to Pydantic with other utilities in a multi-step visual workflow.
Decode a Base64 string and pretty-print the JSON inside it.
Convert CSV data to JSON, then to YAML format.
Format JSON and generate TypeScript/Zod schema from it.
Convert OpenAPI 3 & Swagger specs (YAML/JSON) to Python Pydantic models
from __future__ import annotations
from typing import Optional
from pydantic import BaseModel, Field, ConfigDict
from datetime import datetime
class Pet(BaseModel):
id: float
name: str
tag: Optional[str] = None
status: Optional[str] = None
model_config = ConfigDict(populate_by_name=True)
class Order(BaseModel):
id: float
pet_id: float = Field(alias="petId")
quantity: Optional[float] = None
ship_date: Optional[datetime] = Field(default=None, alias="shipDate")
complete: Optional[bool] = None
model_config = ConfigDict(populate_by_name=True)