datamodel-code-generator 0.25.9__tar.gz → 0.26.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of datamodel-code-generator might be problematic. Click here for more details.
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/PKG-INFO +71 -73
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/README.md +69 -70
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/__init__.py +13 -8
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/__main__.py +5 -1
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/arguments.py +9 -3
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/format.py +3 -1
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/imports.py +2 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/pydantic/types.py +5 -1
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/pydantic_v2/__init__.py +2 -1
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/pydantic_v2/base_model.py +14 -18
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/pydantic_v2/root_model.py +1 -4
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/pydantic_v2/BaseModel.jinja2 +1 -1
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/types.py +7 -2
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/parser/base.py +7 -4
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/parser/graphql.py +29 -17
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/parser/jsonschema.py +9 -3
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/parser/openapi.py +3 -1
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/pydantic_patch.py +2 -1
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/types.py +3 -2
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/util.py +12 -31
- datamodel_code_generator-0.26.1/datamodel_code_generator/version.py +1 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/pyproject.toml +5 -4
- datamodel_code_generator-0.25.9/datamodel_code_generator/version.py +0 -1
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/LICENSE +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/http.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/__init__.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/base.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/dataclass.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/enum.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/imports.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/msgspec.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/pydantic/__init__.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/pydantic/base_model.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/pydantic/custom_root_type.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/pydantic/dataclass.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/pydantic/imports.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/pydantic_v2/imports.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/pydantic_v2/types.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/rootmodel.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/scalar.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/Enum.jinja2 +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/Scalar.jinja2 +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/TypedDict.jinja2 +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/TypedDictClass.jinja2 +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/TypedDictFunction.jinja2 +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/Union.jinja2 +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/dataclass.jinja2 +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/msgspec.jinja2 +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/pydantic/BaseModel.jinja2 +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/pydantic/BaseModel_root.jinja2 +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/pydantic/Config.jinja2 +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/pydantic/dataclass.jinja2 +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/pydantic_v2/ConfigDict.jinja2 +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/pydantic_v2/RootModel.jinja2 +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/template/root.jinja2 +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/typed_dict.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/model/union.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/parser/__init__.py +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/py.typed +0 -0
- {datamodel_code_generator-0.25.9 → datamodel_code_generator-0.26.1}/datamodel_code_generator/reference.py +0 -0
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: datamodel-code-generator
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.26.1
|
|
4
4
|
Summary: Datamodel Code Generator
|
|
5
5
|
Home-page: https://github.com/koxudaxi/datamodel-code-generator
|
|
6
6
|
License: MIT
|
|
7
7
|
Author: Koudai Aono
|
|
8
8
|
Author-email: koxudaxi@gmail.com
|
|
9
|
-
Requires-Python: >=3.
|
|
9
|
+
Requires-Python: >=3.8,<4.0
|
|
10
10
|
Classifier: Development Status :: 4 - Beta
|
|
11
11
|
Classifier: License :: OSI Approved :: MIT License
|
|
12
12
|
Classifier: Natural Language :: English
|
|
13
13
|
Classifier: Programming Language :: Python :: 3
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.8
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.9
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.10
|
|
@@ -386,61 +385,64 @@ This method needs the [http extra option](#http-extra-option)
|
|
|
386
385
|
|
|
387
386
|
The `datamodel-codegen` command:
|
|
388
387
|
|
|
388
|
+
<!-- start command help -->
|
|
389
389
|
```bash
|
|
390
|
-
usage:
|
|
390
|
+
usage:
|
|
391
391
|
datamodel-codegen [options]
|
|
392
392
|
|
|
393
393
|
Generate Python data models from schema definitions or structured data
|
|
394
394
|
|
|
395
395
|
Options:
|
|
396
|
+
--additional-imports ADDITIONAL_IMPORTS
|
|
397
|
+
Custom imports for output (delimited list input). For example
|
|
398
|
+
"datetime.date,datetime.datetime"
|
|
399
|
+
--custom-formatters CUSTOM_FORMATTERS
|
|
400
|
+
List of modules with custom formatter (delimited list input).
|
|
396
401
|
--http-headers HTTP_HEADER [HTTP_HEADER ...]
|
|
397
|
-
Set headers in HTTP requests to the remote host.
|
|
398
|
-
|
|
399
|
-
--http-ignore-tls Disable verification of the remote host''s TLS
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
(example: "ref=branch")
|
|
402
|
+
Set headers in HTTP requests to the remote host. (example:
|
|
403
|
+
"Authorization: Basic dXNlcjpwYXNz")
|
|
404
|
+
--http-ignore-tls Disable verification of the remote host''s TLS certificate
|
|
405
|
+
--http-query-parameters HTTP_QUERY_PARAMETERS [HTTP_QUERY_PARAMETERS ...]
|
|
406
|
+
Set query parameters in HTTP requests to the remote host. (example:
|
|
407
|
+
"ref=branch")
|
|
404
408
|
--input INPUT Input file/directory (default: stdin)
|
|
405
|
-
--input-file-type {auto,openapi,
|
|
409
|
+
--input-file-type {auto,openapi,jsonschema,json,yaml,dict,csv,graphql}
|
|
406
410
|
Input file type (default: auto)
|
|
407
411
|
--output OUTPUT Output file (default: stdout)
|
|
408
412
|
--output-model-type {pydantic.BaseModel,pydantic_v2.BaseModel,dataclasses.dataclass,typing.TypedDict,msgspec.Struct}
|
|
409
|
-
|
|
410
|
-
|
|
413
|
+
Output model type (default: pydantic.BaseModel)
|
|
414
|
+
--url URL Input file URL. `--input` is ignored when `--url` is used
|
|
411
415
|
|
|
412
416
|
Typing customization:
|
|
413
417
|
--base-class BASE_CLASS
|
|
414
418
|
Base Class (default: pydantic.BaseModel)
|
|
415
419
|
--enum-field-as-literal {all,one}
|
|
416
|
-
Parse enum field as literal. all: all enum field type
|
|
417
|
-
|
|
418
|
-
has only one possible value
|
|
420
|
+
Parse enum field as literal. all: all enum field type are Literal.
|
|
421
|
+
one: field type is Literal when an enum has only one possible value
|
|
419
422
|
--field-constraints Use field constraints and not con* annotations
|
|
420
423
|
--set-default-enum-member
|
|
421
424
|
Set enum members as default values for enum field
|
|
422
425
|
--strict-types {str,bytes,int,float,bool} [{str,bytes,int,float,bool} ...]
|
|
423
426
|
Use strict types
|
|
424
|
-
--use-annotated Use typing.Annotated for Field(). Also, `--field-
|
|
425
|
-
|
|
427
|
+
--use-annotated Use typing.Annotated for Field(). Also, `--field-constraints` option
|
|
428
|
+
will be enabled.
|
|
426
429
|
--use-generic-container-types
|
|
427
|
-
Use generic container types for type hinting
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
collections.abc instead of typing
|
|
430
|
+
Use generic container types for type hinting (typing.Sequence,
|
|
431
|
+
typing.Mapping). If `--use-standard-collections` option is set, then
|
|
432
|
+
import from collections.abc instead of typing
|
|
431
433
|
--use-non-positive-negative-number-constrained-types
|
|
432
|
-
Use the Non{Positive,Negative}{FloatInt} types instead
|
|
433
|
-
|
|
434
|
+
Use the Non{Positive,Negative}{FloatInt} types instead of the
|
|
435
|
+
corresponding con* constrained types.
|
|
434
436
|
--use-one-literal-as-default
|
|
435
437
|
Use one literal as default value for one literal field
|
|
436
438
|
--use-standard-collections
|
|
437
439
|
Use standard collections for type hinting (list, dict)
|
|
438
|
-
--use-subclass-enum Define Enum class as subclass with field type when
|
|
439
|
-
|
|
440
|
+
--use-subclass-enum Define Enum class as subclass with field type when enum has type
|
|
441
|
+
(int, float, bytes, str)
|
|
440
442
|
--use-union-operator Use | operator for Union type (PEP 604).
|
|
441
443
|
--use-unique-items-as-set
|
|
442
|
-
define field type as `set` when the field attribute
|
|
443
|
-
|
|
444
|
+
define field type as `set` when the field attribute has
|
|
445
|
+
`uniqueItems`
|
|
444
446
|
|
|
445
447
|
Field customization:
|
|
446
448
|
--capitalise-enum-members, --capitalize-enum-members
|
|
@@ -450,61 +452,60 @@ Field customization:
|
|
|
450
452
|
--field-extra-keys FIELD_EXTRA_KEYS [FIELD_EXTRA_KEYS ...]
|
|
451
453
|
Add extra keys to field parameters
|
|
452
454
|
--field-extra-keys-without-x-prefix FIELD_EXTRA_KEYS_WITHOUT_X_PREFIX [FIELD_EXTRA_KEYS_WITHOUT_X_PREFIX ...]
|
|
453
|
-
Add extra keys with `x-` prefix to field parameters.
|
|
454
|
-
|
|
455
|
+
Add extra keys with `x-` prefix to field parameters. The extra keys
|
|
456
|
+
are stripped of the `x-` prefix.
|
|
455
457
|
--field-include-all-keys
|
|
456
458
|
Add all keys to field parameters
|
|
457
459
|
--force-optional Force optional for required fields
|
|
458
460
|
--original-field-name-delimiter ORIGINAL_FIELD_NAME_DELIMITER
|
|
459
|
-
Set delimiter to convert to snake case. This option
|
|
460
|
-
|
|
461
|
-
)
|
|
461
|
+
Set delimiter to convert to snake case. This option only can be used
|
|
462
|
+
with --snake-case-field (default: `_` )
|
|
462
463
|
--remove-special-field-name-prefix
|
|
463
|
-
Remove field name prefix if it has a special meaning
|
|
464
|
-
|
|
464
|
+
Remove field name prefix if it has a special meaning e.g.
|
|
465
|
+
underscores
|
|
465
466
|
--snake-case-field Change camel-case field name to snake-case
|
|
466
467
|
--special-field-name-prefix SPECIAL_FIELD_NAME_PREFIX
|
|
467
|
-
Set field name prefix when first character can''t be
|
|
468
|
-
|
|
468
|
+
Set field name prefix when first character can''t be used as Python
|
|
469
|
+
field name (default: `field`)
|
|
469
470
|
--strip-default-none Strip default None on fields
|
|
471
|
+
--union-mode {smart,left_to_right}
|
|
472
|
+
Union mode for only pydantic v2 field
|
|
470
473
|
--use-default Use default value even if a field is required
|
|
471
|
-
--use-default-kwarg Use `default=` instead of a positional argument for
|
|
472
|
-
|
|
474
|
+
--use-default-kwarg Use `default=` instead of a positional argument for Fields that have
|
|
475
|
+
default values.
|
|
473
476
|
--use-field-description
|
|
474
477
|
Use schema description to populate field docstring
|
|
475
|
-
--use-pendulum
|
|
476
|
-
Use pendulum instead of `datetime` for `date`,
|
|
477
|
-
`datetime`, and `time` data types
|
|
478
478
|
|
|
479
479
|
Model customization:
|
|
480
|
-
--allow-extra-fields Allow to pass extra fields, if this flag is not
|
|
481
|
-
|
|
480
|
+
--allow-extra-fields Allow to pass extra fields, if this flag is not passed, extra fields
|
|
481
|
+
are forbidden.
|
|
482
482
|
--allow-population-by-field-name
|
|
483
483
|
Allow population by field name
|
|
484
484
|
--class-name CLASS_NAME
|
|
485
485
|
Set class name of root model
|
|
486
486
|
--collapse-root-models
|
|
487
|
-
Models generated with a root-type field will be
|
|
488
|
-
|
|
487
|
+
Models generated with a root-type field will be merged into the
|
|
488
|
+
models using that root-type model
|
|
489
489
|
--disable-appending-item-suffix
|
|
490
|
-
Disable appending `Item` suffix to model name in an
|
|
491
|
-
array
|
|
490
|
+
Disable appending `Item` suffix to model name in an array
|
|
492
491
|
--disable-timestamp Disable timestamp on file headers
|
|
493
492
|
--enable-faux-immutability
|
|
494
493
|
Enable faux immutability
|
|
495
494
|
--enable-version-header
|
|
496
495
|
Enable package version on file headers
|
|
497
496
|
--keep-model-order Keep generated models'' order
|
|
498
|
-
--reuse-model Reuse models on the field when a module has the model
|
|
499
|
-
|
|
500
|
-
--target-python-version {3.6,3.7,3.8,3.9,3.10,3.11}
|
|
501
|
-
target python version (default: 3.
|
|
497
|
+
--reuse-model Reuse models on the field when a module has the model with the same
|
|
498
|
+
content
|
|
499
|
+
--target-python-version {3.6,3.7,3.8,3.9,3.10,3.11,3.12}
|
|
500
|
+
target python version (default: 3.8)
|
|
501
|
+
--treat-dot-as-module
|
|
502
|
+
treat dotted module names as modules
|
|
503
|
+
--use-exact-imports import exact types instead of modules, for example: "from .foo
|
|
504
|
+
import Bar" instead of "from . import foo" with "foo.Bar"
|
|
505
|
+
--use-pendulum use pendulum instead of datetime
|
|
502
506
|
--use-schema-description
|
|
503
507
|
Use schema description to populate class docstring
|
|
504
508
|
--use-title-as-name use titles as class names of models
|
|
505
|
-
--use-exact-imports Import exact types instead of modules, for example:
|
|
506
|
-
`from .foo import Bar` instead of
|
|
507
|
-
`from . import foo` with `foo.Bar`
|
|
508
509
|
|
|
509
510
|
Template customization:
|
|
510
511
|
--aliases ALIASES Alias mapping file
|
|
@@ -512,41 +513,38 @@ Template customization:
|
|
|
512
513
|
Custom file header
|
|
513
514
|
--custom-file-header-path CUSTOM_FILE_HEADER_PATH
|
|
514
515
|
Custom file header file path
|
|
516
|
+
--custom-formatters-kwargs CUSTOM_FORMATTERS_KWARGS
|
|
517
|
+
A file with kwargs for custom formatters.
|
|
515
518
|
--custom-template-dir CUSTOM_TEMPLATE_DIR
|
|
516
519
|
Custom template directory
|
|
517
|
-
--encoding ENCODING The encoding of input and output (default:
|
|
520
|
+
--encoding ENCODING The encoding of input and output (default: utf-8)
|
|
518
521
|
--extra-template-data EXTRA_TEMPLATE_DATA
|
|
519
522
|
Extra template data
|
|
520
|
-
--use-double-quotes Model generated with double quotes. Single quotes or
|
|
521
|
-
|
|
522
|
-
|
|
523
|
+
--use-double-quotes Model generated with double quotes. Single quotes or your black
|
|
524
|
+
config skip_string_normalization value will be used without this
|
|
525
|
+
option.
|
|
523
526
|
--wrap-string-literal
|
|
524
|
-
Wrap string literal by using black `experimental-
|
|
525
|
-
|
|
526
|
-
later)
|
|
527
|
-
--additional-imports Custom imports for output (delimited list input).
|
|
528
|
-
For example "datetime.date,datetime.datetime"
|
|
529
|
-
--custom-formatters List of modules with custom formatter (delimited list input).
|
|
530
|
-
--custom-formatters-kwargs A file with kwargs for custom formatters.
|
|
527
|
+
Wrap string literal by using black `experimental-string-processing`
|
|
528
|
+
option (require black 20.8b0 or later)
|
|
531
529
|
|
|
532
530
|
OpenAPI-only options:
|
|
533
531
|
--openapi-scopes {schemas,paths,tags,parameters} [{schemas,paths,tags,parameters} ...]
|
|
534
532
|
Scopes of OpenAPI model generation (default: schemas)
|
|
535
|
-
--strict-nullable Treat default field as a non-nullable field (Only
|
|
536
|
-
OpenAPI)
|
|
533
|
+
--strict-nullable Treat default field as a non-nullable field (Only OpenAPI)
|
|
537
534
|
--use-operation-id-as-name
|
|
538
535
|
use operation id of OpenAPI as class names of models
|
|
539
|
-
--validation Deprecated: Enable validation (Only OpenAPI). this
|
|
540
|
-
|
|
541
|
-
releases
|
|
536
|
+
--validation Deprecated: Enable validation (Only OpenAPI). this option is
|
|
537
|
+
deprecated. it will be removed in future releases
|
|
542
538
|
|
|
543
539
|
General options:
|
|
544
|
-
--debug show debug message (require "debug". `$ pip install 'datamodel-code-
|
|
540
|
+
--debug show debug message (require "debug". `$ pip install ''datamodel-code-
|
|
541
|
+
generator[debug]''`)
|
|
545
542
|
--disable-warnings disable warnings
|
|
546
543
|
--no-color disable colorized output
|
|
547
544
|
--version show version
|
|
548
545
|
-h, --help show this help message and exit
|
|
549
546
|
```
|
|
547
|
+
<!-- end command help -->
|
|
550
548
|
|
|
551
549
|
## Related projects
|
|
552
550
|
### fastapi-code-generator
|
|
@@ -341,61 +341,64 @@ This method needs the [http extra option](#http-extra-option)
|
|
|
341
341
|
|
|
342
342
|
The `datamodel-codegen` command:
|
|
343
343
|
|
|
344
|
+
<!-- start command help -->
|
|
344
345
|
```bash
|
|
345
|
-
usage:
|
|
346
|
+
usage:
|
|
346
347
|
datamodel-codegen [options]
|
|
347
348
|
|
|
348
349
|
Generate Python data models from schema definitions or structured data
|
|
349
350
|
|
|
350
351
|
Options:
|
|
352
|
+
--additional-imports ADDITIONAL_IMPORTS
|
|
353
|
+
Custom imports for output (delimited list input). For example
|
|
354
|
+
"datetime.date,datetime.datetime"
|
|
355
|
+
--custom-formatters CUSTOM_FORMATTERS
|
|
356
|
+
List of modules with custom formatter (delimited list input).
|
|
351
357
|
--http-headers HTTP_HEADER [HTTP_HEADER ...]
|
|
352
|
-
Set headers in HTTP requests to the remote host.
|
|
353
|
-
|
|
354
|
-
--http-ignore-tls Disable verification of the remote host''s TLS
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
(example: "ref=branch")
|
|
358
|
+
Set headers in HTTP requests to the remote host. (example:
|
|
359
|
+
"Authorization: Basic dXNlcjpwYXNz")
|
|
360
|
+
--http-ignore-tls Disable verification of the remote host''s TLS certificate
|
|
361
|
+
--http-query-parameters HTTP_QUERY_PARAMETERS [HTTP_QUERY_PARAMETERS ...]
|
|
362
|
+
Set query parameters in HTTP requests to the remote host. (example:
|
|
363
|
+
"ref=branch")
|
|
359
364
|
--input INPUT Input file/directory (default: stdin)
|
|
360
|
-
--input-file-type {auto,openapi,
|
|
365
|
+
--input-file-type {auto,openapi,jsonschema,json,yaml,dict,csv,graphql}
|
|
361
366
|
Input file type (default: auto)
|
|
362
367
|
--output OUTPUT Output file (default: stdout)
|
|
363
368
|
--output-model-type {pydantic.BaseModel,pydantic_v2.BaseModel,dataclasses.dataclass,typing.TypedDict,msgspec.Struct}
|
|
364
|
-
|
|
365
|
-
|
|
369
|
+
Output model type (default: pydantic.BaseModel)
|
|
370
|
+
--url URL Input file URL. `--input` is ignored when `--url` is used
|
|
366
371
|
|
|
367
372
|
Typing customization:
|
|
368
373
|
--base-class BASE_CLASS
|
|
369
374
|
Base Class (default: pydantic.BaseModel)
|
|
370
375
|
--enum-field-as-literal {all,one}
|
|
371
|
-
Parse enum field as literal. all: all enum field type
|
|
372
|
-
|
|
373
|
-
has only one possible value
|
|
376
|
+
Parse enum field as literal. all: all enum field type are Literal.
|
|
377
|
+
one: field type is Literal when an enum has only one possible value
|
|
374
378
|
--field-constraints Use field constraints and not con* annotations
|
|
375
379
|
--set-default-enum-member
|
|
376
380
|
Set enum members as default values for enum field
|
|
377
381
|
--strict-types {str,bytes,int,float,bool} [{str,bytes,int,float,bool} ...]
|
|
378
382
|
Use strict types
|
|
379
|
-
--use-annotated Use typing.Annotated for Field(). Also, `--field-
|
|
380
|
-
|
|
383
|
+
--use-annotated Use typing.Annotated for Field(). Also, `--field-constraints` option
|
|
384
|
+
will be enabled.
|
|
381
385
|
--use-generic-container-types
|
|
382
|
-
Use generic container types for type hinting
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
collections.abc instead of typing
|
|
386
|
+
Use generic container types for type hinting (typing.Sequence,
|
|
387
|
+
typing.Mapping). If `--use-standard-collections` option is set, then
|
|
388
|
+
import from collections.abc instead of typing
|
|
386
389
|
--use-non-positive-negative-number-constrained-types
|
|
387
|
-
Use the Non{Positive,Negative}{FloatInt} types instead
|
|
388
|
-
|
|
390
|
+
Use the Non{Positive,Negative}{FloatInt} types instead of the
|
|
391
|
+
corresponding con* constrained types.
|
|
389
392
|
--use-one-literal-as-default
|
|
390
393
|
Use one literal as default value for one literal field
|
|
391
394
|
--use-standard-collections
|
|
392
395
|
Use standard collections for type hinting (list, dict)
|
|
393
|
-
--use-subclass-enum Define Enum class as subclass with field type when
|
|
394
|
-
|
|
396
|
+
--use-subclass-enum Define Enum class as subclass with field type when enum has type
|
|
397
|
+
(int, float, bytes, str)
|
|
395
398
|
--use-union-operator Use | operator for Union type (PEP 604).
|
|
396
399
|
--use-unique-items-as-set
|
|
397
|
-
define field type as `set` when the field attribute
|
|
398
|
-
|
|
400
|
+
define field type as `set` when the field attribute has
|
|
401
|
+
`uniqueItems`
|
|
399
402
|
|
|
400
403
|
Field customization:
|
|
401
404
|
--capitalise-enum-members, --capitalize-enum-members
|
|
@@ -405,61 +408,60 @@ Field customization:
|
|
|
405
408
|
--field-extra-keys FIELD_EXTRA_KEYS [FIELD_EXTRA_KEYS ...]
|
|
406
409
|
Add extra keys to field parameters
|
|
407
410
|
--field-extra-keys-without-x-prefix FIELD_EXTRA_KEYS_WITHOUT_X_PREFIX [FIELD_EXTRA_KEYS_WITHOUT_X_PREFIX ...]
|
|
408
|
-
Add extra keys with `x-` prefix to field parameters.
|
|
409
|
-
|
|
411
|
+
Add extra keys with `x-` prefix to field parameters. The extra keys
|
|
412
|
+
are stripped of the `x-` prefix.
|
|
410
413
|
--field-include-all-keys
|
|
411
414
|
Add all keys to field parameters
|
|
412
415
|
--force-optional Force optional for required fields
|
|
413
416
|
--original-field-name-delimiter ORIGINAL_FIELD_NAME_DELIMITER
|
|
414
|
-
Set delimiter to convert to snake case. This option
|
|
415
|
-
|
|
416
|
-
)
|
|
417
|
+
Set delimiter to convert to snake case. This option only can be used
|
|
418
|
+
with --snake-case-field (default: `_` )
|
|
417
419
|
--remove-special-field-name-prefix
|
|
418
|
-
Remove field name prefix if it has a special meaning
|
|
419
|
-
|
|
420
|
+
Remove field name prefix if it has a special meaning e.g.
|
|
421
|
+
underscores
|
|
420
422
|
--snake-case-field Change camel-case field name to snake-case
|
|
421
423
|
--special-field-name-prefix SPECIAL_FIELD_NAME_PREFIX
|
|
422
|
-
Set field name prefix when first character can''t be
|
|
423
|
-
|
|
424
|
+
Set field name prefix when first character can''t be used as Python
|
|
425
|
+
field name (default: `field`)
|
|
424
426
|
--strip-default-none Strip default None on fields
|
|
427
|
+
--union-mode {smart,left_to_right}
|
|
428
|
+
Union mode for only pydantic v2 field
|
|
425
429
|
--use-default Use default value even if a field is required
|
|
426
|
-
--use-default-kwarg Use `default=` instead of a positional argument for
|
|
427
|
-
|
|
430
|
+
--use-default-kwarg Use `default=` instead of a positional argument for Fields that have
|
|
431
|
+
default values.
|
|
428
432
|
--use-field-description
|
|
429
433
|
Use schema description to populate field docstring
|
|
430
|
-
--use-pendulum
|
|
431
|
-
Use pendulum instead of `datetime` for `date`,
|
|
432
|
-
`datetime`, and `time` data types
|
|
433
434
|
|
|
434
435
|
Model customization:
|
|
435
|
-
--allow-extra-fields Allow to pass extra fields, if this flag is not
|
|
436
|
-
|
|
436
|
+
--allow-extra-fields Allow to pass extra fields, if this flag is not passed, extra fields
|
|
437
|
+
are forbidden.
|
|
437
438
|
--allow-population-by-field-name
|
|
438
439
|
Allow population by field name
|
|
439
440
|
--class-name CLASS_NAME
|
|
440
441
|
Set class name of root model
|
|
441
442
|
--collapse-root-models
|
|
442
|
-
Models generated with a root-type field will be
|
|
443
|
-
|
|
443
|
+
Models generated with a root-type field will be merged into the
|
|
444
|
+
models using that root-type model
|
|
444
445
|
--disable-appending-item-suffix
|
|
445
|
-
Disable appending `Item` suffix to model name in an
|
|
446
|
-
array
|
|
446
|
+
Disable appending `Item` suffix to model name in an array
|
|
447
447
|
--disable-timestamp Disable timestamp on file headers
|
|
448
448
|
--enable-faux-immutability
|
|
449
449
|
Enable faux immutability
|
|
450
450
|
--enable-version-header
|
|
451
451
|
Enable package version on file headers
|
|
452
452
|
--keep-model-order Keep generated models'' order
|
|
453
|
-
--reuse-model Reuse models on the field when a module has the model
|
|
454
|
-
|
|
455
|
-
--target-python-version {3.6,3.7,3.8,3.9,3.10,3.11}
|
|
456
|
-
target python version (default: 3.
|
|
453
|
+
--reuse-model Reuse models on the field when a module has the model with the same
|
|
454
|
+
content
|
|
455
|
+
--target-python-version {3.6,3.7,3.8,3.9,3.10,3.11,3.12}
|
|
456
|
+
target python version (default: 3.8)
|
|
457
|
+
--treat-dot-as-module
|
|
458
|
+
treat dotted module names as modules
|
|
459
|
+
--use-exact-imports import exact types instead of modules, for example: "from .foo
|
|
460
|
+
import Bar" instead of "from . import foo" with "foo.Bar"
|
|
461
|
+
--use-pendulum use pendulum instead of datetime
|
|
457
462
|
--use-schema-description
|
|
458
463
|
Use schema description to populate class docstring
|
|
459
464
|
--use-title-as-name use titles as class names of models
|
|
460
|
-
--use-exact-imports Import exact types instead of modules, for example:
|
|
461
|
-
`from .foo import Bar` instead of
|
|
462
|
-
`from . import foo` with `foo.Bar`
|
|
463
465
|
|
|
464
466
|
Template customization:
|
|
465
467
|
--aliases ALIASES Alias mapping file
|
|
@@ -467,41 +469,38 @@ Template customization:
|
|
|
467
469
|
Custom file header
|
|
468
470
|
--custom-file-header-path CUSTOM_FILE_HEADER_PATH
|
|
469
471
|
Custom file header file path
|
|
472
|
+
--custom-formatters-kwargs CUSTOM_FORMATTERS_KWARGS
|
|
473
|
+
A file with kwargs for custom formatters.
|
|
470
474
|
--custom-template-dir CUSTOM_TEMPLATE_DIR
|
|
471
475
|
Custom template directory
|
|
472
|
-
--encoding ENCODING The encoding of input and output (default:
|
|
476
|
+
--encoding ENCODING The encoding of input and output (default: utf-8)
|
|
473
477
|
--extra-template-data EXTRA_TEMPLATE_DATA
|
|
474
478
|
Extra template data
|
|
475
|
-
--use-double-quotes Model generated with double quotes. Single quotes or
|
|
476
|
-
|
|
477
|
-
|
|
479
|
+
--use-double-quotes Model generated with double quotes. Single quotes or your black
|
|
480
|
+
config skip_string_normalization value will be used without this
|
|
481
|
+
option.
|
|
478
482
|
--wrap-string-literal
|
|
479
|
-
Wrap string literal by using black `experimental-
|
|
480
|
-
|
|
481
|
-
later)
|
|
482
|
-
--additional-imports Custom imports for output (delimited list input).
|
|
483
|
-
For example "datetime.date,datetime.datetime"
|
|
484
|
-
--custom-formatters List of modules with custom formatter (delimited list input).
|
|
485
|
-
--custom-formatters-kwargs A file with kwargs for custom formatters.
|
|
483
|
+
Wrap string literal by using black `experimental-string-processing`
|
|
484
|
+
option (require black 20.8b0 or later)
|
|
486
485
|
|
|
487
486
|
OpenAPI-only options:
|
|
488
487
|
--openapi-scopes {schemas,paths,tags,parameters} [{schemas,paths,tags,parameters} ...]
|
|
489
488
|
Scopes of OpenAPI model generation (default: schemas)
|
|
490
|
-
--strict-nullable Treat default field as a non-nullable field (Only
|
|
491
|
-
OpenAPI)
|
|
489
|
+
--strict-nullable Treat default field as a non-nullable field (Only OpenAPI)
|
|
492
490
|
--use-operation-id-as-name
|
|
493
491
|
use operation id of OpenAPI as class names of models
|
|
494
|
-
--validation Deprecated: Enable validation (Only OpenAPI). this
|
|
495
|
-
|
|
496
|
-
releases
|
|
492
|
+
--validation Deprecated: Enable validation (Only OpenAPI). this option is
|
|
493
|
+
deprecated. it will be removed in future releases
|
|
497
494
|
|
|
498
495
|
General options:
|
|
499
|
-
--debug show debug message (require "debug". `$ pip install 'datamodel-code-
|
|
496
|
+
--debug show debug message (require "debug". `$ pip install ''datamodel-code-
|
|
497
|
+
generator[debug]''`)
|
|
500
498
|
--disable-warnings disable warnings
|
|
501
499
|
--no-color disable colorized output
|
|
502
500
|
--version show version
|
|
503
501
|
-h, --help show this help message and exit
|
|
504
502
|
```
|
|
503
|
+
<!-- end command help -->
|
|
505
504
|
|
|
506
505
|
## Related projects
|
|
507
506
|
### fastapi-code-generator
|
|
@@ -31,6 +31,7 @@ import yaml
|
|
|
31
31
|
|
|
32
32
|
import datamodel_code_generator.pydantic_patch # noqa: F401
|
|
33
33
|
from datamodel_code_generator.format import PythonVersion
|
|
34
|
+
from datamodel_code_generator.model.pydantic_v2 import UnionMode
|
|
34
35
|
from datamodel_code_generator.parser import DefaultPutDict, LiteralType
|
|
35
36
|
from datamodel_code_generator.parser.base import Parser
|
|
36
37
|
from datamodel_code_generator.types import StrictTypes
|
|
@@ -66,14 +67,9 @@ else:
|
|
|
66
67
|
def get_version() -> str:
|
|
67
68
|
package = 'datamodel-code-generator'
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
from importlib.metadata import version
|
|
71
|
-
|
|
72
|
-
return version(package)
|
|
73
|
-
except ImportError:
|
|
74
|
-
import pkg_resources
|
|
70
|
+
from importlib.metadata import version
|
|
75
71
|
|
|
76
|
-
|
|
72
|
+
return version(package)
|
|
77
73
|
|
|
78
74
|
|
|
79
75
|
def enable_debug_message() -> None: # pragma: no cover
|
|
@@ -241,7 +237,7 @@ def generate(
|
|
|
241
237
|
input_file_type: InputFileType = InputFileType.Auto,
|
|
242
238
|
output: Optional[Path] = None,
|
|
243
239
|
output_model_type: DataModelType = DataModelType.PydanticBaseModel,
|
|
244
|
-
target_python_version: PythonVersion = PythonVersion.
|
|
240
|
+
target_python_version: PythonVersion = PythonVersion.PY_38,
|
|
245
241
|
base_class: str = '',
|
|
246
242
|
additional_imports: Optional[List[str]] = None,
|
|
247
243
|
custom_template_dir: Optional[Path] = None,
|
|
@@ -304,6 +300,7 @@ def generate(
|
|
|
304
300
|
http_query_parameters: Optional[Sequence[Tuple[str, str]]] = None,
|
|
305
301
|
treat_dots_as_module: bool = False,
|
|
306
302
|
use_exact_imports: bool = False,
|
|
303
|
+
union_mode: Optional[UnionMode] = None,
|
|
307
304
|
) -> None:
|
|
308
305
|
remote_text_cache: DefaultPutDict[str, str] = DefaultPutDict()
|
|
309
306
|
if isinstance(input_, str):
|
|
@@ -391,6 +388,13 @@ def generate(
|
|
|
391
388
|
if isinstance(input_, ParseResult) and input_file_type not in RAW_DATA_TYPES:
|
|
392
389
|
input_text = None
|
|
393
390
|
|
|
391
|
+
if union_mode is not None:
|
|
392
|
+
if output_model_type == DataModelType.PydanticV2BaseModel:
|
|
393
|
+
default_field_extras = {'union_mode': union_mode}
|
|
394
|
+
else: # pragma: no cover
|
|
395
|
+
raise Error('union_mode is only supported for pydantic_v2.BaseModel')
|
|
396
|
+
else:
|
|
397
|
+
default_field_extras = None
|
|
394
398
|
from datamodel_code_generator.model import get_data_model_types
|
|
395
399
|
|
|
396
400
|
data_model_types = get_data_model_types(output_model_type, target_python_version)
|
|
@@ -466,6 +470,7 @@ def generate(
|
|
|
466
470
|
http_query_parameters=http_query_parameters,
|
|
467
471
|
treat_dots_as_module=treat_dots_as_module,
|
|
468
472
|
use_exact_imports=use_exact_imports,
|
|
473
|
+
default_field_extras=default_field_extras,
|
|
469
474
|
**kwargs,
|
|
470
475
|
)
|
|
471
476
|
|
|
@@ -33,6 +33,8 @@ import argcomplete
|
|
|
33
33
|
import black
|
|
34
34
|
from pydantic import BaseModel
|
|
35
35
|
|
|
36
|
+
from datamodel_code_generator.model.pydantic_v2 import UnionMode
|
|
37
|
+
|
|
36
38
|
if TYPE_CHECKING:
|
|
37
39
|
from argparse import Namespace
|
|
38
40
|
|
|
@@ -248,7 +250,7 @@ class Config(BaseModel):
|
|
|
248
250
|
output: Optional[Path] = None
|
|
249
251
|
debug: bool = False
|
|
250
252
|
disable_warnings: bool = False
|
|
251
|
-
target_python_version: PythonVersion = PythonVersion.
|
|
253
|
+
target_python_version: PythonVersion = PythonVersion.PY_38
|
|
252
254
|
base_class: str = ''
|
|
253
255
|
additional_imports: Optional[List[str]] = (None,)
|
|
254
256
|
custom_template_dir: Optional[Path] = None
|
|
@@ -310,6 +312,7 @@ class Config(BaseModel):
|
|
|
310
312
|
http_query_parameters: Optional[Sequence[Tuple[str, str]]] = None
|
|
311
313
|
treat_dot_as_module: bool = False
|
|
312
314
|
use_exact_imports: bool = False
|
|
315
|
+
union_mode: Optional[UnionMode] = None
|
|
313
316
|
|
|
314
317
|
def merge_args(self, args: Namespace) -> None:
|
|
315
318
|
set_args = {
|
|
@@ -508,6 +511,7 @@ def main(args: Optional[Sequence[str]] = None) -> Exit:
|
|
|
508
511
|
http_query_parameters=config.http_query_parameters,
|
|
509
512
|
treat_dots_as_module=config.treat_dot_as_module,
|
|
510
513
|
use_exact_imports=config.use_exact_imports,
|
|
514
|
+
union_mode=config.union_mode,
|
|
511
515
|
)
|
|
512
516
|
return Exit.OK
|
|
513
517
|
except InvalidClassNameError as e:
|
|
@@ -7,6 +7,7 @@ from typing import TYPE_CHECKING
|
|
|
7
7
|
|
|
8
8
|
from datamodel_code_generator import DataModelType, InputFileType, OpenAPIScope
|
|
9
9
|
from datamodel_code_generator.format import PythonVersion
|
|
10
|
+
from datamodel_code_generator.model.pydantic_v2 import UnionMode
|
|
10
11
|
from datamodel_code_generator.parser import LiteralType
|
|
11
12
|
from datamodel_code_generator.types import StrictTypes
|
|
12
13
|
|
|
@@ -151,13 +152,13 @@ model_options.add_argument(
|
|
|
151
152
|
)
|
|
152
153
|
model_options.add_argument(
|
|
153
154
|
'--reuse-model',
|
|
154
|
-
help='
|
|
155
|
+
help='Reuse models on the field when a module has the model with the same content',
|
|
155
156
|
action='store_true',
|
|
156
157
|
default=None,
|
|
157
158
|
)
|
|
158
159
|
model_options.add_argument(
|
|
159
160
|
'--target-python-version',
|
|
160
|
-
help='target python version (default: 3.
|
|
161
|
+
help='target python version (default: 3.8)',
|
|
161
162
|
choices=[v.value for v in PythonVersion],
|
|
162
163
|
)
|
|
163
164
|
model_options.add_argument(
|
|
@@ -361,6 +362,12 @@ field_options.add_argument(
|
|
|
361
362
|
action='store_true',
|
|
362
363
|
default=None,
|
|
363
364
|
)
|
|
365
|
+
field_options.add_argument(
|
|
366
|
+
'--union-mode',
|
|
367
|
+
help='Union mode for only pydantic v2 field',
|
|
368
|
+
choices=[u.value for u in UnionMode],
|
|
369
|
+
default=None,
|
|
370
|
+
)
|
|
364
371
|
|
|
365
372
|
# ======================================================================================
|
|
366
373
|
# Options for templating output
|
|
@@ -492,7 +499,6 @@ general_options.add_argument(
|
|
|
492
499
|
help='show version',
|
|
493
500
|
)
|
|
494
501
|
|
|
495
|
-
|
|
496
502
|
__all__ = [
|
|
497
503
|
'arg_parser',
|
|
498
504
|
'DEFAULT_ENCODING',
|
|
@@ -139,7 +139,9 @@ class CodeFormatter:
|
|
|
139
139
|
'experimental-string-processing'
|
|
140
140
|
)
|
|
141
141
|
else:
|
|
142
|
-
experimental_string_processing = config.get(
|
|
142
|
+
experimental_string_processing = config.get(
|
|
143
|
+
'preview', False
|
|
144
|
+
) and ( # pragma: no cover
|
|
143
145
|
config.get('unstable', False)
|
|
144
146
|
or 'string_processing' in config.get('enable-unstable-feature', [])
|
|
145
147
|
)
|