datamodel-code-generator 0.27.2__py3-none-any.whl → 0.27.3__py3-none-any.whl
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/__init__.py +159 -190
- datamodel_code_generator/__main__.py +151 -173
- datamodel_code_generator/arguments.py +227 -230
- datamodel_code_generator/format.py +77 -99
- datamodel_code_generator/http.py +9 -10
- datamodel_code_generator/imports.py +57 -64
- datamodel_code_generator/model/__init__.py +26 -31
- datamodel_code_generator/model/base.py +94 -127
- datamodel_code_generator/model/dataclass.py +58 -59
- datamodel_code_generator/model/enum.py +34 -30
- datamodel_code_generator/model/imports.py +13 -11
- datamodel_code_generator/model/msgspec.py +112 -126
- datamodel_code_generator/model/pydantic/__init__.py +14 -27
- datamodel_code_generator/model/pydantic/base_model.py +120 -139
- datamodel_code_generator/model/pydantic/custom_root_type.py +2 -2
- datamodel_code_generator/model/pydantic/dataclass.py +6 -4
- datamodel_code_generator/model/pydantic/imports.py +35 -33
- datamodel_code_generator/model/pydantic/types.py +86 -117
- datamodel_code_generator/model/pydantic_v2/__init__.py +17 -17
- datamodel_code_generator/model/pydantic_v2/base_model.py +118 -119
- datamodel_code_generator/model/pydantic_v2/imports.py +5 -3
- datamodel_code_generator/model/pydantic_v2/root_model.py +6 -6
- datamodel_code_generator/model/pydantic_v2/types.py +8 -7
- datamodel_code_generator/model/rootmodel.py +1 -1
- datamodel_code_generator/model/scalar.py +33 -32
- datamodel_code_generator/model/typed_dict.py +42 -41
- datamodel_code_generator/model/types.py +19 -17
- datamodel_code_generator/model/union.py +21 -17
- datamodel_code_generator/parser/__init__.py +12 -11
- datamodel_code_generator/parser/base.py +320 -492
- datamodel_code_generator/parser/graphql.py +80 -111
- datamodel_code_generator/parser/jsonschema.py +422 -580
- datamodel_code_generator/parser/openapi.py +175 -204
- datamodel_code_generator/pydantic_patch.py +8 -9
- datamodel_code_generator/reference.py +192 -274
- datamodel_code_generator/types.py +147 -182
- datamodel_code_generator/util.py +22 -26
- {datamodel_code_generator-0.27.2.dist-info → datamodel_code_generator-0.27.3.dist-info}/METADATA +7 -1
- datamodel_code_generator-0.27.3.dist-info/RECORD +59 -0
- datamodel_code_generator-0.27.2.dist-info/RECORD +0 -59
- {datamodel_code_generator-0.27.2.dist-info → datamodel_code_generator-0.27.3.dist-info}/WHEEL +0 -0
- {datamodel_code_generator-0.27.2.dist-info → datamodel_code_generator-0.27.3.dist-info}/entry_points.txt +0 -0
- {datamodel_code_generator-0.27.2.dist-info → datamodel_code_generator-0.27.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -13,7 +13,7 @@ from datamodel_code_generator.types import StrictTypes
|
|
|
13
13
|
|
|
14
14
|
if TYPE_CHECKING:
|
|
15
15
|
from argparse import Action
|
|
16
|
-
from typing import Iterable
|
|
16
|
+
from typing import Iterable
|
|
17
17
|
|
|
18
18
|
DEFAULT_ENCODING = locale.getpreferredencoding()
|
|
19
19
|
|
|
@@ -21,187 +21,184 @@ namespace = Namespace(no_color=False)
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
class SortingHelpFormatter(HelpFormatter):
|
|
24
|
-
def _bold_cyan(self, text: str) -> str:
|
|
25
|
-
return f
|
|
24
|
+
def _bold_cyan(self, text: str) -> str: # noqa: PLR6301
|
|
25
|
+
return f"\x1b[36;1m{text}\x1b[0m"
|
|
26
26
|
|
|
27
27
|
def add_arguments(self, actions: Iterable[Action]) -> None:
|
|
28
|
-
actions = sorted(actions, key=attrgetter(
|
|
28
|
+
actions = sorted(actions, key=attrgetter("option_strings"))
|
|
29
29
|
super().add_arguments(actions)
|
|
30
30
|
|
|
31
|
-
def start_section(self, heading:
|
|
32
|
-
return super().start_section(
|
|
33
|
-
heading if namespace.no_color or not heading else self._bold_cyan(heading)
|
|
34
|
-
)
|
|
31
|
+
def start_section(self, heading: str | None) -> None:
|
|
32
|
+
return super().start_section(heading if namespace.no_color or not heading else self._bold_cyan(heading))
|
|
35
33
|
|
|
36
34
|
|
|
37
35
|
arg_parser = ArgumentParser(
|
|
38
|
-
usage=
|
|
39
|
-
description=
|
|
36
|
+
usage="\n datamodel-codegen [options]",
|
|
37
|
+
description="Generate Python data models from schema definitions or structured data",
|
|
40
38
|
formatter_class=SortingHelpFormatter,
|
|
41
39
|
add_help=False,
|
|
42
40
|
)
|
|
43
41
|
|
|
44
|
-
base_options = arg_parser.add_argument_group(
|
|
45
|
-
typing_options = arg_parser.add_argument_group(
|
|
46
|
-
field_options = arg_parser.add_argument_group(
|
|
47
|
-
model_options = arg_parser.add_argument_group(
|
|
48
|
-
template_options = arg_parser.add_argument_group(
|
|
49
|
-
openapi_options = arg_parser.add_argument_group(
|
|
50
|
-
general_options = arg_parser.add_argument_group(
|
|
42
|
+
base_options = arg_parser.add_argument_group("Options")
|
|
43
|
+
typing_options = arg_parser.add_argument_group("Typing customization")
|
|
44
|
+
field_options = arg_parser.add_argument_group("Field customization")
|
|
45
|
+
model_options = arg_parser.add_argument_group("Model customization")
|
|
46
|
+
template_options = arg_parser.add_argument_group("Template customization")
|
|
47
|
+
openapi_options = arg_parser.add_argument_group("OpenAPI-only options")
|
|
48
|
+
general_options = arg_parser.add_argument_group("General options")
|
|
51
49
|
|
|
52
50
|
# ======================================================================================
|
|
53
51
|
# Base options for input/output
|
|
54
52
|
# ======================================================================================
|
|
55
53
|
base_options.add_argument(
|
|
56
|
-
|
|
57
|
-
nargs=
|
|
58
|
-
metavar=
|
|
54
|
+
"--http-headers",
|
|
55
|
+
nargs="+",
|
|
56
|
+
metavar="HTTP_HEADER",
|
|
59
57
|
help='Set headers in HTTP requests to the remote host. (example: "Authorization: Basic dXNlcjpwYXNz")',
|
|
60
58
|
)
|
|
61
59
|
base_options.add_argument(
|
|
62
|
-
|
|
63
|
-
nargs=
|
|
64
|
-
metavar=
|
|
60
|
+
"--http-query-parameters",
|
|
61
|
+
nargs="+",
|
|
62
|
+
metavar="HTTP_QUERY_PARAMETERS",
|
|
65
63
|
help='Set query parameters in HTTP requests to the remote host. (example: "ref=branch")',
|
|
66
64
|
)
|
|
67
65
|
base_options.add_argument(
|
|
68
|
-
|
|
66
|
+
"--http-ignore-tls",
|
|
69
67
|
help="Disable verification of the remote host's TLS certificate",
|
|
70
|
-
action=
|
|
68
|
+
action="store_true",
|
|
71
69
|
default=None,
|
|
72
70
|
)
|
|
73
71
|
base_options.add_argument(
|
|
74
|
-
|
|
75
|
-
help=
|
|
72
|
+
"--input",
|
|
73
|
+
help="Input file/directory (default: stdin)",
|
|
76
74
|
)
|
|
77
75
|
base_options.add_argument(
|
|
78
|
-
|
|
79
|
-
help=
|
|
76
|
+
"--input-file-type",
|
|
77
|
+
help="Input file type (default: auto)",
|
|
80
78
|
choices=[i.value for i in InputFileType],
|
|
81
79
|
)
|
|
82
80
|
base_options.add_argument(
|
|
83
|
-
|
|
84
|
-
help=
|
|
81
|
+
"--output",
|
|
82
|
+
help="Output file (default: stdout)",
|
|
85
83
|
)
|
|
86
84
|
base_options.add_argument(
|
|
87
|
-
|
|
88
|
-
help=
|
|
85
|
+
"--output-model-type",
|
|
86
|
+
help="Output model type (default: pydantic.BaseModel)",
|
|
89
87
|
choices=[i.value for i in DataModelType],
|
|
90
88
|
)
|
|
91
89
|
base_options.add_argument(
|
|
92
|
-
|
|
93
|
-
help=
|
|
90
|
+
"--url",
|
|
91
|
+
help="Input file URL. `--input` is ignored when `--url` is used",
|
|
94
92
|
)
|
|
95
93
|
|
|
96
94
|
# ======================================================================================
|
|
97
95
|
# Customization options for generated models
|
|
98
96
|
# ======================================================================================
|
|
99
97
|
model_options.add_argument(
|
|
100
|
-
|
|
101
|
-
help=
|
|
102
|
-
action=
|
|
98
|
+
"--allow-extra-fields",
|
|
99
|
+
help="Allow passing extra fields, if this flag is not passed, extra fields are forbidden.",
|
|
100
|
+
action="store_true",
|
|
103
101
|
default=None,
|
|
104
102
|
)
|
|
105
103
|
model_options.add_argument(
|
|
106
|
-
|
|
107
|
-
help=
|
|
108
|
-
action=
|
|
104
|
+
"--allow-population-by-field-name",
|
|
105
|
+
help="Allow population by field name",
|
|
106
|
+
action="store_true",
|
|
109
107
|
default=None,
|
|
110
108
|
)
|
|
111
109
|
model_options.add_argument(
|
|
112
|
-
|
|
113
|
-
help=
|
|
110
|
+
"--class-name",
|
|
111
|
+
help="Set class name of root model",
|
|
114
112
|
default=None,
|
|
115
113
|
)
|
|
116
114
|
model_options.add_argument(
|
|
117
|
-
|
|
118
|
-
action=
|
|
115
|
+
"--collapse-root-models",
|
|
116
|
+
action="store_true",
|
|
119
117
|
default=None,
|
|
120
|
-
help=
|
|
121
|
-
'into the models using that root-type model',
|
|
118
|
+
help="Models generated with a root-type field will be merged into the models using that root-type model",
|
|
122
119
|
)
|
|
123
120
|
model_options.add_argument(
|
|
124
|
-
|
|
125
|
-
help=
|
|
126
|
-
action=
|
|
121
|
+
"--disable-appending-item-suffix",
|
|
122
|
+
help="Disable appending `Item` suffix to model name in an array",
|
|
123
|
+
action="store_true",
|
|
127
124
|
default=None,
|
|
128
125
|
)
|
|
129
126
|
model_options.add_argument(
|
|
130
|
-
|
|
131
|
-
help=
|
|
132
|
-
action=
|
|
127
|
+
"--disable-timestamp",
|
|
128
|
+
help="Disable timestamp on file headers",
|
|
129
|
+
action="store_true",
|
|
133
130
|
default=None,
|
|
134
131
|
)
|
|
135
132
|
model_options.add_argument(
|
|
136
|
-
|
|
137
|
-
help=
|
|
138
|
-
action=
|
|
133
|
+
"--enable-faux-immutability",
|
|
134
|
+
help="Enable faux immutability",
|
|
135
|
+
action="store_true",
|
|
139
136
|
default=None,
|
|
140
137
|
)
|
|
141
138
|
model_options.add_argument(
|
|
142
|
-
|
|
143
|
-
help=
|
|
144
|
-
action=
|
|
139
|
+
"--enable-version-header",
|
|
140
|
+
help="Enable package version on file headers",
|
|
141
|
+
action="store_true",
|
|
145
142
|
default=None,
|
|
146
143
|
)
|
|
147
144
|
model_options.add_argument(
|
|
148
|
-
|
|
145
|
+
"--keep-model-order",
|
|
149
146
|
help="Keep generated models' order",
|
|
150
|
-
action=
|
|
147
|
+
action="store_true",
|
|
151
148
|
default=None,
|
|
152
149
|
)
|
|
153
150
|
model_options.add_argument(
|
|
154
|
-
|
|
155
|
-
help=
|
|
156
|
-
action=
|
|
151
|
+
"--keyword-only",
|
|
152
|
+
help="Defined models as keyword only (for example dataclass(kw_only=True)).",
|
|
153
|
+
action="store_true",
|
|
157
154
|
default=None,
|
|
158
155
|
)
|
|
159
156
|
model_options.add_argument(
|
|
160
|
-
|
|
161
|
-
help=
|
|
162
|
-
action=
|
|
157
|
+
"--reuse-model",
|
|
158
|
+
help="Reuse models on the field when a module has the model with the same content",
|
|
159
|
+
action="store_true",
|
|
163
160
|
default=None,
|
|
164
161
|
)
|
|
165
162
|
model_options.add_argument(
|
|
166
|
-
|
|
167
|
-
help=
|
|
163
|
+
"--target-python-version",
|
|
164
|
+
help="target python version (default: 3.8)",
|
|
168
165
|
choices=[v.value for v in PythonVersion],
|
|
169
166
|
)
|
|
170
167
|
model_options.add_argument(
|
|
171
|
-
|
|
172
|
-
help=
|
|
173
|
-
action=
|
|
168
|
+
"--treat-dot-as-module",
|
|
169
|
+
help="treat dotted module names as modules",
|
|
170
|
+
action="store_true",
|
|
174
171
|
default=False,
|
|
175
172
|
)
|
|
176
173
|
model_options.add_argument(
|
|
177
|
-
|
|
178
|
-
help=
|
|
179
|
-
action=
|
|
174
|
+
"--use-schema-description",
|
|
175
|
+
help="Use schema description to populate class docstring",
|
|
176
|
+
action="store_true",
|
|
180
177
|
default=None,
|
|
181
178
|
)
|
|
182
179
|
model_options.add_argument(
|
|
183
|
-
|
|
184
|
-
help=
|
|
185
|
-
action=
|
|
180
|
+
"--use-title-as-name",
|
|
181
|
+
help="use titles as class names of models",
|
|
182
|
+
action="store_true",
|
|
186
183
|
default=None,
|
|
187
184
|
)
|
|
188
185
|
model_options.add_argument(
|
|
189
|
-
|
|
190
|
-
help=
|
|
191
|
-
action=
|
|
186
|
+
"--use-pendulum",
|
|
187
|
+
help="use pendulum instead of datetime",
|
|
188
|
+
action="store_true",
|
|
192
189
|
default=False,
|
|
193
190
|
)
|
|
194
191
|
model_options.add_argument(
|
|
195
|
-
|
|
192
|
+
"--use-exact-imports",
|
|
196
193
|
help='import exact types instead of modules, for example: "from .foo import Bar" instead of '
|
|
197
194
|
'"from . import foo" with "foo.Bar"',
|
|
198
|
-
action=
|
|
195
|
+
action="store_true",
|
|
199
196
|
default=False,
|
|
200
197
|
)
|
|
201
198
|
model_options.add_argument(
|
|
202
|
-
|
|
203
|
-
help=
|
|
204
|
-
|
|
199
|
+
"--output-datetime-class",
|
|
200
|
+
help="Choose Datetime class between AwareDatetime, NaiveDatetime or datetime. "
|
|
201
|
+
"Each output model has its default mapping (for example pydantic: datetime, dataclass: str, ...)",
|
|
205
202
|
choices=[i.value for i in DatetimeClassType],
|
|
206
203
|
default=None,
|
|
207
204
|
)
|
|
@@ -210,83 +207,83 @@ model_options.add_argument(
|
|
|
210
207
|
# Typing options for generated models
|
|
211
208
|
# ======================================================================================
|
|
212
209
|
typing_options.add_argument(
|
|
213
|
-
|
|
214
|
-
help=
|
|
210
|
+
"--base-class",
|
|
211
|
+
help="Base Class (default: pydantic.BaseModel)",
|
|
215
212
|
type=str,
|
|
216
213
|
)
|
|
217
214
|
typing_options.add_argument(
|
|
218
|
-
|
|
219
|
-
help=
|
|
220
|
-
|
|
221
|
-
|
|
215
|
+
"--enum-field-as-literal",
|
|
216
|
+
help="Parse enum field as literal. "
|
|
217
|
+
"all: all enum field type are Literal. "
|
|
218
|
+
"one: field type is Literal when an enum has only one possible value",
|
|
222
219
|
choices=[lt.value for lt in LiteralType],
|
|
223
220
|
default=None,
|
|
224
221
|
)
|
|
225
222
|
typing_options.add_argument(
|
|
226
|
-
|
|
227
|
-
help=
|
|
228
|
-
action=
|
|
223
|
+
"--field-constraints",
|
|
224
|
+
help="Use field constraints and not con* annotations",
|
|
225
|
+
action="store_true",
|
|
229
226
|
default=None,
|
|
230
227
|
)
|
|
231
228
|
typing_options.add_argument(
|
|
232
|
-
|
|
233
|
-
help=
|
|
234
|
-
action=
|
|
229
|
+
"--set-default-enum-member",
|
|
230
|
+
help="Set enum members as default values for enum field",
|
|
231
|
+
action="store_true",
|
|
235
232
|
default=None,
|
|
236
233
|
)
|
|
237
234
|
typing_options.add_argument(
|
|
238
|
-
|
|
239
|
-
help=
|
|
235
|
+
"--strict-types",
|
|
236
|
+
help="Use strict types",
|
|
240
237
|
choices=[t.value for t in StrictTypes],
|
|
241
|
-
nargs=
|
|
238
|
+
nargs="+",
|
|
242
239
|
)
|
|
243
240
|
typing_options.add_argument(
|
|
244
|
-
|
|
245
|
-
help=
|
|
246
|
-
action=
|
|
241
|
+
"--use-annotated",
|
|
242
|
+
help="Use typing.Annotated for Field(). Also, `--field-constraints` option will be enabled.",
|
|
243
|
+
action="store_true",
|
|
247
244
|
default=None,
|
|
248
245
|
)
|
|
249
246
|
typing_options.add_argument(
|
|
250
|
-
|
|
251
|
-
help=
|
|
252
|
-
|
|
253
|
-
action=
|
|
247
|
+
"--use-generic-container-types",
|
|
248
|
+
help="Use generic container types for type hinting (typing.Sequence, typing.Mapping). "
|
|
249
|
+
"If `--use-standard-collections` option is set, then import from collections.abc instead of typing",
|
|
250
|
+
action="store_true",
|
|
254
251
|
default=None,
|
|
255
252
|
)
|
|
256
253
|
typing_options.add_argument(
|
|
257
|
-
|
|
258
|
-
help=
|
|
259
|
-
action=
|
|
254
|
+
"--use-non-positive-negative-number-constrained-types",
|
|
255
|
+
help="Use the Non{Positive,Negative}{FloatInt} types instead of the corresponding con* constrained types.",
|
|
256
|
+
action="store_true",
|
|
260
257
|
default=None,
|
|
261
258
|
)
|
|
262
259
|
typing_options.add_argument(
|
|
263
|
-
|
|
264
|
-
help=
|
|
265
|
-
action=
|
|
260
|
+
"--use-one-literal-as-default",
|
|
261
|
+
help="Use one literal as default value for one literal field",
|
|
262
|
+
action="store_true",
|
|
266
263
|
default=None,
|
|
267
264
|
)
|
|
268
265
|
typing_options.add_argument(
|
|
269
|
-
|
|
270
|
-
help=
|
|
271
|
-
action=
|
|
266
|
+
"--use-standard-collections",
|
|
267
|
+
help="Use standard collections for type hinting (list, dict)",
|
|
268
|
+
action="store_true",
|
|
272
269
|
default=None,
|
|
273
270
|
)
|
|
274
271
|
typing_options.add_argument(
|
|
275
|
-
|
|
276
|
-
help=
|
|
277
|
-
action=
|
|
272
|
+
"--use-subclass-enum",
|
|
273
|
+
help="Define Enum class as subclass with field type when enum has type (int, float, bytes, str)",
|
|
274
|
+
action="store_true",
|
|
278
275
|
default=None,
|
|
279
276
|
)
|
|
280
277
|
typing_options.add_argument(
|
|
281
|
-
|
|
282
|
-
help=
|
|
283
|
-
action=
|
|
278
|
+
"--use-union-operator",
|
|
279
|
+
help="Use | operator for Union type (PEP 604).",
|
|
280
|
+
action="store_true",
|
|
284
281
|
default=None,
|
|
285
282
|
)
|
|
286
283
|
typing_options.add_argument(
|
|
287
|
-
|
|
288
|
-
help=
|
|
289
|
-
action=
|
|
284
|
+
"--use-unique-items-as-set",
|
|
285
|
+
help="define field type as `set` when the field attribute has `uniqueItems`",
|
|
286
|
+
action="store_true",
|
|
290
287
|
default=None,
|
|
291
288
|
)
|
|
292
289
|
|
|
@@ -294,98 +291,98 @@ typing_options.add_argument(
|
|
|
294
291
|
# Customization options for generated model fields
|
|
295
292
|
# ======================================================================================
|
|
296
293
|
field_options.add_argument(
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
help=
|
|
300
|
-
action=
|
|
294
|
+
"--capitalise-enum-members",
|
|
295
|
+
"--capitalize-enum-members",
|
|
296
|
+
help="Capitalize field names on enum",
|
|
297
|
+
action="store_true",
|
|
301
298
|
default=None,
|
|
302
299
|
)
|
|
303
300
|
field_options.add_argument(
|
|
304
|
-
|
|
305
|
-
help=
|
|
301
|
+
"--empty-enum-field-name",
|
|
302
|
+
help="Set field name when enum value is empty (default: `_`)",
|
|
306
303
|
default=None,
|
|
307
304
|
)
|
|
308
305
|
field_options.add_argument(
|
|
309
|
-
|
|
310
|
-
help=
|
|
306
|
+
"--field-extra-keys",
|
|
307
|
+
help="Add extra keys to field parameters",
|
|
311
308
|
type=str,
|
|
312
|
-
nargs=
|
|
309
|
+
nargs="+",
|
|
313
310
|
)
|
|
314
311
|
field_options.add_argument(
|
|
315
|
-
|
|
316
|
-
help=
|
|
312
|
+
"--field-extra-keys-without-x-prefix",
|
|
313
|
+
help="Add extra keys with `x-` prefix to field parameters. The extra keys are stripped of the `x-` prefix.",
|
|
317
314
|
type=str,
|
|
318
|
-
nargs=
|
|
315
|
+
nargs="+",
|
|
319
316
|
)
|
|
320
317
|
field_options.add_argument(
|
|
321
|
-
|
|
322
|
-
help=
|
|
323
|
-
action=
|
|
318
|
+
"--field-include-all-keys",
|
|
319
|
+
help="Add all keys to field parameters",
|
|
320
|
+
action="store_true",
|
|
324
321
|
default=None,
|
|
325
322
|
)
|
|
326
323
|
field_options.add_argument(
|
|
327
|
-
|
|
328
|
-
help=
|
|
329
|
-
action=
|
|
324
|
+
"--force-optional",
|
|
325
|
+
help="Force optional for required fields",
|
|
326
|
+
action="store_true",
|
|
330
327
|
default=None,
|
|
331
328
|
)
|
|
332
329
|
field_options.add_argument(
|
|
333
|
-
|
|
334
|
-
help=
|
|
330
|
+
"--original-field-name-delimiter",
|
|
331
|
+
help="Set delimiter to convert to snake case. This option only can be used with --snake-case-field (default: `_` )",
|
|
335
332
|
default=None,
|
|
336
333
|
)
|
|
337
334
|
field_options.add_argument(
|
|
338
|
-
|
|
339
|
-
help=
|
|
340
|
-
action=
|
|
335
|
+
"--remove-special-field-name-prefix",
|
|
336
|
+
help="Remove field name prefix if it has a special meaning e.g. underscores",
|
|
337
|
+
action="store_true",
|
|
341
338
|
default=None,
|
|
342
339
|
)
|
|
343
340
|
field_options.add_argument(
|
|
344
|
-
|
|
345
|
-
help=
|
|
346
|
-
action=
|
|
341
|
+
"--snake-case-field",
|
|
342
|
+
help="Change camel-case field name to snake-case",
|
|
343
|
+
action="store_true",
|
|
347
344
|
default=None,
|
|
348
345
|
)
|
|
349
346
|
field_options.add_argument(
|
|
350
|
-
|
|
347
|
+
"--special-field-name-prefix",
|
|
351
348
|
help="Set field name prefix when first character can't be used as Python field name (default: `field`)",
|
|
352
349
|
default=None,
|
|
353
350
|
)
|
|
354
351
|
field_options.add_argument(
|
|
355
|
-
|
|
356
|
-
help=
|
|
357
|
-
action=
|
|
352
|
+
"--strip-default-none",
|
|
353
|
+
help="Strip default None on fields",
|
|
354
|
+
action="store_true",
|
|
358
355
|
default=None,
|
|
359
356
|
)
|
|
360
357
|
field_options.add_argument(
|
|
361
|
-
|
|
362
|
-
help=
|
|
363
|
-
action=
|
|
358
|
+
"--use-default",
|
|
359
|
+
help="Use default value even if a field is required",
|
|
360
|
+
action="store_true",
|
|
364
361
|
default=None,
|
|
365
362
|
)
|
|
366
363
|
field_options.add_argument(
|
|
367
|
-
|
|
368
|
-
action=
|
|
369
|
-
help=
|
|
364
|
+
"--use-default-kwarg",
|
|
365
|
+
action="store_true",
|
|
366
|
+
help="Use `default=` instead of a positional argument for Fields that have default values.",
|
|
370
367
|
default=None,
|
|
371
368
|
)
|
|
372
369
|
field_options.add_argument(
|
|
373
|
-
|
|
374
|
-
help=
|
|
375
|
-
action=
|
|
370
|
+
"--use-field-description",
|
|
371
|
+
help="Use schema description to populate field docstring",
|
|
372
|
+
action="store_true",
|
|
376
373
|
default=None,
|
|
377
374
|
)
|
|
378
375
|
field_options.add_argument(
|
|
379
|
-
|
|
380
|
-
help=
|
|
376
|
+
"--union-mode",
|
|
377
|
+
help="Union mode for only pydantic v2 field",
|
|
381
378
|
choices=[u.value for u in UnionMode],
|
|
382
379
|
default=None,
|
|
383
380
|
)
|
|
384
381
|
field_options.add_argument(
|
|
385
|
-
|
|
386
|
-
help="""Do not add a field alias. E.g., if --snake-case-field is used along with a base class, which has an
|
|
382
|
+
"--no-alias",
|
|
383
|
+
help="""Do not add a field alias. E.g., if --snake-case-field is used along with a base class, which has an
|
|
387
384
|
alias_generator""",
|
|
388
|
-
action=
|
|
385
|
+
action="store_true",
|
|
389
386
|
default=None,
|
|
390
387
|
)
|
|
391
388
|
|
|
@@ -393,95 +390,95 @@ field_options.add_argument(
|
|
|
393
390
|
# Options for templating output
|
|
394
391
|
# ======================================================================================
|
|
395
392
|
template_options.add_argument(
|
|
396
|
-
|
|
397
|
-
help=
|
|
398
|
-
type=FileType(
|
|
393
|
+
"--aliases",
|
|
394
|
+
help="Alias mapping file",
|
|
395
|
+
type=FileType("rt"),
|
|
399
396
|
)
|
|
400
397
|
template_options.add_argument(
|
|
401
|
-
|
|
402
|
-
help=
|
|
398
|
+
"--custom-file-header",
|
|
399
|
+
help="Custom file header",
|
|
403
400
|
type=str,
|
|
404
401
|
default=None,
|
|
405
402
|
)
|
|
406
403
|
template_options.add_argument(
|
|
407
|
-
|
|
408
|
-
help=
|
|
404
|
+
"--custom-file-header-path",
|
|
405
|
+
help="Custom file header file path",
|
|
409
406
|
default=None,
|
|
410
407
|
type=str,
|
|
411
408
|
)
|
|
412
409
|
template_options.add_argument(
|
|
413
|
-
|
|
414
|
-
help=
|
|
410
|
+
"--custom-template-dir",
|
|
411
|
+
help="Custom template directory",
|
|
415
412
|
type=str,
|
|
416
413
|
)
|
|
417
414
|
template_options.add_argument(
|
|
418
|
-
|
|
419
|
-
help=f
|
|
415
|
+
"--encoding",
|
|
416
|
+
help=f"The encoding of input and output (default: {DEFAULT_ENCODING})",
|
|
420
417
|
default=None,
|
|
421
418
|
)
|
|
422
419
|
template_options.add_argument(
|
|
423
|
-
|
|
424
|
-
help=
|
|
425
|
-
type=FileType(
|
|
420
|
+
"--extra-template-data",
|
|
421
|
+
help="Extra template data",
|
|
422
|
+
type=FileType("rt"),
|
|
426
423
|
)
|
|
427
424
|
template_options.add_argument(
|
|
428
|
-
|
|
429
|
-
action=
|
|
425
|
+
"--use-double-quotes",
|
|
426
|
+
action="store_true",
|
|
430
427
|
default=None,
|
|
431
|
-
help=
|
|
432
|
-
|
|
428
|
+
help="Model generated with double quotes. Single quotes or "
|
|
429
|
+
"your black config skip_string_normalization value will be used without this option.",
|
|
433
430
|
)
|
|
434
431
|
template_options.add_argument(
|
|
435
|
-
|
|
436
|
-
help=
|
|
437
|
-
action=
|
|
432
|
+
"--wrap-string-literal",
|
|
433
|
+
help="Wrap string literal by using black `experimental-string-processing` option (require black 20.8b0 or later)",
|
|
434
|
+
action="store_true",
|
|
438
435
|
default=None,
|
|
439
436
|
)
|
|
440
437
|
base_options.add_argument(
|
|
441
|
-
|
|
438
|
+
"--additional-imports",
|
|
442
439
|
help='Custom imports for output (delimited list input). For example "datetime.date,datetime.datetime"',
|
|
443
440
|
type=str,
|
|
444
441
|
default=None,
|
|
445
442
|
)
|
|
446
443
|
base_options.add_argument(
|
|
447
|
-
|
|
448
|
-
help=
|
|
444
|
+
"--custom-formatters",
|
|
445
|
+
help="List of modules with custom formatter (delimited list input).",
|
|
449
446
|
type=str,
|
|
450
447
|
default=None,
|
|
451
448
|
)
|
|
452
449
|
template_options.add_argument(
|
|
453
|
-
|
|
454
|
-
help=
|
|
455
|
-
type=FileType(
|
|
450
|
+
"--custom-formatters-kwargs",
|
|
451
|
+
help="A file with kwargs for custom formatters.",
|
|
452
|
+
type=FileType("rt"),
|
|
456
453
|
)
|
|
457
454
|
|
|
458
455
|
# ======================================================================================
|
|
459
456
|
# Options specific to OpenAPI input schemas
|
|
460
457
|
# ======================================================================================
|
|
461
458
|
openapi_options.add_argument(
|
|
462
|
-
|
|
463
|
-
help=
|
|
459
|
+
"--openapi-scopes",
|
|
460
|
+
help="Scopes of OpenAPI model generation (default: schemas)",
|
|
464
461
|
choices=[o.value for o in OpenAPIScope],
|
|
465
|
-
nargs=
|
|
462
|
+
nargs="+",
|
|
466
463
|
default=None,
|
|
467
464
|
)
|
|
468
465
|
openapi_options.add_argument(
|
|
469
|
-
|
|
470
|
-
help=
|
|
471
|
-
action=
|
|
466
|
+
"--strict-nullable",
|
|
467
|
+
help="Treat default field as a non-nullable field (Only OpenAPI)",
|
|
468
|
+
action="store_true",
|
|
472
469
|
default=None,
|
|
473
470
|
)
|
|
474
471
|
openapi_options.add_argument(
|
|
475
|
-
|
|
476
|
-
help=
|
|
477
|
-
action=
|
|
472
|
+
"--use-operation-id-as-name",
|
|
473
|
+
help="use operation id of OpenAPI as class names of models",
|
|
474
|
+
action="store_true",
|
|
478
475
|
default=None,
|
|
479
476
|
)
|
|
480
477
|
openapi_options.add_argument(
|
|
481
|
-
|
|
482
|
-
help=
|
|
483
|
-
|
|
484
|
-
action=
|
|
478
|
+
"--validation",
|
|
479
|
+
help="Deprecated: Enable validation (Only OpenAPI). this option is deprecated. it will be removed in future "
|
|
480
|
+
"releases",
|
|
481
|
+
action="store_true",
|
|
485
482
|
default=None,
|
|
486
483
|
)
|
|
487
484
|
|
|
@@ -489,38 +486,38 @@ openapi_options.add_argument(
|
|
|
489
486
|
# General options
|
|
490
487
|
# ======================================================================================
|
|
491
488
|
general_options.add_argument(
|
|
492
|
-
|
|
493
|
-
help=
|
|
494
|
-
action=
|
|
489
|
+
"--debug",
|
|
490
|
+
help="show debug message (require \"debug\". `$ pip install 'datamodel-code-generator[debug]'`)",
|
|
491
|
+
action="store_true",
|
|
495
492
|
default=None,
|
|
496
493
|
)
|
|
497
494
|
general_options.add_argument(
|
|
498
|
-
|
|
499
|
-
help=
|
|
500
|
-
action=
|
|
495
|
+
"--disable-warnings",
|
|
496
|
+
help="disable warnings",
|
|
497
|
+
action="store_true",
|
|
501
498
|
default=None,
|
|
502
499
|
)
|
|
503
500
|
general_options.add_argument(
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
action=
|
|
507
|
-
default=
|
|
508
|
-
help=
|
|
501
|
+
"-h",
|
|
502
|
+
"--help",
|
|
503
|
+
action="help",
|
|
504
|
+
default="==SUPPRESS==",
|
|
505
|
+
help="show this help message and exit",
|
|
509
506
|
)
|
|
510
507
|
general_options.add_argument(
|
|
511
|
-
|
|
512
|
-
action=
|
|
508
|
+
"--no-color",
|
|
509
|
+
action="store_true",
|
|
513
510
|
default=False,
|
|
514
|
-
help=
|
|
511
|
+
help="disable colorized output",
|
|
515
512
|
)
|
|
516
513
|
general_options.add_argument(
|
|
517
|
-
|
|
518
|
-
action=
|
|
519
|
-
help=
|
|
514
|
+
"--version",
|
|
515
|
+
action="store_true",
|
|
516
|
+
help="show version",
|
|
520
517
|
)
|
|
521
518
|
|
|
522
519
|
__all__ = [
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
520
|
+
"DEFAULT_ENCODING",
|
|
521
|
+
"arg_parser",
|
|
522
|
+
"namespace",
|
|
526
523
|
]
|