Skip to content

fix: loose-schema bug with nested schemas that are already loose#191

Merged
macielti merged 1 commit into
mainfrom
feat/loose-schema-nested-bug-fix-test
Mar 11, 2026
Merged

fix: loose-schema bug with nested schemas that are already loose#191
macielti merged 1 commit into
mainfrom
feat/loose-schema-nested-bug-fix-test

Conversation

@macielti

Copy link
Copy Markdown
Owner

Summary

Fixed a bug in the loose-schema function where nested schemas that were already loose would cause a More than one non-optional/required key schemata: [Keyword Keyword] error.

Root Cause

clojure.walk/postwalk treats schema record types (Predicate, OptionalKey, etc.) as maps since they implement IPersistentMap. This caused {s/Keyword s/Any} to be injected into schema type internals. When a schema value was itself already a loose schema (e.g., Telegram inside Config), the walk would add a duplicate s/Keyword entry.

Fix

Added two guards to the postwalk predicate:

  • (not (record? %)) — skips schema record types like Predicate, OptionalKey
  • (not (contains? % s/Keyword)) — skips maps that already have a s/Keyword catch-all key

Changes

  • src/common_clj/schema/core.clj: Fixed loose-schema function
  • test/unit/common_clj/schema/core_test.clj: Added loose-schema-with-nested-loose-schema-test with 5 test cases
  • project.clj: Version bump to 46.1.5
  • CHANGELOG.md: Added entry for 46.1.5

- Fixed postwalk walking into schema record types (Predicate, OptionalKey, etc.)
  causing duplicate s/Keyword entries when nested schemas were already loose.
- Added unit tests covering nested loose-schema scenario (Telegram inside Config).
- Bumped version to 46.1.5.
@macielti macielti merged commit a1a02cf into main Mar 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant