datamodel-code-generator
Version updated for https://github.com/koxudaxi/datamodel-code-generator to version 0.73.0.
- This action is used across all versions by 3,464 repositories.
Action Type
This is a Composite action.
Go to the GitHub Marketplace to find the latest changes.
Action Summary
The datamodel-code-generator GitHub Action automates the process of generating Python data models from various schema formats, including OpenAPI 3, AsyncAPI, JSON Schema, Apache Avro, XML Schema, Protocol Buffers/gRPC, GraphQL, and MCP tool schemas. It can also convert existing Python types (Pydantic, dataclass, TypedDict) to different output types and supports Pydantic v2 and multiple model styles such as Pydantic v2 dataclass, dataclasses, TypedDict, or msgspec. The action handles complex schemas with features like $ref, allOf, oneOf, anyOf, enums, and nested types, ensuring type-safe, validated code output for development environments and type checkers.
What’s Changed
Breaking Changes
Error Handling Changes
- Additional imports are now validated as Python import paths - Values passed via
--additional-imports, the Python config API (GenerateConfig,JSONSchemaParserConfig, etc.), or--extra-template-datamust now be dotted sequences of Python identifiers. Previously any value was accepted and split on commas without validation; now inputs that are not valid import paths (e.g. containing newlines, semicolons, or non-identifier syntax) raise anErrorand abort generation instead of being emitted into the generated output. Valid dotted paths (optionally whitespace-padded) continue to work unchanged. (#3763)
additional_imports must be a Python import path composed of identifiers: 'collections.deque\nINJECTION_MARKER = 1'
Default Behavior Changes
- Reserved template keys in
--extra-template-datanow raise an error for built-in templates - When rendering a built-in (project-owned) template, supplying any generator-reserved key through--extra-template-data(or theextra_template_dataAPI argument) now raises anErrorand aborts generation instead of injecting the value. The reserved keys areclass_body_lines,config_items,schema_runtime_validation,schema_runtime_validation_base_class_name,schema_runtime_validation_use_base,sequence_base_class,sequence_item_type,sequence_slice_type,_safe_config_items,typed_dict_kwargs, andtyped_dict_kwargs_suffix. To inject raw code via these keys you must now use a custom root template through--custom-template-dir. (#3765) - Stricter
extra_template_datavalidation -extra_template_datathat is not a dictionary, contains non-string keys, or contains duplicate (normalized) keys now raises anErrorrather than being silently accepted. (#3765)
Code Generation Changes
- Built-in templates now serialize
extra_template_datavalues as non-executing literals - For built-in templates, user-supplied values that were previously emitted as raw Python source are now serialized as quoted, non-executing literals. This affects GraphQL scalarpy_type, TypedDictadditionalPropertiesType,ConfigDictvalues, msgspecbase_class_kwargs, and comments. Only bare or dotted identifiers (e.g.datetime.date) are still emitted unquoted; more complex expressions become string literals. For example, a scalarpy_typesupplied as a type expression is now rendered as:
Evil = TypeAliasType("Evil", "__import__('os').system('id') or str")
Trusted custom root templates (--custom-template-dir providing the root template) keep the previous unrestricted raw behavior. (#3765)
- Include-only custom template directories no longer receive raw built-in context - “Custom root” detection changed from
template_file_path.is_absolute()to_uses_custom_root_template. A--custom-template-dirthat only supplies include/partial templates (not the model’s root template) no longer opts the built-in root into the unrestricted raw-context path; itsextra_template_datais now treated with the hardened built-in rules (and reserved keys raise an error). (#3765)
What’s Changed
- Update CHANGELOG for 0.72.4 by @dcg-generated-docs[bot] in https://github.com/koxudaxi/datamodel-code-generator/pull/3736
- Update release benchmark data by @dcg-generated-docs[bot] in https://github.com/koxudaxi/datamodel-code-generator/pull/3737
- Guard refactor contracts by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3739
- Tighten generation types by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3740
- Simplify generation dispatch by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3741
- Simplify parser metadata flow by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3742
- Optimize built-in generation performance by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3738
- Optimize simple field construction by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3754
- Optimize msgspec unset field rendering by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3755
- Optimize false reference handling by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3750
- Compile built-in templates by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3757
- Optimize Pydantic field name resolution by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3758
- Avoid Jinja in the playground runtime by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3759
- Fix main lint workflow by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3761
- Bump the github-actions group with 5 updates by @dependabot[bot] in https://github.com/koxudaxi/datamodel-code-generator/pull/3751
- Fix payload runtime validation exclusions by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3764
- Validate additional import paths by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3763
- Harden built-in template data by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3765
- Restrict template source paths by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/3766
Full Changelog: https://github.com/koxudaxi/datamodel-code-generator/compare/0.72.4...0.73.0