Feature/oneof unique subtypes naming #58

Merged
HideyoshiNakazone merged 2 commits from feature/oneof-unique-subtypes-naming into main 2025-11-24 01:11:01 +00:00
HideyoshiNakazone commented 2025-11-24 01:10:54 +00:00 (Migrated from github.com)

Solves #55


This pull request updates how subtypes are named when parsing anyOf and oneOf constructs in JSON schemas, ensuring that each generated subtype has a unique name. This change improves type clarity and avoids potential naming collisions in generated models. Additionally, a new test verifies that subtypes created from a oneOf schema have distinct names.

Improvements to subtype naming in parsers:

  • Modified both AnyOfTypeParser and OneOfTypeParser to generate unique subtype names by appending an index to the base name (e.g., name_sub0, name_sub1) when parsing subtypes from the schema. [1] [2]

Test enhancements:

  • Added a new test test_scoped_ref_schema to tests/test_schema_converter.py that verifies subtypes generated from a oneOf schema have different names, preventing type name conflicts.
  • Updated test imports to include JSONSchema and get_args for improved type handling in test cases.
Solves #55 --- This pull request updates how subtypes are named when parsing `anyOf` and `oneOf` constructs in JSON schemas, ensuring that each generated subtype has a unique name. This change improves type clarity and avoids potential naming collisions in generated models. Additionally, a new test verifies that subtypes created from a `oneOf` schema have distinct names. ### Improvements to subtype naming in parsers: * Modified both `AnyOfTypeParser` and `OneOfTypeParser` to generate unique subtype names by appending an index to the base name (e.g., `name_sub0`, `name_sub1`) when parsing subtypes from the schema. [[1]](diffhunk://#diff-5d520b897b6563dd224e958d60f7b4a6f839f44b96cc21fd7bebe5d4d91770e5L33-R36) [[2]](diffhunk://#diff-ee90b057908899d31f1e4b43d4dc255af6db0c81d03f76260f4957aad12f1742L32-R36) ### Test enhancements: * Added a new test `test_scoped_ref_schema` to `tests/test_schema_converter.py` that verifies subtypes generated from a `oneOf` schema have different names, preventing type name conflicts. * Updated test imports to include `JSONSchema` and `get_args` for improved type handling in test cases.
Sign in to join this conversation.