You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add --external-ref-mapping to import from external packages instead of generating (#3006)
* feat: Add --external-ref-mapping CLI option and config plumbing
Add a new --external-ref-mapping option that maps external $ref file
paths to Python import packages. When a $ref points to a mapped file,
an import statement is generated instead of a duplicate class definition.
This commit adds the option to the CLI argument parser, Config class,
GenerateConfig, ParserConfig, and their TypedDict counterparts. No
behavior change yet — the core logic follows in the next commit.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: Implement external ref mapping in JSON Schema parser
When --external-ref-mapping is provided, external $ref targets that
match a mapped file produce import-based DataTypes (via Import.from_full_path
and DataType.from_import) instead of loading and parsing the external file.
This follows the exact same pattern as the existing x-python-import
vendor extension, but configured externally via CLI rather than requiring
modifications to the schema YAML.
Three changes in jsonschema.py:
- __init__: normalize mapping file paths to absolute for reliable matching
- get_ref_data_type: check mapping before _load_ref_schema_object
- resolve_ref: skip loading/parsing for mapped external files
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: Add tests for --external-ref-mapping feature
Five test cases covering:
- Basic CLI usage: external refs produce imports, not class definitions
- No duplicate classes: mapped types are imported, not generated
- Regression: without the flag, behavior is unchanged
- Invalid format: missing '=' in mapping produces a clear error
- Programmatic API: GenerateConfig with external_ref_mapping dict
Test fixtures: api.yaml referencing common.yaml via $ref, with
expected output showing imports from the mapped package.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: Correct help text for --external-ref-mapping
With nargs="+", multiple mappings are passed after a single flag
invocation, not by repeating the flag. Updated help text to reflect this.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: resolve PR3006 CI and nested external ref mapping
* fix: address external-ref-mapping review feedback
* fix: validate non-empty external-ref-mapping pairs
* test: use assert helper for external ref mapping errors
* test: move external ref mapping cases into main openapi e2e
* test: fix absolute ref template for Windows yaml parsing
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Koudai Aono <koxudaxi@gmail.com>
0 commit comments