Skip to content

Commit d0f64f1

Browse files
authored
Fix CLI doc option_description errors in tests and build script (#2846)
1 parent 19f1fb7 commit d0f64f1

8 files changed

Lines changed: 81 additions & 44 deletions

File tree

docs/cli-reference/general-options.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
| [`--ignore-pyproject`](#ignore-pyproject) | Ignore pyproject.toml configuration file. |
1818
| [`--module-split-mode`](#module-split-mode) | Split generated models into separate files, one per model cl... |
1919
| [`--shared-module-name`](#shared-module-name) | Customize the name of the shared module for deduplicated mod... |
20-
| [`--watch`](#watch) | Watch mode cannot be used with --check mode. |
21-
| [`--watch-delay`](#watch-delay) | Watch mode starts file watcher and handles clean exit. |
20+
| [`--watch`](#watch) | Watch input file(s) for changes and regenerate output automa... |
21+
| [`--watch-delay`](#watch-delay) | Set debounce delay in seconds for watch mode. |
2222

2323
---
2424

@@ -1905,11 +1905,12 @@ Note: This option only affects modular output with tree-level model reuse.
19051905

19061906
## `--watch` {#watch}
19071907

1908-
Watch mode cannot be used with --check mode.
1908+
Watch input file(s) for changes and regenerate output automatically.
19091909

1910-
The `--watch` flag enables file watching for automatic regeneration.
1911-
It cannot be combined with `--check` since check mode requires a single
1912-
comparison, not continuous watching.
1910+
The `--watch` flag enables continuous file monitoring mode. When enabled,
1911+
datamodel-codegen watches the input file or directory for changes and
1912+
automatically regenerates the output whenever changes are detected.
1913+
Press Ctrl+C to stop watching.
19131914

19141915
!!! tip "Usage"
19151916

@@ -1919,6 +1920,14 @@ comparison, not continuous watching.
19191920

19201921
1. :material-arrow-left: `--watch` - the option documented here
19211922

1923+
!!! warning "Requires extra dependency"
1924+
1925+
The watch feature requires the `watch` extra:
1926+
1927+
```bash
1928+
pip install 'datamodel-code-generator[watch]'
1929+
```
1930+
19221931
??? example "Examples"
19231932

19241933
=== "JSON Schema"
@@ -1972,12 +1981,14 @@ comparison, not continuous watching.
19721981

19731982
## `--watch-delay` {#watch-delay}
19741983

1975-
Watch mode starts file watcher and handles clean exit.
1984+
Set debounce delay in seconds for watch mode.
1985+
1986+
The `--watch-delay` option configures the debounce interval (default: 0.5 seconds)
1987+
for watch mode. This prevents multiple regenerations when files are rapidly
1988+
modified in succession. The delay ensures that after the last file change,
1989+
the generator waits the specified time before regenerating.
19761990

1977-
The `--watch` flag starts a file watcher that monitors the input file
1978-
or directory for changes. The `--watch-delay` option sets the debounce
1979-
delay in seconds (default: 0.5) to prevent multiple regenerations for
1980-
rapid file changes. Press Ctrl+C to stop watching.
1991+
**Related:** [`--watch`](general-options.md#watch)
19811992

19821993
!!! tip "Usage"
19831994

docs/cli-reference/quick-reference.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ datamodel-codegen [OPTIONS]
4545
| [`--use-generic-container-types`](typing-customization.md#use-generic-container-types) | Use generic container types (Sequence, Mapping) for type hinting. |
4646
| [`--use-non-positive-negative-number-constrained-types`](typing-customization.md#use-non-positive-negative-number-constrained-types) | Use NonPositive/NonNegative types for number constraints. |
4747
| [`--use-pendulum`](typing-customization.md#use-pendulum) | Use pendulum types for date/time fields instead of datetime module. |
48-
| [`--use-root-model-type-alias`](typing-customization.md#use-root-model-type-alias) | Generate RootModel as type alias format for better mypy support (issue #1903). |
48+
| [`--use-root-model-type-alias`](typing-customization.md#use-root-model-type-alias) | Generate RootModel as type alias format for better mypy support. |
4949
| [`--use-specialized-enum`](typing-customization.md#use-specialized-enum) | Generate StrEnum/IntEnum for string/integer enums (Python 3.11+). |
5050
| [`--use-standard-collections`](typing-customization.md#use-standard-collections) | Use built-in dict/list instead of typing.Dict/List. |
5151
| [`--use-standard-primitive-types`](typing-customization.md#use-standard-primitive-types) | Use Python standard library types for string formats instead of str. |
@@ -173,15 +173,15 @@ datamodel-codegen [OPTIONS]
173173
| [`--ignore-pyproject`](general-options.md#ignore-pyproject) | Ignore pyproject.toml configuration file. |
174174
| [`--module-split-mode`](general-options.md#module-split-mode) | Split generated models into separate files, one per model class. |
175175
| [`--shared-module-name`](general-options.md#shared-module-name) | Customize the name of the shared module for deduplicated models. |
176-
| [`--watch`](general-options.md#watch) | Watch mode cannot be used with --check mode. |
177-
| [`--watch-delay`](general-options.md#watch-delay) | Watch mode starts file watcher and handles clean exit. |
176+
| [`--watch`](general-options.md#watch) | Watch input file(s) for changes and regenerate output automatically. |
177+
| [`--watch-delay`](general-options.md#watch-delay) | Set debounce delay in seconds for watch mode. |
178178

179179
### 📝 Utility Options
180180

181181
| Option | Description |
182182
|--------|-------------|
183183
| [`--debug`](utility-options.md#debug) | Show debug messages during code generation |
184-
| [`--generate-prompt`](utility-options.md#generate-prompt) | |
184+
| [`--generate-prompt`](utility-options.md#generate-prompt) | Generate a prompt for consulting LLMs about CLI options |
185185
| [`--help`](utility-options.md#help) | Show help message and exit |
186186
| [`--no-color`](utility-options.md#no-color) | Disable colorized output |
187187
| [`--profile`](utility-options.md#profile) | Use a named profile from pyproject.toml |
@@ -239,7 +239,7 @@ All options sorted alphabetically:
239239
- [`--formatters`](template-customization.md#formatters) - Specify code formatters to apply to generated output.
240240
- [`--frozen-dataclasses`](model-customization.md#frozen-dataclasses) - Generate frozen dataclasses with optional keyword-only field...
241241
- [`--generate-cli-command`](general-options.md#generate-cli-command) - Generate CLI command from pyproject.toml configuration.
242-
- [`--generate-prompt`](utility-options.md#generate-prompt) -
242+
- [`--generate-prompt`](utility-options.md#generate-prompt) - Generate a prompt for consulting LLMs about CLI options
243243
- [`--generate-pyproject-config`](general-options.md#generate-pyproject-config) - Generate pyproject.toml configuration from CLI arguments.
244244
- [`--help`](utility-options.md#help) - Show help message and exit
245245
- [`--http-headers`](general-options.md#http-headers) - Fetch schema from URL with custom HTTP headers.
@@ -325,6 +325,6 @@ All options sorted alphabetically:
325325
- [`--use-unique-items-as-set`](typing-customization.md#use-unique-items-as-set) - Generate set types for arrays with uniqueItems constraint.
326326
- [`--validation`](openapi-only-options.md#validation) - Enable validation constraints (deprecated, use --field-const...
327327
- [`--version`](utility-options.md#version) - Show program version and exit
328-
- [`--watch`](general-options.md#watch) - Watch mode cannot be used with --check mode.
329-
- [`--watch-delay`](general-options.md#watch-delay) - Watch mode starts file watcher and handles clean exit.
328+
- [`--watch`](general-options.md#watch) - Watch input file(s) for changes and regenerate output automa...
329+
- [`--watch-delay`](general-options.md#watch-delay) - Set debounce delay in seconds for watch mode.
330330
- [`--wrap-string-literal`](template-customization.md#wrap-string-literal) - Wrap long string literals across multiple lines.

docs/cli-reference/typing-customization.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3305,7 +3305,10 @@ working with the pendulum library for enhanced timezone and date handling.
33053305

33063306
## `--use-root-model-type-alias` {#use-root-model-type-alias}
33073307

3308-
Generate RootModel as type alias format for better mypy support (issue #1903).
3308+
Generate RootModel as type alias format for better mypy support.
3309+
3310+
When enabled, root models with simple types are generated as type aliases
3311+
instead of class definitions, improving mypy type inference.
33093312

33103313
!!! tip "Usage"
33113314

docs/cli-reference/utility-options.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
| Option | Description |
66
|--------|-------------|
77
| [`--debug`](#debug) | Show debug messages during code generation |
8-
| [`--generate-prompt`](#generate-prompt) | |
8+
| [`--generate-prompt`](#generate-prompt) | Generate a prompt for consulting LLMs about CLI options |
99
| [`--help`](#help) | Show help message and exit |
1010
| [`--no-color`](#no-color) | Disable colorized output |
1111
| [`--profile`](#profile) | Use a named profile from pyproject.toml |
@@ -46,7 +46,7 @@ Outputs a formatted prompt containing your current options, all available
4646
options by category, and full help text. Pipe to CLI LLM tools or copy
4747
to clipboard for web-based LLM chats.
4848

49-
**See also:** [LLM Integration](../../llm-integration.md) for detailed usage examples
49+
**See also:** [LLM Integration](../llm-integration.md) for detailed usage examples
5050

5151
!!! tip "Usage"
5252

@@ -139,7 +139,7 @@ Use a named profile from pyproject.toml configuration.
139139
Profiles allow you to define multiple named configurations in your pyproject.toml
140140
file. Each profile can override the default settings with its own set of options.
141141

142-
**Related:** [pyproject.toml Configuration](../../pyproject_toml.md)
142+
**Related:** [pyproject.toml Configuration](../pyproject_toml.md)
143143

144144
!!! tip "Usage"
145145

scripts/build_cli_docs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ def get_unique_schema_types(self) -> list[str]:
179179
"--debug": "Show debug messages during code generation",
180180
"--profile": "Use a named profile from pyproject.toml",
181181
"--no-color": "Disable colorized output",
182+
"--generate-prompt": "Generate a prompt for consulting LLMs about CLI options",
182183
}
183184

184185
# Regex pattern for detecting MkDocs Material admonitions in docstrings
@@ -907,6 +908,9 @@ def generate_manual_docs_section(manual_docs: dict[str, str]) -> str:
907908

908909
for option in sorted(manual_docs.keys()):
909910
content = manual_docs[option]
911+
# Adjust relative paths: manual docs are in manual/ subdirectory,
912+
# but utility-options.md is in cli-reference/, so ../../ becomes ../
913+
content = content.replace("](../../", "](../")
910914
md += content
911915
if not content.endswith("\n"):
912916
md += "\n"

src/datamodel_code_generator/prompt_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
"--use-one-literal-as-default": "Use single literal value as default when enum has only one option.",
120120
"--use-operation-id-as-name": "Use OpenAPI operationId as the generated function/class name.",
121121
"--use-pendulum": "Use pendulum types for date/time fields instead of datetime module.",
122-
"--use-root-model-type-alias": "Generate RootModel as type alias format for better mypy support (issue #1903).",
122+
"--use-root-model-type-alias": "Generate RootModel as type alias format for better mypy support.",
123123
"--use-schema-description": "Use schema description as class docstring.",
124124
"--use-serialize-as-any": "Wrap fields with subtypes in Pydantic's SerializeAsAny.",
125125
"--use-specialized-enum": "Generate StrEnum/IntEnum for string/integer enums (Python 3.11+).",
@@ -133,7 +133,7 @@
133133
"--use-union-operator": "Use | operator for Union types (PEP 604).",
134134
"--use-unique-items-as-set": "Generate set types for arrays with uniqueItems constraint.",
135135
"--validation": "Enable validation constraints (deprecated, use --field-constraints).",
136-
"--watch": "Watch mode cannot be used with --check mode.",
137-
"--watch-delay": "Watch mode starts file watcher and handles clean exit.",
136+
"--watch": "Watch input file(s) for changes and regenerate output automatically.",
137+
"--watch-delay": "Set debounce delay in seconds for watch mode.",
138138
"--wrap-string-literal": "Wrap long string literals across multiple lines.",
139139
}

tests/main/jsonschema/test_main_jsonschema.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5485,7 +5485,11 @@ def test_main_jsonschema_empty_items_array(output_file: Path) -> None:
54855485

54865486
@pytest.mark.cli_doc(
54875487
options=["--aliases"],
5488-
option_description="""Test hierarchical aliases with scoped format (ClassName.field).""",
5488+
option_description="""Apply custom field and class name aliases from JSON file.
5489+
5490+
The `--aliases` option allows renaming fields and classes via a JSON mapping file,
5491+
providing fine-grained control over generated names independent of schema definitions.
5492+
Supports scoped format (ClassName.field) for hierarchical aliasing.""",
54895493
input_schema="jsonschema/hierarchical_aliases.json",
54905494
cli_args=["--aliases", "aliases/hierarchical_aliases_scoped.json"],
54915495
golden_output="jsonschema/jsonschema_hierarchical_aliases_scoped.py",
@@ -5960,12 +5964,11 @@ def test_main_jsonschema_ref_with_additional_keywords(output_dir: Path) -> None:
59605964
)
59615965
@pytest.mark.cli_doc(
59625966
options=["--output-model-type"],
5963-
option_description="""Test reserved field name handling across model types (Issue #1833).
5967+
option_description="""Select the output model type (Pydantic v1/v2, dataclasses, TypedDict, msgspec).
59645968
5965-
This demonstrates how 'schema' field is handled:
5966-
- TypedDict: not renamed (schema is not reserved)
5967-
- dataclass: not renamed (schema is not reserved)
5968-
- Pydantic: renamed to 'schema_' with alias (BaseModel.schema conflicts)""",
5969+
The `--output-model-type` flag specifies which Python data model framework to use.
5970+
Each model type has different handling for reserved field names like 'schema':
5971+
TypedDict and dataclass preserve the name, while Pydantic renames with alias.""",
59695972
input_schema="jsonschema/reserved_field_name_schema.json",
59705973
cli_args=["--target-python-version", "3.11"],
59715974
model_outputs={
@@ -6833,7 +6836,10 @@ def test_main_parent_scoped_naming_backward_compat(output_file: Path) -> None:
68336836

68346837
@pytest.mark.cli_doc(
68356838
options=["--use-root-model-type-alias"],
6836-
option_description="""Generate RootModel as type alias format for better mypy support (issue #1903).""",
6839+
option_description="""Generate RootModel as type alias format for better mypy support.
6840+
6841+
When enabled, root models with simple types are generated as type aliases
6842+
instead of class definitions, improving mypy type inference.""",
68376843
input_schema="jsonschema/root_model_type_alias.json",
68386844
cli_args=["--use-root-model-type-alias", "--output-model-type", "pydantic_v2.BaseModel"],
68396845
golden_output="jsonschema/root_model_type_alias.py",

tests/main/test_main_watch.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,24 @@
1616

1717
@pytest.mark.cli_doc(
1818
options=["--watch"],
19-
option_description="""Watch mode cannot be used with --check mode.
19+
option_description="""Watch input file(s) for changes and regenerate output automatically.
2020
21-
The `--watch` flag enables file watching for automatic regeneration.
22-
It cannot be combined with `--check` since check mode requires a single
23-
comparison, not continuous watching.""",
21+
The `--watch` flag enables continuous file monitoring mode. When enabled,
22+
datamodel-codegen watches the input file or directory for changes and
23+
automatically regenerates the output whenever changes are detected.
24+
Press Ctrl+C to stop watching.
25+
26+
!!! warning "Requires extra dependency"
27+
28+
The watch feature requires the `watch` extra:
29+
30+
```bash
31+
pip install 'datamodel-code-generator[watch]'
32+
```""",
2433
input_schema="jsonschema/person.json",
2534
cli_args=["--watch", "--check"],
2635
expected_stdout="Error: --watch and --check cannot be used together",
36+
primary=True,
2737
)
2838
def test_watch_with_check_error(output_file: Path) -> None:
2939
"""Watch mode cannot be used with --check mode.
@@ -48,10 +58,11 @@ def test_watch_with_check_error(output_file: Path) -> None:
4858

4959
@pytest.mark.cli_doc(
5060
options=["--watch"],
51-
option_description="""Watch mode requires a file path input, not a URL.
61+
option_description="""Watch input file(s) for changes and regenerate output automatically.
5262
53-
The `--watch` flag monitors local files for changes. It cannot be used
54-
with `--url` since remote URLs cannot be watched for changes.""",
63+
The `--watch` flag monitors local files for changes. It requires a local file
64+
path via `--input` and cannot be used with `--url` since remote URLs cannot
65+
be watched for changes.""",
5566
cli_args=["--watch", "--url", "https://example.com/schema.json"],
5667
expected_stdout="Error: --watch requires --input file path",
5768
)
@@ -122,12 +133,14 @@ def test_get_watchfiles_success() -> None:
122133

123134
@pytest.mark.cli_doc(
124135
options=["--watch", "--watch-delay"],
125-
option_description="""Watch mode starts file watcher and handles clean exit.
136+
option_description="""Set debounce delay in seconds for watch mode.
137+
138+
The `--watch-delay` option configures the debounce interval (default: 0.5 seconds)
139+
for watch mode. This prevents multiple regenerations when files are rapidly
140+
modified in succession. The delay ensures that after the last file change,
141+
the generator waits the specified time before regenerating.
126142
127-
The `--watch` flag starts a file watcher that monitors the input file
128-
or directory for changes. The `--watch-delay` option sets the debounce
129-
delay in seconds (default: 0.5) to prevent multiple regenerations for
130-
rapid file changes. Press Ctrl+C to stop watching.""",
143+
**Related:** [`--watch`](general-options.md#watch)""",
131144
input_schema="jsonschema/person.json",
132145
cli_args=["--watch", "--watch-delay", "1.5"],
133146
expected_stdout="Watching",

0 commit comments

Comments
 (0)