#638: Add support of propertyNames - #1100
Open
superstas wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1100 +/- ##
==========================================
+ Coverage 93.20% 93.23% +0.02%
==========================================
Files 23 23
Lines 4988 5009 +21
==========================================
+ Hits 4649 4670 +21
Misses 272 272
Partials 67 67 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class JSON Schema propertyNames support to Huma schemas, enabling validation and schema generation for map/object key constraints (notably for OpenAPI 3.1), with appropriate OpenAPI 3.0 downgrade behavior.
Changes:
- Add
PropertyNamestohuma.Schema, ensure it is preserved through schema generation and JSON marshaling, and precompute nested validation messages. - Enforce
propertyNamesvalidation for object/map inputs during request validation (includingmap[string]anyandmap[any]anywith string keys). - Ensure
propertyNamesis removed when downgrading specs to OpenAPI 3.0, and extend tests for validation, marshaling, downgrade, and autopatch optionalization.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| validate.go | Validates propertyNames against each object/map key during runtime validation. |
| validate_test.go | Adds coverage for propertyNames validation behavior and error reporting. |
| schema.go | Adds Schema.PropertyNames, includes it in JSON output, and precomputes nested messages. |
| schema_test.go | Verifies propertyNames survives schema provider/transformer generation and marshaling. |
| openapi.go | Drops propertyNames when downgrading from OAS 3.1 to 3.0. |
| openapi_test.go | Extends downgrade test inputs to include propertyNames. |
| autopatch/autopatch.go | Ensures PropertyNames is recursively optionalized by autopatch. |
| autopatch/autopatch_test.go | Tests optional schema generation preserves PropertyNames. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi there!
This PR adds support for
propertyNames, as discussed in #638.At the moment, it is supported only when set explicitly on
huma.Schema.Automatically generating
propertyNamesfrom map key types requires a separate discussion.Example
generates
... InputBody: additionalProperties: false properties: $schema: description: A URL to the JSON Schema for this object. examples: - https://example.com/schemas/InputBody.json format: uri readOnly: true type: string values: additionalProperties: description: A value for a map. maxLength: 32 minLength: 1 type: string propertyNames: description: A key for a map. maxLength: 10 minLength: 1 type: string type: object required: - values type: object ...Thank you.