feature: add instance level ref cache #63

Merged
HideyoshiNakazone merged 12 commits from feature/add-instance-level-ref-cache into main 2025-11-25 00:07:55 +00:00
HideyoshiNakazone commented 2025-11-24 21:20:47 +00:00 (Migrated from github.com)

This pull request introduces a comprehensive refactor focused on improving reference cache handling and type naming for JSON schema parsing and model generation. The changes enforce the use of a dedicated RefCacheDict type for reference caching, add cache management utilities, and enhance error and warning reporting for cache-related issues. Additionally, the test suite is updated to ensure proper cache usage and to validate new error/warning behaviors.

Reference cache management and API improvements

  • Introduced the RefCacheDict type for consistent reference cache handling across parsers and the schema converter, replacing previous use of plain dictionaries. [1] [2] [3] [4] [5]
  • Refactored SchemaConverter to support instance-level reference caching, added methods to clear and query the cache, and updated the build logic to accept and use the cache. [1] [2] [3] [4]

Parser behavior and error/warning handling

  • Enforced that ObjectTypeParser requires a ref_cache argument, raising InternalAssertionException if missing, and added warnings when a type name collision occurs in the cache. [1] [2] [3] [4]
  • Updated type naming conventions in AnyOfTypeParser and ObjectTypeParser to use dot notation for subtypes, improving clarity and avoiding naming collisions. [1] [2]

Test suite updates

Internal API consistency

  • Updated type parser option definitions and usages to require the new RefCacheDict type, ensuring consistent type safety and API clarity. [1] [2]

Warnings and error handling in tests

  • Added new tests to ensure ObjectTypeParser raises errors when ref_cache is missing and emits warnings when cached types are overridden. [1] [2]
This pull request introduces a comprehensive refactor focused on improving reference cache handling and type naming for JSON schema parsing and model generation. The changes enforce the use of a dedicated `RefCacheDict` type for reference caching, add cache management utilities, and enhance error and warning reporting for cache-related issues. Additionally, the test suite is updated to ensure proper cache usage and to validate new error/warning behaviors. ### Reference cache management and API improvements * Introduced the `RefCacheDict` type for consistent reference cache handling across parsers and the schema converter, replacing previous use of plain dictionaries. [[1]](diffhunk://#diff-f707dbcc4de072318a98f0f7505c9cce1e32a0580a7c1588faf98fede8939d50L3-R12) [[2]](diffhunk://#diff-c3cae2e672447dfee0484b55a0d5073ff62fb8aa003a9e68b8327404392e05c8L7-R15) [[3]](diffhunk://#diff-d16be762c5d7769e8b1823a352f89dc50dda662776e67a912ab1ca41aa7e0a8dR3) [[4]](diffhunk://#diff-d16be762c5d7769e8b1823a352f89dc50dda662776e67a912ab1ca41aa7e0a8dL75-R76) [[5]](diffhunk://#diff-5eb39c1cffff2b2a9a900defd2b0298fc810cf4d9206a237ecf69ece8fe07561L3-R8) * Refactored `SchemaConverter` to support instance-level reference caching, added methods to clear and query the cache, and updated the build logic to accept and use the cache. [[1]](diffhunk://#diff-5eb39c1cffff2b2a9a900defd2b0298fc810cf4d9206a237ecf69ece8fe07561R20-R63) [[2]](diffhunk://#diff-5eb39c1cffff2b2a9a900defd2b0298fc810cf4d9206a237ecf69ece8fe07561L49-R87) [[3]](diffhunk://#diff-5eb39c1cffff2b2a9a900defd2b0298fc810cf4d9206a237ecf69ece8fe07561L58-R96) [[4]](diffhunk://#diff-5eb39c1cffff2b2a9a900defd2b0298fc810cf4d9206a237ecf69ece8fe07561R109-R127) ### Parser behavior and error/warning handling * Enforced that `ObjectTypeParser` requires a `ref_cache` argument, raising `InternalAssertionException` if missing, and added warnings when a type name collision occurs in the cache. [[1]](diffhunk://#diff-34c0afbd0b65cfb477a4af7877931a3d3a07b25525b054633ef7db5feba83c1dR1) [[2]](diffhunk://#diff-34c0afbd0b65cfb477a4af7877931a3d3a07b25525b054633ef7db5feba83c1dR10-R11) [[3]](diffhunk://#diff-34c0afbd0b65cfb477a4af7877931a3d3a07b25525b054633ef7db5feba83c1dR60-R102) [[4]](diffhunk://#diff-00efaeb5d18a67c49c3ea8d50cc494205938a48952a8cedb7d8b1074081c741eR1-R21) * Updated type naming conventions in `AnyOfTypeParser` and `ObjectTypeParser` to use dot notation for subtypes, improving clarity and avoiding naming collisions. [[1]](diffhunk://#diff-5d520b897b6563dd224e958d60f7b4a6f839f44b96cc21fd7bebe5d4d91770e5L34-R34) [[2]](diffhunk://#diff-34c0afbd0b65cfb477a4af7877931a3d3a07b25525b054633ef7db5feba83c1dR60-R102) ### Test suite updates * Updated all relevant tests to explicitly provide a `ref_cache` argument, ensuring compatibility with the new cache requirements and validating error/warning behaviors. [[1]](diffhunk://#diff-f55e9aea6bd04f07c2aa1545c63902a62edd107f61392beb2ceb2bcadef13c43L45-R45) [[2]](diffhunk://#diff-f55e9aea6bd04f07c2aa1545c63902a62edd107f61392beb2ceb2bcadef13c43L90-R90) [[3]](diffhunk://#diff-f55e9aea6bd04f07c2aa1545c63902a62edd107f61392beb2ceb2bcadef13c43L119-R119) [[4]](diffhunk://#diff-f55e9aea6bd04f07c2aa1545c63902a62edd107f61392beb2ceb2bcadef13c43L140-R140) [[5]](diffhunk://#diff-f55e9aea6bd04f07c2aa1545c63902a62edd107f61392beb2ceb2bcadef13c43L161-R161) [[6]](diffhunk://#diff-f55e9aea6bd04f07c2aa1545c63902a62edd107f61392beb2ceb2bcadef13c43L174-R174) [[7]](diffhunk://#diff-f55e9aea6bd04f07c2aa1545c63902a62edd107f61392beb2ceb2bcadef13c43L187-R187) [[8]](diffhunk://#diff-f55e9aea6bd04f07c2aa1545c63902a62edd107f61392beb2ceb2bcadef13c43L203-R203) [[9]](diffhunk://#diff-f55e9aea6bd04f07c2aa1545c63902a62edd107f61392beb2ceb2bcadef13c43L240-R242) [[10]](diffhunk://#diff-f55e9aea6bd04f07c2aa1545c63902a62edd107f61392beb2ceb2bcadef13c43L278-R282) [[11]](diffhunk://#diff-f55e9aea6bd04f07c2aa1545c63902a62edd107f61392beb2ceb2bcadef13c43L311-R315) [[12]](diffhunk://#diff-f55e9aea6bd04f07c2aa1545c63902a62edd107f61392beb2ceb2bcadef13c43L347-R351) [[13]](diffhunk://#diff-00efaeb5d18a67c49c3ea8d50cc494205938a48952a8cedb7d8b1074081c741eL18-R35) [[14]](diffhunk://#diff-00efaeb5d18a67c49c3ea8d50cc494205938a48952a8cedb7d8b1074081c741eL42-R61) [[15]](diffhunk://#diff-00efaeb5d18a67c49c3ea8d50cc494205938a48952a8cedb7d8b1074081c741eL64-R85) [[16]](diffhunk://#diff-00efaeb5d18a67c49c3ea8d50cc494205938a48952a8cedb7d8b1074081c741eR95-R109) ### Internal API consistency * Updated type parser option definitions and usages to require the new `RefCacheDict` type, ensuring consistent type safety and API clarity. [[1]](diffhunk://#diff-f707dbcc4de072318a98f0f7505c9cce1e32a0580a7c1588faf98fede8939d50L3-R12) [[2]](diffhunk://#diff-c3cae2e672447dfee0484b55a0d5073ff62fb8aa003a9e68b8327404392e05c8L7-R15) ### Warnings and error handling in tests * Added new tests to ensure `ObjectTypeParser` raises errors when `ref_cache` is missing and emits warnings when cached types are overridden. [[1]](diffhunk://#diff-00efaeb5d18a67c49c3ea8d50cc494205938a48952a8cedb7d8b1074081c741eR1-R21) [[2]](diffhunk://#diff-00efaeb5d18a67c49c3ea8d50cc494205938a48952a8cedb7d8b1074081c741eR95-R109)
codecov[bot] commented 2025-11-24 21:21:02 +00:00 (Migrated from github.com)

Codecov Report

All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

## [Codecov](https://app.codecov.io/gh/HideyoshiNakazone/jambo/pull/63?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Vitor+Hideyoshi) Report :white_check_mark: All modified and coverable lines are covered by tests. :loudspeaker: Thoughts on this report? [Let us know!](https://github.com/codecov/feedback/issues/255)
Sign in to join this conversation.