Skip to content

Fix object form rendering to avoid field duplication#11

Merged
vearutop merged 1 commit into
masterfrom
fix-object-forms
May 2, 2026
Merged

Fix object form rendering to avoid field duplication#11
vearutop merged 1 commit into
masterfrom
fix-object-forms

Conversation

@vearutop

@vearutop vearutop commented May 2, 2026

Copy link
Copy Markdown
Member

No description provided.

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

Lines Of Code

Language Files Lines Code Comments Blanks Complexity Bytes
Go 10 831 (+78) 621 (+66) 46 164 (+12) 73 (+7) 21.7K (+2.4K)
Go (test) 2 214 (-2) 196 (-2) 1 17 0 6.1K (-78B)
Makefile 1 38 27 (-1) 4 (+1) 7 2 1.1K (+1B)
YAML 5 330 (-12) 288 (+7) 17 (-13) 25 (-6) 0 10.2K (-691B)

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

Go API Changes

# summary
Inferred base version: v0.2.7
Suggested version: v0.2.8

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

Unit Test Coverage

total: (statements) 45.9%
changed lines: (statements) 100.0%

Coverage of changed lines
File Function Coverage
Total 100.0%
schema.go 100.0%
schema.go:117 reflect 100.0%
example/handler.go no coverage
example/main.go no coverage
example/usecase.go no coverage
example/user.go no coverage
Coverage diff with base branch

No changes in coverage.

@vearutop vearutop merged commit 37c4e35 into master May 2, 2026
6 checks passed
@vearutop vearutop deleted the fix-object-forms branch May 2, 2026 09:47

@llamapreview llamapreview Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review by LlamaPReview

🎯 TL;DR & Recommendation

Recommendation: Request Changes

This PR fixes a bug causing duplicate form entries for nested object properties by skipping object-typed properties in the form item generation. However, test coverage for the new behavior is incomplete.

📄 Documentation Diagram

This diagram documents the refactored object form rendering logic that avoids field duplication.

sequenceDiagram
    participant R as Repository
    participant RF as Reflector
    participant IC as InterceptProp
    participant FM as FormItem Map

    R->>RF: Reflect(value)
    RF->>IC: InterceptProp for each property
    alt !params.Processed OR params.PropertySchema.HasType(Object)
        IC-->>RF: return nil (skip)
    else
        IC->>FM: Add FormItem for property
    end
    note over IC: PR #35;11: skip object-type properties to avoid duplication
    RF-->>R: Return FormSchema
    R->>FM: Assemble final form
Loading

🌟 Strengths

  • Core fix is correct and passes all CI checks.
Priority File Category Impact Summary (≤12 words) Anchors
P1 schema.go Bug Prevents field duplication for nested objects
P2 schema_test.go Testing Removes expected duplicates from test assertion
P2 .github/.../golangci-lint.yml Maintainability Updates CI and removes dead config

🔍 Notable Themes

  • Missing test coverage for nested objects: Despite the fix, the test suite only leverages the existing User.counters field, not the newly added Image type. Adding a unit test that verifies the form output for Image (nested Settings) would prevent future regressions.

📈 Risk Diagram

This diagram illustrates the risk of breaking existing forms that depend on whole-object form items.

sequenceDiagram
    participant Code as PR #35;11 Code
    participant Form as Form Renderer
    participant User as Downstream Consumer

    Code->>Code: Check property type
    alt Property is Object
        Code->>Code: Skip adding FormItem (whole object)
        note over Code: R1(P1): Object property skipped; existing forms depending on whole object key may break
        Code->>Form: Only sub-fields rendered
    else
        Code->>Form: Add FormItem
    end
    Form->>User: Render form (missing expected object-level field)
Loading

💡 Have feedback? We'd love to hear it in our GitHub Discussions.
✨ This review was generated by LlamaPReview Advanced, which is free for all open-source projects. Learn more.

Comment thread schema_test.go
Comment on lines 64 to 66
{"key":"user.code","type":"ace","aceMode":"ace/mode/sql"},
{"key":"user.counters"},{"key":"user"},
{
"type":"fieldhtml",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 | Confidence: High

The test expectations are updated to remove the duplicate items that were previously generated for object-typed properties. This correctly aligns the test with the fixed behaviour. However, the test coverage for nested objects is limited to the User struct's counters field and the Neighbors array items. The PR adds an Image struct with a nested Settings object as an example, but no dedicated unit test validates this scenario. Adding a test case that explicitly verifies the form output for a type like Image would provide stronger regression protection.

Code Suggestion:

Consider adding a test case using the `Image` type (similar to how the existing example harness works) to assert that no duplicate items appear and that all subfields are correctly listed.

Comment on lines 26 to 29
- name: golangci-lint
uses: golangci/golangci-lint-action@v8.0.0
uses: golangci/golangci-lint-action@v9.2.0
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v2.11.3

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 | Confidence: High

The PR removes long-commented optional configuration lines from the CI workflow, updates the golangci/golangci-lint-action from v8.0.0 to v9.2.0, and updates several dependency versions in go.mod and example/go.mod. The lint configuration .golangci.yml also disables two linters (embeddedstructfieldcheck, nilnil) and adds a complexity limit. These changes reduce technical debt but are not directly related to the bug fix. The dependency bumps may introduce slight behavioural changes in downstream libraries; however, all CI checks pass, so they are safe. No functional impact is expected.

Comment thread schema.go
if !params.Processed || params.PropertySchema.HasType(jsonschema.Object) {
return nil
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Contextual Comment]
This comment refers to code near real line 127. Anchored to nearest_changed(125) line 125.


P1 | Confidence: High

The core logic change prevents object-typed properties from being added as a whole FormItem. Previously, the condition !params.Processed added a FormItem for every property, including those with type object. Because object properties are also recursively expanded into their sub-fields, this resulted in duplicate form entries (e.g., both {"key":"user.counters"} and the expanded sub-fields of counters appeared). The fix adds an explicit check for params.PropertySchema.HasType(jsonschema.Object), causing object-typed properties to be skipped. The test file schema_test.go confirms this by removing the expected duplicates {"key":"user.counters"}, {"key":"user"}, and {"key":"neighbors[].counters"} from the golden assertion. The example code introduces an Image type with nested ImageSettings to manually verify correct rendering with nested objects. The change is correct and passes all CI checks.

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