Skip to content

Update using_as_module.md to document config parameter#2879

Merged
koxudaxi merged 2 commits intomainfrom
docs/update-using-as-module-config-parameter
Dec 30, 2025
Merged

Update using_as_module.md to document config parameter#2879
koxudaxi merged 2 commits intomainfrom
docs/update-using-as-module-config-parameter

Conversation

@koxudaxi
Copy link
Copy Markdown
Owner

@koxudaxi koxudaxi commented Dec 30, 2025

Summary by CodeRabbit

  • New Features

    • Introduced GenerateConfig and JSONSchemaParserConfig classes for more flexible module-based code generation configuration.
  • Documentation

    • Updated usage documentation with examples of the new config-driven approach for generators and parsers.
    • Added reference section for available parser configuration classes.
    • Maintained backward-compatible keyword-arguments examples for existing workflows.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 30, 2025

📝 Walkthrough

Walkthrough

Documentation updated to demonstrate a config-driven API using GenerateConfig and parser-specific config classes alongside backward-compatible keyword arguments. New public exports added for GenerateConfig and JSONSchemaParserConfig. Examples show usage patterns for single-module and multi-module generation scenarios.

Changes

Cohort / File(s) Summary
Documentation Update
docs/using_as_module.md
Updated code examples to demonstrate GenerateConfig-based approach for module usage; added GenerateConfig and JSONSchemaParserConfig imports in examples; introduced "Available Parser Config Classes" section mapping parsers to their config classes; maintained backward-compatible keyword-arguments approach alongside new config-driven patterns.
Public API Exports
datamodel_code_generator (module exports)
Added public export of GenerateConfig class for module-based code generation configuration.
Parser Config Exports
datamodel_code_generator.config (module exports)
Added public export of JSONSchemaParserConfig class for parser-specific configuration.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 Config objects hop with grace,
Replacing args in their place,
Backward-compat still survives,
Keeping old code's lives,
Parsers dance in cleaner ways,
Configuring brighter days!

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: updating documentation to document the config parameter for the using_as_module.md file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 30, 2025

📚 Docs Preview: https://pr-2879.datamodel-code-generator.pages.dev

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Dec 30, 2025

CodSpeed Performance Report

Merging #2879 will not alter performance

Comparing docs/update-using-as-module-config-parameter (1693d02) with main (9ef026e)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 11 untouched
⏩ 98 skipped1

Footnotes

  1. 98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.38%. Comparing base (9ef026e) to head (1693d02).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2879   +/-   ##
=======================================
  Coverage   99.38%   99.38%           
=======================================
  Files          91       91           
  Lines       15648    15648           
  Branches     1849     1849           
=======================================
  Hits        15552    15552           
  Misses         50       50           
  Partials       46       46           
Flag Coverage Δ
unittests 99.38% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@koxudaxi koxudaxi merged commit 7486e2a into main Dec 30, 2025
33 of 34 checks passed
@koxudaxi koxudaxi deleted the docs/update-using-as-module-config-parameter branch December 30, 2025 23:44
@github-actions
Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR (#2879) is a documentation-only change that updates docs/using_as_module.md to document the new config parameter pattern introduced in previous PRs (#2874, #2877, #2878). The PR modifies only the documentation file with 62 insertions and 12 deletions, showing the new GenerateConfig and parser config class patterns. The documentation explicitly maintains backward-compatible keyword argument examples, confirming the old API still works. Since no source code was changed in this PR - only documentation was updated - there are no breaking changes to code generation output, templates, API/CLI, defaults, Python version support, or error handling.


This analysis was performed by Claude Code Action

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/using_as_module.md (1)

130-167: Ensure clarity on recommended vs. backward-compatible approaches.

The section now shows two approaches: config-based (recommended) and keyword-arguments (backward compatible). Both subsections use the same code output, which may be confusing. Consider clarifying that both approaches produce identical results.

The output section at line 215-236 could benefit from a brief note indicating that both code examples above it produce the same result, reinforcing that this is an API compatibility choice, not a functional difference.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ef026e and 1693d02.

📒 Files selected for processing (1)
  • docs/using_as_module.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: py312-pydantic1 on Ubuntu
  • GitHub Check: 3.10 on Ubuntu
  • GitHub Check: 3.11 on macOS
  • GitHub Check: 3.13 on macOS
  • GitHub Check: py312-isort5 on Ubuntu
  • GitHub Check: py312-isort6 on Ubuntu
  • GitHub Check: 3.13 on Ubuntu
  • GitHub Check: 3.10 on Windows
  • GitHub Check: 3.13 on Windows
  • GitHub Check: 3.11 on Windows
  • GitHub Check: 3.14 on Windows
  • GitHub Check: 3.12 on Windows
  • GitHub Check: Analyze (python)
  • GitHub Check: benchmarks
🔇 Additional comments (3)
docs/using_as_module.md (3)

164-164: Both parser initialization patterns are correctly supported. The JsonSchemaParser constructor accepts the config parameter as documented at line 164, and also supports keyword-argument-based initialization (e.g., data_model_type, data_model_root_type) as shown at line 191. The patterns are mutually exclusive by design—the base Parser class validates that you cannot mix them simultaneously.


203-213: Parser config classes table is complete and accurate.

The table at lines 207-211 correctly documents all available parsers and their corresponding config classes: JsonSchemaParser/JSONSchemaParserConfig, OpenAPIParser/OpenAPIParserConfig, and GraphQLParser/GraphQLParserConfig. No additional parsers exist in the codebase.


33-37: No issues found. All config instantiation patterns in the documentation match the actual class definitions. Parameter names and types are correct for all examples (lines 33-37, 53-55, 90-96, and 157-163).

Comment thread docs/using_as_module.md

```python
from datamodel_code_generator import InputFileType, generate, DataModelType
from datamodel_code_generator import InputFileType, generate, GenerateConfig, DataModelType
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# Check if GenerateConfig is exported from the main module
echo "=== Checking GenerateConfig in datamodel_code_generator/__init__.py ==="
cat datamodel_code_generator/__init__.py | grep -n "GenerateConfig"

# Check for JSONSchemaParserConfig
echo ""
echo "=== Checking JSONSchemaParserConfig ==="
rg "class JSONSchemaParserConfig" --type python

# Check for GeneratedModules
echo ""
echo "=== Checking GeneratedModules ==="
rg "class GeneratedModules|GeneratedModules" --type python | head -20

# Check for get_data_model_types
echo ""
echo "=== Checking get_data_model_types ==="
rg "def get_data_model_types" --type python

# List what's actually exported from __init__.py
echo ""
echo "=== Checking __all__ in datamodel_code_generator/__init__.py ==="
grep "__all__" datamodel_code_generator/__init__.py -A 50

Repository: koxudaxi/datamodel-code-generator

Length of output: 163


🏁 Script executed:

# Check key imports with specific line limits
echo "=== GenerateConfig in __init__.py ==="
rg "GenerateConfig" datamodel_code_generator/__init__.py --max-count=5

echo ""
echo "=== JSONSchemaParserConfig location ==="
rg "class JSONSchemaParserConfig" --type python --max-count=5

echo ""
echo "=== GeneratedModules location ==="
rg "class GeneratedModules" --type python --max-count=5

echo ""
echo "=== get_data_model_types location ==="
rg "def get_data_model_types" --type python --max-count=5

echo ""
echo "=== Checking __init__.py __all__ export list ==="
rg "^__all__" datamodel_code_generator/__init__.py -A 30 --max-count=1

Repository: koxudaxi/datamodel-code-generator

Length of output: 543


🏁 Script executed:

# Find the datamodel_code_generator module
echo "=== Locating datamodel_code_generator module ==="
fd -t d "datamodel_code_generator" | head -5

# List top-level directory structure
echo ""
echo "=== Repository root structure ==="
ls -la | head -20

# Find __init__.py files
echo ""
echo "=== Finding __init__.py files ==="
fd "__init__\.py" | grep datamodel | head -10

Repository: koxudaxi/datamodel-code-generator

Length of output: 1638


🏁 Script executed:

# Check main __init__.py for exports
echo "=== Checking src/datamodel_code_generator/__init__.py ==="
head -100 src/datamodel_code_generator/__init__.py | grep -E "GenerateConfig|GeneratedModules|__all__|import"

echo ""
echo "=== Searching for GenerateConfig definition ==="
rg "class GenerateConfig|^GenerateConfig" src/ --max-count=5

echo ""
echo "=== Searching for JSONSchemaParserConfig ==="
rg "class JSONSchemaParserConfig" src/ --max-count=5

echo ""
echo "=== Searching for GeneratedModules ==="
rg "class GeneratedModules" src/ --max-count=5

echo ""
echo "=== Searching for get_data_model_types ==="
rg "def get_data_model_types" src/ --max-count=5

Repository: koxudaxi/datamodel-code-generator

Length of output: 1765


🏁 Script executed:

# Check __all__ in main __init__.py
echo "=== Checking __all__ in main __init__.py ==="
rg "^__all__" src/datamodel_code_generator/__init__.py -A 50

echo ""
echo "=== Checking if JSONSchemaParserConfig is in main __init__.py imports ==="
grep -n "JSONSchemaParserConfig" src/datamodel_code_generator/__init__.py

echo ""
echo "=== Check what the docs file actually imports on line 20 ==="
sed -n '15,25p' docs/using_as_module.md

echo ""
echo "=== Check imports on other lines mentioned (47, 74, 138) ==="
sed -n '42,52p' docs/using_as_module.md
echo "---"
sed -n '69,79p' docs/using_as_module.md
echo "---"
sed -n '133,143p' docs/using_as_module.md

Repository: koxudaxi/datamodel-code-generator

Length of output: 2697


🏁 Script executed:

# Check for DataModelType
echo "=== Searching for DataModelType ==="
rg "class DataModelType|DataModelType.*=" src/datamodel_code_generator/__init__.py | head -10

echo ""
echo "=== Check full imports in main __init__.py that aren't in __all__ ==="
rg "^from|^import" src/datamodel_code_generator/__init__.py | grep -E "GenerateConfig|DataModelType" | head -10

echo ""
echo "=== Check what DataModelType actually is ==="
rg "class DataModelType|DataModelType\s*=" src/ --max-count=10

Repository: koxudaxi/datamodel-code-generator

Length of output: 883


🏁 Script executed:

# Get full imports section from main __init__.py
echo "=== Full import section of main __init__.py ==="
head -80 src/datamodel_code_generator/__init__.py | tail -40

echo ""
echo "=== Check if DataModelType is imported in main ==="
grep "DataModelType" src/datamodel_code_generator/__init__.py

echo ""
echo "=== Check full __all__ list to confirm ==="
grep -A 50 "^__all__" src/datamodel_code_generator/__init__.py | grep -E "DataModelType|GenerateConfig"

Repository: koxudaxi/datamodel-code-generator

Length of output: 1775


🏁 Script executed:

# Check the enums import in main __init__.py more carefully
echo "=== Check enums imports in main __init__.py ==="
rg "from datamodel_code_generator.enums import" src/datamodel_code_generator/__init__.py -A 15

echo ""
echo "=== Verify GenerateConfig is ONLY in TYPE_CHECKING ==="
grep -n "GenerateConfig" src/datamodel_code_generator/__init__.py

echo ""
echo "=== Check if there's runtime import of GenerateConfig elsewhere ==="
head -150 src/datamodel_code_generator/__init__.py | grep -n "GenerateConfig"

Repository: koxudaxi/datamodel-code-generator

Length of output: 183


🏁 Script executed:

# Simple check: Can these be imported at runtime?
echo "=== Check DataModelType in main __init__.py (first 100 lines) ==="
head -100 src/datamodel_code_generator/__init__.py | grep -n "DataModelType"

echo ""
echo "=== Count GenerateConfig occurrences and context ==="
grep -B2 -A2 "GenerateConfig" src/datamodel_code_generator/__init__.py | head -20

echo ""
echo "=== Check if DataModelType is in the enums import ==="
sed -n '1,50p' src/datamodel_code_generator/__init__.py | grep -A 20 "from datamodel_code_generator.enums"

Repository: koxudaxi/datamodel-code-generator

Length of output: 183


🏁 Script executed:

# Read first part of __init__.py to find all imports
wc -l src/datamodel_code_generator/__init__.py

# Read lines 1-50 to see initial imports
echo "=== Lines 1-50 ==="
sed -n '1,50p' src/datamodel_code_generator/__init__.py

# Then check around the TYPE_CHECKING section
echo ""
echo "=== Search for TYPE_CHECKING section ==="
grep -n "TYPE_CHECKING" src/datamodel_code_generator/__init__.py

Repository: koxudaxi/datamodel-code-generator

Length of output: 183


🏁 Script executed:

python3 << 'EOF'
import sys

# Read the main __init__.py file
with open('src/datamodel_code_generator/__init__.py', 'r') as f:
    lines = f.readlines()

# Find TYPE_CHECKING import block
print("=== Checking TYPE_CHECKING block for GenerateConfig ===")
in_type_checking = False
for i, line in enumerate(lines[:100], 1):
    if 'TYPE_CHECKING' in line:
        in_type_checking = True
        print(f"Line {i}: {line.rstrip()}")
    elif in_type_checking:
        print(f"Line {i}: {line.rstrip()}")
        if 'GenerateConfig' in line:
            print("  ^^^ GenerateConfig found in TYPE_CHECKING block")
        if line.strip() == '' or (line[0] not in ' \t' and 'import' not in line):
            in_type_checking = False

# Check if DataModelType is imported outside TYPE_CHECKING
print("\n=== Checking for DataModelType in runtime imports ===")
for i, line in enumerate(lines[:100], 1):
    if 'DataModelType' in line and 'TYPE_CHECKING' not in line:
        print(f"Line {i}: {line.rstrip()}")
EOF

Repository: koxudaxi/datamodel-code-generator

Length of output: 183


🏁 Script executed:

# Try very simple file size check first
stat src/datamodel_code_generator/__init__.py

# Then use cat with head
cat src/datamodel_code_generator/__init__.py | head -80

Repository: koxudaxi/datamodel-code-generator

Length of output: 183


🌐 Web query:

datamodel-code-generator GenerateConfig public API export import

💡 Result:

I’m not sure what you mean by “GenerateConfig” in the context of datamodel-code-generator. Do you mean:

  • the CLI/module generate function and its config/options (using datamodel_code_generator.generate or CLI flags), or
  • a specific class named GenerateConfig in another library, or
  • exporting/importing a saved configuration (e.g., pyproject.toml / CLI flags) for datamodel-code-generator?

Tell me which one and I’ll give exact import/export code or commands (and examples).


Fix import path for GenerateConfig in documentation examples (lines 20, 47, 74, 138).

GenerateConfig cannot be imported from the main datamodel_code_generator module at runtime—it is only available for type checking. Update all documentation examples to import from the config submodule:

from datamodel_code_generator.config import GenerateConfig

instead of:

from datamodel_code_generator import GenerateConfig

The imports for JSONSchemaParserConfig (from datamodel_code_generator.config) and get_data_model_types (from datamodel_code_generator.model) are correct. GeneratedModules is also correctly exported from the main module.

🤖 Prompt for AI Agents
In docs/using_as_module.md around line 20 (and also update lines 47, 74, 138),
the examples import GenerateConfig from the top-level package which only exposes
it for type checking; change those imports to import GenerateConfig from the
config submodule (i.e., use from datamodel_code_generator.config import
GenerateConfig) so the examples work at runtime—leave other imports
(JSONSchemaParserConfig, get_data_model_types, GeneratedModules) as they are.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 1, 2026

🎉 Released in 0.51.0

This PR is now available in the latest release. See the release notes for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant