📚 Supported Input Formats¶
This code generator supports the following input formats:
- OpenAPI 3.0/3.1/3.2 (YAML/JSON, OpenAPI Data Types); OpenAPI 2.0 (Swagger) has limited support.
- AsyncAPI 2.x/3.x (YAML/JSON).
- JSON Schema (JSON Schema Core / JSON Schema Validation).
- Apache Avro schema (
.avsc, Apache Avro). - XML Schema (XSD).
- Protocol Buffers / gRPC (
.proto, Protocol Buffers / gRPC). - GraphQL schema (GraphQL Schemas and Types).
- MCP tool schemas (
--input-file-type mcp-tools, MCP Tool Schemas). - JSON / YAML / CSV data (converted to JSON Schema before model generation).
- Python dictionary (converted to JSON Schema before model generation).
- Existing Python types via
--input-model: Pydantic models, dataclasses, Pydantic dataclasses, TypedDict, and dict schemas.
Use --input-file-type auto (the default) for common files, or set an explicit
type when a file extension is ambiguous. For example, YAML can contain either an
OpenAPI/JSON Schema document or raw sample data, so use jsonschema, openapi,
or yaml depending on the intended input.
📘 OpenAPI 3 and JSON Schema¶
Below are the data types and features recognized by datamodel-code-generator for OpenAPI 3 and JSON Schema.
✅ Implemented data types and features¶
📊 Data Types¶
- string (supported keywords: pattern/minLength/maxLength)
- number (supported keywords: maximum/exclusiveMaximum/minimum/exclusiveMinimum/multipleOf)
- integer (supported keywords: maximum/exclusiveMaximum/minimum/exclusiveMinimum/multipleOf)
- boolean
- array
- object
📝 String Formats¶
- date
- datetime
- time
- password
- email (requires
email-validator) - idn-email (requires
email-validator) - idn-hostname
- path
- uuid (uuid1/uuid2/uuid3/uuid4/uuid5)
- ulid (requires
python-ulid) - ipv4
- ipv4-network
- ipv6
- ipv6-network
- hostname
- decimal
- uri
- uri-reference
- uri-template
- iri
- iri-reference
- json-pointer
- relative-json-pointer
- regex
🔗 Other schema¶
- enum (as enum.Enum or typing.Literal)
- allOf (as Multiple inheritance)
- anyOf (as typing.Union)
- oneOf (as typing.Union)
- $ref (http extra is required when resolving $ref for remote files.)
- $id (for JSONSchema)