datamodel-code-generator 0.25.7__tar.gz → 0.25.9__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.7 → datamodel_code_generator-0.25.9}/PKG-INFO +49 -24
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/README.md +48 -23
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/__init__.py +5 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/__main__.py +6 -6
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/arguments.py +14 -1
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/imports.py +2 -1
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/base.py +2 -2
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/pydantic_v2/base_model.py +4 -4
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/parser/base.py +158 -32
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/parser/graphql.py +34 -19
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/parser/jsonschema.py +11 -7
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/parser/openapi.py +4 -0
- datamodel_code_generator-0.25.9/datamodel_code_generator/pydantic_patch.py +21 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/types.py +1 -6
- datamodel_code_generator-0.25.9/datamodel_code_generator/version.py +1 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/pyproject.toml +2 -2
- datamodel_code_generator-0.25.7/datamodel_code_generator/version.py +0 -1
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/LICENSE +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/format.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/http.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/__init__.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/dataclass.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/enum.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/imports.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/msgspec.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/pydantic/__init__.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/pydantic/base_model.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/pydantic/custom_root_type.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/pydantic/dataclass.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/pydantic/imports.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/pydantic/types.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/pydantic_v2/__init__.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/pydantic_v2/imports.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/pydantic_v2/root_model.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/pydantic_v2/types.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/rootmodel.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/scalar.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/Enum.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/Scalar.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/TypedDict.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/TypedDictClass.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/TypedDictFunction.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/Union.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/dataclass.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/msgspec.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/pydantic/BaseModel.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/pydantic/BaseModel_root.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/pydantic/Config.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/pydantic/dataclass.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/pydantic_v2/BaseModel.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/pydantic_v2/ConfigDict.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/pydantic_v2/RootModel.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/template/root.jinja2 +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/typed_dict.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/types.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/model/union.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/parser/__init__.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/py.typed +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/reference.py +0 -0
- {datamodel_code_generator-0.25.7 → datamodel_code_generator-0.25.9}/datamodel_code_generator/util.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: datamodel-code-generator
|
|
3
|
-
Version: 0.25.
|
|
3
|
+
Version: 0.25.9
|
|
4
4
|
Summary: Datamodel Code Generator
|
|
5
5
|
Home-page: https://github.com/koxudaxi/datamodel-code-generator
|
|
6
6
|
License: MIT
|
|
@@ -61,9 +61,6 @@ and [msgspec.Struct](https://github.com/jcrist/msgspec) from an openapi file and
|
|
|
61
61
|
## Help
|
|
62
62
|
See [documentation](https://koxudaxi.github.io/datamodel-code-generator) for more details.
|
|
63
63
|
|
|
64
|
-
## Sponsors
|
|
65
|
-
[](https://github.com/JetBrainsOfficial)
|
|
66
|
-
|
|
67
64
|
## Quick Installation
|
|
68
65
|
|
|
69
66
|
To install `datamodel-code-generator`:
|
|
@@ -281,13 +278,52 @@ class Apis(BaseModel):
|
|
|
281
278
|
```
|
|
282
279
|
</details>
|
|
283
280
|
|
|
281
|
+
## Supported input types
|
|
282
|
+
- OpenAPI 3 (YAML/JSON, [OpenAPI Data Type](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#data-types));
|
|
283
|
+
- JSON Schema ([JSON Schema Core](http://json-schema.org/draft/2019-09/json-schema-validation.html)/[JSON Schema Validation](http://json-schema.org/draft/2019-09/json-schema-validation.html));
|
|
284
|
+
- JSON/YAML/CSV Data (it will be converted to JSON Schema);
|
|
285
|
+
- Python dictionary (it will be converted to JSON Schema);
|
|
286
|
+
- GraphQL schema ([GraphQL Schemas and Types](https://graphql.org/learn/schema/));
|
|
287
|
+
|
|
288
|
+
## Supported output types
|
|
289
|
+
- [pydantic](https://docs.pydantic.dev/1.10/).BaseModel;
|
|
290
|
+
- [pydantic_v2](https://docs.pydantic.dev/2.0/).BaseModel;
|
|
291
|
+
- [dataclasses.dataclass](https://docs.python.org/3/library/dataclasses.html);
|
|
292
|
+
- [typing.TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict);
|
|
293
|
+
- [msgspec.Struct](https://github.com/jcrist/msgspec);
|
|
294
|
+
- Custom type from your [jinja2](https://jinja.palletsprojects.com/en/3.1.x/) template;
|
|
295
|
+
|
|
296
|
+
## Sponsors
|
|
297
|
+
<table>
|
|
298
|
+
<tr>
|
|
299
|
+
<td valign="top" align="center">
|
|
300
|
+
<a href="https://github.com/JetBrainsOfficial">
|
|
301
|
+
<img src="https://avatars.githubusercontent.com/u/60931315?s=100&v=4" alt="JetBrains Logo" style="width: 100px;">
|
|
302
|
+
<p>JetBrains</p>
|
|
303
|
+
</a>
|
|
304
|
+
</td>
|
|
305
|
+
<td valign="top" align="center">
|
|
306
|
+
<a href="https://github.com/astral-sh">
|
|
307
|
+
<img src="https://avatars.githubusercontent.com/u/115962839?s=200&v=4" alt="Astral Logo" style="width: 100px;">
|
|
308
|
+
<p>Astral</p>
|
|
309
|
+
</a>
|
|
310
|
+
</td>
|
|
311
|
+
<td valign="top" align="center">
|
|
312
|
+
<a href="https://github.com/DataDog">
|
|
313
|
+
<img src="https://avatars.githubusercontent.com/u/365230?s=200&v=4" alt="Datadog, Inc. Logo" style="width: 100px;">
|
|
314
|
+
<p>Datadog, Inc.</p>
|
|
315
|
+
</a>
|
|
316
|
+
</td>
|
|
317
|
+
</tr>
|
|
318
|
+
</table>
|
|
319
|
+
|
|
284
320
|
## Projects that use datamodel-code-generator
|
|
285
321
|
|
|
286
322
|
These OSS projects use datamodel-code-generator to generate many models.
|
|
287
323
|
See the following linked projects for real world examples and inspiration.
|
|
288
324
|
|
|
289
325
|
- [airbytehq/airbyte](https://github.com/airbytehq/airbyte)
|
|
290
|
-
- *[
|
|
326
|
+
- *[Generate Python, Java/Kotlin, and Typescript protocol models](https://github.com/airbytehq/airbyte-protocol/tree/main/protocol-models/bin)*
|
|
291
327
|
- [apache/iceberg](https://github.com/apache/iceberg)
|
|
292
328
|
- *[Generate Python code](https://github.com/apache/iceberg/blob/d2e1094ee0cc6239d43f63ba5114272f59d605d2/open-api/README.md?plain=1#L39)*
|
|
293
329
|
*[`make generate`](https://github.com/apache/iceberg/blob/d2e1094ee0cc6239d43f63ba5114272f59d605d2/open-api/Makefile#L24-L34)*
|
|
@@ -312,21 +348,6 @@ See the following linked projects for real world examples and inspiration.
|
|
|
312
348
|
- [SeldonIO/MLServer](https://github.com/SeldonIO/MLServer)
|
|
313
349
|
- *[generate-types.sh](https://github.com/SeldonIO/MLServer/blob/master/hack/generate-types.sh)*
|
|
314
350
|
|
|
315
|
-
## Supported input types
|
|
316
|
-
- OpenAPI 3 (YAML/JSON, [OpenAPI Data Type](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#data-types));
|
|
317
|
-
- JSON Schema ([JSON Schema Core](http://json-schema.org/draft/2019-09/json-schema-validation.html)/[JSON Schema Validation](http://json-schema.org/draft/2019-09/json-schema-validation.html));
|
|
318
|
-
- JSON/YAML/CSV Data (it will be converted to JSON Schema);
|
|
319
|
-
- Python dictionary (it will be converted to JSON Schema);
|
|
320
|
-
- GraphQL schema ([GraphQL Schemas and Types](https://graphql.org/learn/schema/));
|
|
321
|
-
|
|
322
|
-
## Supported output types
|
|
323
|
-
- [pydantic](https://docs.pydantic.dev/1.10/).BaseModel;
|
|
324
|
-
- [pydantic_v2](https://docs.pydantic.dev/2.0/).BaseModel;
|
|
325
|
-
- [dataclasses.dataclass](https://docs.python.org/3/library/dataclasses.html);
|
|
326
|
-
- [typing.TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict);
|
|
327
|
-
- [msgspec.Struct](https://github.com/jcrist/msgspec);
|
|
328
|
-
- Custom type from your [jinja2](https://jinja.palletsprojects.com/en/3.1.x/) template;
|
|
329
|
-
|
|
330
351
|
## Installation
|
|
331
352
|
|
|
332
353
|
To install `datamodel-code-generator`:
|
|
@@ -364,6 +385,7 @@ This method needs the [http extra option](#http-extra-option)
|
|
|
364
385
|
## All Command Options
|
|
365
386
|
|
|
366
387
|
The `datamodel-codegen` command:
|
|
388
|
+
|
|
367
389
|
```bash
|
|
368
390
|
usage:
|
|
369
391
|
datamodel-codegen [options]
|
|
@@ -374,7 +396,7 @@ Options:
|
|
|
374
396
|
--http-headers HTTP_HEADER [HTTP_HEADER ...]
|
|
375
397
|
Set headers in HTTP requests to the remote host.
|
|
376
398
|
(example: "Authorization: Basic dXNlcjpwYXNz")
|
|
377
|
-
--http-ignore-tls Disable verification of the remote host's TLS
|
|
399
|
+
--http-ignore-tls Disable verification of the remote host''s TLS
|
|
378
400
|
certificate
|
|
379
401
|
--http-query-parameters QUERY_PARAMETER [QUERY_PARAMETER ...]
|
|
380
402
|
Set query parameters in HTTP requests to the remote host.
|
|
@@ -442,7 +464,7 @@ Field customization:
|
|
|
442
464
|
e.g. underscores
|
|
443
465
|
--snake-case-field Change camel-case field name to snake-case
|
|
444
466
|
--special-field-name-prefix SPECIAL_FIELD_NAME_PREFIX
|
|
445
|
-
Set field name prefix when first character can't be
|
|
467
|
+
Set field name prefix when first character can''t be
|
|
446
468
|
used as Python field name (default: `field`)
|
|
447
469
|
--strip-default-none Strip default None on fields
|
|
448
470
|
--use-default Use default value even if a field is required
|
|
@@ -463,7 +485,7 @@ Model customization:
|
|
|
463
485
|
Set class name of root model
|
|
464
486
|
--collapse-root-models
|
|
465
487
|
Models generated with a root-type field will be
|
|
466
|
-
|
|
488
|
+
merged into the models using that root-type model
|
|
467
489
|
--disable-appending-item-suffix
|
|
468
490
|
Disable appending `Item` suffix to model name in an
|
|
469
491
|
array
|
|
@@ -472,7 +494,7 @@ Model customization:
|
|
|
472
494
|
Enable faux immutability
|
|
473
495
|
--enable-version-header
|
|
474
496
|
Enable package version on file headers
|
|
475
|
-
--keep-model-order Keep generated models' order
|
|
497
|
+
--keep-model-order Keep generated models'' order
|
|
476
498
|
--reuse-model Reuse models on the field when a module has the model
|
|
477
499
|
with the same content
|
|
478
500
|
--target-python-version {3.6,3.7,3.8,3.9,3.10,3.11}
|
|
@@ -480,6 +502,9 @@ Model customization:
|
|
|
480
502
|
--use-schema-description
|
|
481
503
|
Use schema description to populate class docstring
|
|
482
504
|
--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`
|
|
483
508
|
|
|
484
509
|
Template customization:
|
|
485
510
|
--aliases ALIASES Alias mapping file
|
|
@@ -16,9 +16,6 @@ and [msgspec.Struct](https://github.com/jcrist/msgspec) from an openapi file and
|
|
|
16
16
|
## Help
|
|
17
17
|
See [documentation](https://koxudaxi.github.io/datamodel-code-generator) for more details.
|
|
18
18
|
|
|
19
|
-
## Sponsors
|
|
20
|
-
[](https://github.com/JetBrainsOfficial)
|
|
21
|
-
|
|
22
19
|
## Quick Installation
|
|
23
20
|
|
|
24
21
|
To install `datamodel-code-generator`:
|
|
@@ -236,13 +233,52 @@ class Apis(BaseModel):
|
|
|
236
233
|
```
|
|
237
234
|
</details>
|
|
238
235
|
|
|
236
|
+
## Supported input types
|
|
237
|
+
- OpenAPI 3 (YAML/JSON, [OpenAPI Data Type](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#data-types));
|
|
238
|
+
- JSON Schema ([JSON Schema Core](http://json-schema.org/draft/2019-09/json-schema-validation.html)/[JSON Schema Validation](http://json-schema.org/draft/2019-09/json-schema-validation.html));
|
|
239
|
+
- JSON/YAML/CSV Data (it will be converted to JSON Schema);
|
|
240
|
+
- Python dictionary (it will be converted to JSON Schema);
|
|
241
|
+
- GraphQL schema ([GraphQL Schemas and Types](https://graphql.org/learn/schema/));
|
|
242
|
+
|
|
243
|
+
## Supported output types
|
|
244
|
+
- [pydantic](https://docs.pydantic.dev/1.10/).BaseModel;
|
|
245
|
+
- [pydantic_v2](https://docs.pydantic.dev/2.0/).BaseModel;
|
|
246
|
+
- [dataclasses.dataclass](https://docs.python.org/3/library/dataclasses.html);
|
|
247
|
+
- [typing.TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict);
|
|
248
|
+
- [msgspec.Struct](https://github.com/jcrist/msgspec);
|
|
249
|
+
- Custom type from your [jinja2](https://jinja.palletsprojects.com/en/3.1.x/) template;
|
|
250
|
+
|
|
251
|
+
## Sponsors
|
|
252
|
+
<table>
|
|
253
|
+
<tr>
|
|
254
|
+
<td valign="top" align="center">
|
|
255
|
+
<a href="https://github.com/JetBrainsOfficial">
|
|
256
|
+
<img src="https://avatars.githubusercontent.com/u/60931315?s=100&v=4" alt="JetBrains Logo" style="width: 100px;">
|
|
257
|
+
<p>JetBrains</p>
|
|
258
|
+
</a>
|
|
259
|
+
</td>
|
|
260
|
+
<td valign="top" align="center">
|
|
261
|
+
<a href="https://github.com/astral-sh">
|
|
262
|
+
<img src="https://avatars.githubusercontent.com/u/115962839?s=200&v=4" alt="Astral Logo" style="width: 100px;">
|
|
263
|
+
<p>Astral</p>
|
|
264
|
+
</a>
|
|
265
|
+
</td>
|
|
266
|
+
<td valign="top" align="center">
|
|
267
|
+
<a href="https://github.com/DataDog">
|
|
268
|
+
<img src="https://avatars.githubusercontent.com/u/365230?s=200&v=4" alt="Datadog, Inc. Logo" style="width: 100px;">
|
|
269
|
+
<p>Datadog, Inc.</p>
|
|
270
|
+
</a>
|
|
271
|
+
</td>
|
|
272
|
+
</tr>
|
|
273
|
+
</table>
|
|
274
|
+
|
|
239
275
|
## Projects that use datamodel-code-generator
|
|
240
276
|
|
|
241
277
|
These OSS projects use datamodel-code-generator to generate many models.
|
|
242
278
|
See the following linked projects for real world examples and inspiration.
|
|
243
279
|
|
|
244
280
|
- [airbytehq/airbyte](https://github.com/airbytehq/airbyte)
|
|
245
|
-
- *[
|
|
281
|
+
- *[Generate Python, Java/Kotlin, and Typescript protocol models](https://github.com/airbytehq/airbyte-protocol/tree/main/protocol-models/bin)*
|
|
246
282
|
- [apache/iceberg](https://github.com/apache/iceberg)
|
|
247
283
|
- *[Generate Python code](https://github.com/apache/iceberg/blob/d2e1094ee0cc6239d43f63ba5114272f59d605d2/open-api/README.md?plain=1#L39)*
|
|
248
284
|
*[`make generate`](https://github.com/apache/iceberg/blob/d2e1094ee0cc6239d43f63ba5114272f59d605d2/open-api/Makefile#L24-L34)*
|
|
@@ -267,21 +303,6 @@ See the following linked projects for real world examples and inspiration.
|
|
|
267
303
|
- [SeldonIO/MLServer](https://github.com/SeldonIO/MLServer)
|
|
268
304
|
- *[generate-types.sh](https://github.com/SeldonIO/MLServer/blob/master/hack/generate-types.sh)*
|
|
269
305
|
|
|
270
|
-
## Supported input types
|
|
271
|
-
- OpenAPI 3 (YAML/JSON, [OpenAPI Data Type](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#data-types));
|
|
272
|
-
- JSON Schema ([JSON Schema Core](http://json-schema.org/draft/2019-09/json-schema-validation.html)/[JSON Schema Validation](http://json-schema.org/draft/2019-09/json-schema-validation.html));
|
|
273
|
-
- JSON/YAML/CSV Data (it will be converted to JSON Schema);
|
|
274
|
-
- Python dictionary (it will be converted to JSON Schema);
|
|
275
|
-
- GraphQL schema ([GraphQL Schemas and Types](https://graphql.org/learn/schema/));
|
|
276
|
-
|
|
277
|
-
## Supported output types
|
|
278
|
-
- [pydantic](https://docs.pydantic.dev/1.10/).BaseModel;
|
|
279
|
-
- [pydantic_v2](https://docs.pydantic.dev/2.0/).BaseModel;
|
|
280
|
-
- [dataclasses.dataclass](https://docs.python.org/3/library/dataclasses.html);
|
|
281
|
-
- [typing.TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict);
|
|
282
|
-
- [msgspec.Struct](https://github.com/jcrist/msgspec);
|
|
283
|
-
- Custom type from your [jinja2](https://jinja.palletsprojects.com/en/3.1.x/) template;
|
|
284
|
-
|
|
285
306
|
## Installation
|
|
286
307
|
|
|
287
308
|
To install `datamodel-code-generator`:
|
|
@@ -319,6 +340,7 @@ This method needs the [http extra option](#http-extra-option)
|
|
|
319
340
|
## All Command Options
|
|
320
341
|
|
|
321
342
|
The `datamodel-codegen` command:
|
|
343
|
+
|
|
322
344
|
```bash
|
|
323
345
|
usage:
|
|
324
346
|
datamodel-codegen [options]
|
|
@@ -329,7 +351,7 @@ Options:
|
|
|
329
351
|
--http-headers HTTP_HEADER [HTTP_HEADER ...]
|
|
330
352
|
Set headers in HTTP requests to the remote host.
|
|
331
353
|
(example: "Authorization: Basic dXNlcjpwYXNz")
|
|
332
|
-
--http-ignore-tls Disable verification of the remote host's TLS
|
|
354
|
+
--http-ignore-tls Disable verification of the remote host''s TLS
|
|
333
355
|
certificate
|
|
334
356
|
--http-query-parameters QUERY_PARAMETER [QUERY_PARAMETER ...]
|
|
335
357
|
Set query parameters in HTTP requests to the remote host.
|
|
@@ -397,7 +419,7 @@ Field customization:
|
|
|
397
419
|
e.g. underscores
|
|
398
420
|
--snake-case-field Change camel-case field name to snake-case
|
|
399
421
|
--special-field-name-prefix SPECIAL_FIELD_NAME_PREFIX
|
|
400
|
-
Set field name prefix when first character can't be
|
|
422
|
+
Set field name prefix when first character can''t be
|
|
401
423
|
used as Python field name (default: `field`)
|
|
402
424
|
--strip-default-none Strip default None on fields
|
|
403
425
|
--use-default Use default value even if a field is required
|
|
@@ -418,7 +440,7 @@ Model customization:
|
|
|
418
440
|
Set class name of root model
|
|
419
441
|
--collapse-root-models
|
|
420
442
|
Models generated with a root-type field will be
|
|
421
|
-
|
|
443
|
+
merged into the models using that root-type model
|
|
422
444
|
--disable-appending-item-suffix
|
|
423
445
|
Disable appending `Item` suffix to model name in an
|
|
424
446
|
array
|
|
@@ -427,7 +449,7 @@ Model customization:
|
|
|
427
449
|
Enable faux immutability
|
|
428
450
|
--enable-version-header
|
|
429
451
|
Enable package version on file headers
|
|
430
|
-
--keep-model-order Keep generated models' order
|
|
452
|
+
--keep-model-order Keep generated models'' order
|
|
431
453
|
--reuse-model Reuse models on the field when a module has the model
|
|
432
454
|
with the same content
|
|
433
455
|
--target-python-version {3.6,3.7,3.8,3.9,3.10,3.11}
|
|
@@ -435,6 +457,9 @@ Model customization:
|
|
|
435
457
|
--use-schema-description
|
|
436
458
|
Use schema description to populate class docstring
|
|
437
459
|
--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`
|
|
438
463
|
|
|
439
464
|
Template customization:
|
|
440
465
|
--aliases ALIASES Alias mapping file
|
|
@@ -29,6 +29,7 @@ from urllib.parse import ParseResult
|
|
|
29
29
|
|
|
30
30
|
import yaml
|
|
31
31
|
|
|
32
|
+
import datamodel_code_generator.pydantic_patch # noqa: F401
|
|
32
33
|
from datamodel_code_generator.format import PythonVersion
|
|
33
34
|
from datamodel_code_generator.parser import DefaultPutDict, LiteralType
|
|
34
35
|
from datamodel_code_generator.parser.base import Parser
|
|
@@ -301,6 +302,8 @@ def generate(
|
|
|
301
302
|
custom_formatters_kwargs: Optional[Dict[str, Any]] = None,
|
|
302
303
|
use_pendulum: bool = False,
|
|
303
304
|
http_query_parameters: Optional[Sequence[Tuple[str, str]]] = None,
|
|
305
|
+
treat_dots_as_module: bool = False,
|
|
306
|
+
use_exact_imports: bool = False,
|
|
304
307
|
) -> None:
|
|
305
308
|
remote_text_cache: DefaultPutDict[str, str] = DefaultPutDict()
|
|
306
309
|
if isinstance(input_, str):
|
|
@@ -461,6 +464,8 @@ def generate(
|
|
|
461
464
|
custom_formatters_kwargs=custom_formatters_kwargs,
|
|
462
465
|
use_pendulum=use_pendulum,
|
|
463
466
|
http_query_parameters=http_query_parameters,
|
|
467
|
+
treat_dots_as_module=treat_dots_as_module,
|
|
468
|
+
use_exact_imports=use_exact_imports,
|
|
464
469
|
**kwargs,
|
|
465
470
|
)
|
|
466
471
|
|
|
@@ -218,16 +218,12 @@ class Config(BaseModel):
|
|
|
218
218
|
def validate_additional_imports(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
|
219
219
|
if values.get('additional_imports') is not None:
|
|
220
220
|
values['additional_imports'] = values.get('additional_imports').split(',')
|
|
221
|
-
else:
|
|
222
|
-
values['additional_imports'] = []
|
|
223
221
|
return values
|
|
224
222
|
|
|
225
223
|
@model_validator(mode='before')
|
|
226
224
|
def validate_custom_formatters(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
|
227
225
|
if values.get('custom_formatters') is not None:
|
|
228
226
|
values['custom_formatters'] = values.get('custom_formatters').split(',')
|
|
229
|
-
else:
|
|
230
|
-
values['custom_formatters'] = []
|
|
231
227
|
return values
|
|
232
228
|
|
|
233
229
|
if PYDANTIC_V2:
|
|
@@ -312,6 +308,8 @@ class Config(BaseModel):
|
|
|
312
308
|
custom_formatters_kwargs: Optional[TextIOBase] = None
|
|
313
309
|
use_pendulum: bool = False
|
|
314
310
|
http_query_parameters: Optional[Sequence[Tuple[str, str]]] = None
|
|
311
|
+
treat_dot_as_module: bool = False
|
|
312
|
+
use_exact_imports: bool = False
|
|
315
313
|
|
|
316
314
|
def merge_args(self, args: Namespace) -> None:
|
|
317
315
|
set_args = {
|
|
@@ -427,7 +425,7 @@ def main(args: Optional[Sequence[str]] = None) -> Exit:
|
|
|
427
425
|
with config.custom_formatters_kwargs as data:
|
|
428
426
|
try:
|
|
429
427
|
custom_formatters_kwargs = json.load(data)
|
|
430
|
-
except json.JSONDecodeError as e:
|
|
428
|
+
except json.JSONDecodeError as e: # pragma: no cover
|
|
431
429
|
print(
|
|
432
430
|
f'Unable to load custom_formatters_kwargs mapping: {e}',
|
|
433
431
|
file=sys.stderr,
|
|
@@ -436,7 +434,7 @@ def main(args: Optional[Sequence[str]] = None) -> Exit:
|
|
|
436
434
|
if not isinstance(custom_formatters_kwargs, dict) or not all(
|
|
437
435
|
isinstance(k, str) and isinstance(v, str)
|
|
438
436
|
for k, v in custom_formatters_kwargs.items()
|
|
439
|
-
):
|
|
437
|
+
): # pragma: no cover
|
|
440
438
|
print(
|
|
441
439
|
'Custom formatters kwargs mapping must be a JSON string mapping (e.g. {"from": "to", ...})',
|
|
442
440
|
file=sys.stderr,
|
|
@@ -508,6 +506,8 @@ def main(args: Optional[Sequence[str]] = None) -> Exit:
|
|
|
508
506
|
custom_formatters_kwargs=custom_formatters_kwargs,
|
|
509
507
|
use_pendulum=config.use_pendulum,
|
|
510
508
|
http_query_parameters=config.http_query_parameters,
|
|
509
|
+
treat_dots_as_module=config.treat_dot_as_module,
|
|
510
|
+
use_exact_imports=config.use_exact_imports,
|
|
511
511
|
)
|
|
512
512
|
return Exit.OK
|
|
513
513
|
except InvalidClassNameError as e:
|
|
@@ -116,7 +116,7 @@ model_options.add_argument(
|
|
|
116
116
|
'--collapse-root-models',
|
|
117
117
|
action='store_true',
|
|
118
118
|
default=None,
|
|
119
|
-
help='Models generated with a root-type field will be merged'
|
|
119
|
+
help='Models generated with a root-type field will be merged '
|
|
120
120
|
'into the models using that root-type model',
|
|
121
121
|
)
|
|
122
122
|
model_options.add_argument(
|
|
@@ -160,6 +160,12 @@ model_options.add_argument(
|
|
|
160
160
|
help='target python version (default: 3.7)',
|
|
161
161
|
choices=[v.value for v in PythonVersion],
|
|
162
162
|
)
|
|
163
|
+
model_options.add_argument(
|
|
164
|
+
'--treat-dot-as-module',
|
|
165
|
+
help='treat dotted module names as modules',
|
|
166
|
+
action='store_true',
|
|
167
|
+
default=False,
|
|
168
|
+
)
|
|
163
169
|
model_options.add_argument(
|
|
164
170
|
'--use-schema-description',
|
|
165
171
|
help='Use schema description to populate class docstring',
|
|
@@ -178,6 +184,13 @@ model_options.add_argument(
|
|
|
178
184
|
action='store_true',
|
|
179
185
|
default=False,
|
|
180
186
|
)
|
|
187
|
+
model_options.add_argument(
|
|
188
|
+
'--use-exact-imports',
|
|
189
|
+
help='import exact types instead of modules, for example: "from .foo import Bar" instead of '
|
|
190
|
+
'"from . import foo" with "foo.Bar"',
|
|
191
|
+
action='store_true',
|
|
192
|
+
default=False,
|
|
193
|
+
)
|
|
181
194
|
|
|
182
195
|
# ======================================================================================
|
|
183
196
|
# Typing options for generated models
|
|
@@ -26,11 +26,12 @@ class Imports(DefaultDict[Optional[str], Set[str]]):
|
|
|
26
26
|
def __str__(self) -> str:
|
|
27
27
|
return self.dump()
|
|
28
28
|
|
|
29
|
-
def __init__(self) -> None:
|
|
29
|
+
def __init__(self, use_exact: bool = False) -> None:
|
|
30
30
|
super().__init__(set)
|
|
31
31
|
self.alias: DefaultDict[Optional[str], Dict[str, str]] = defaultdict(dict)
|
|
32
32
|
self.counter: Dict[Tuple[Optional[str], str], int] = defaultdict(int)
|
|
33
33
|
self.reference_paths: Dict[str, Import] = {}
|
|
34
|
+
self.use_exact: bool = use_exact
|
|
34
35
|
|
|
35
36
|
def _set_alias(self, from_: Optional[str], imports: Set[str]) -> List[str]:
|
|
36
37
|
return [
|
|
@@ -76,7 +76,7 @@ class ConstraintsBase(_BaseModel):
|
|
|
76
76
|
}
|
|
77
77
|
constraints_class = a.__class__
|
|
78
78
|
else:
|
|
79
|
-
root_type_field_constraints = {}
|
|
79
|
+
root_type_field_constraints = {} # pragma: no cover
|
|
80
80
|
|
|
81
81
|
if isinstance(b, ConstraintsBase): # pragma: no cover
|
|
82
82
|
model_field_constraints = {
|
|
@@ -86,7 +86,7 @@ class ConstraintsBase(_BaseModel):
|
|
|
86
86
|
else:
|
|
87
87
|
model_field_constraints = {}
|
|
88
88
|
|
|
89
|
-
if not issubclass(constraints_class, ConstraintsBase):
|
|
89
|
+
if not issubclass(constraints_class, ConstraintsBase): # pragma: no cover
|
|
90
90
|
return None
|
|
91
91
|
|
|
92
92
|
return constraints_class.parse_obj(
|
|
@@ -33,7 +33,7 @@ if TYPE_CHECKING:
|
|
|
33
33
|
else:
|
|
34
34
|
try:
|
|
35
35
|
from typing import Literal
|
|
36
|
-
except ImportError:
|
|
36
|
+
except ImportError: # pragma: no cover
|
|
37
37
|
from typing_extensions import Literal
|
|
38
38
|
|
|
39
39
|
|
|
@@ -106,7 +106,7 @@ class DataModelField(DataModelFieldV1):
|
|
|
106
106
|
|
|
107
107
|
@field_validator('extras')
|
|
108
108
|
def validate_extras(cls, values: Any) -> Dict[str, Any]:
|
|
109
|
-
if not isinstance(values, dict):
|
|
109
|
+
if not isinstance(values, dict): # pragma: no cover
|
|
110
110
|
return values
|
|
111
111
|
if 'examples' in values:
|
|
112
112
|
return values
|
|
@@ -146,7 +146,7 @@ class DataModelField(DataModelFieldV1):
|
|
|
146
146
|
self, field_arguments: List[str]
|
|
147
147
|
) -> List[str]:
|
|
148
148
|
if not self.required or self.const:
|
|
149
|
-
if self.use_default_kwarg:
|
|
149
|
+
if self.use_default_kwarg: # pragma: no cover
|
|
150
150
|
return [
|
|
151
151
|
f'default={repr(self.default)}',
|
|
152
152
|
*field_arguments,
|
|
@@ -215,7 +215,7 @@ class BaseModel(BaseModelBase):
|
|
|
215
215
|
else self.extra_template_data[from_]
|
|
216
216
|
)
|
|
217
217
|
for data_type in self.all_data_types:
|
|
218
|
-
if data_type.is_custom_type:
|
|
218
|
+
if data_type.is_custom_type: # pragma: no cover
|
|
219
219
|
config_parameters['arbitrary_types_allowed'] = True
|
|
220
220
|
break
|
|
221
221
|
|