Skip to content

Conversation

mintyleaf
Copy link

@mintyleaf mintyleaf commented Oct 10, 2025

i have an edgecase, where i need to inline include a really large and upstream dependent go structure from another package into the Input/Output usecase structure definition
That structure has all the needed json tags, yet, it has the context.CancelFunc 'json:"-"' field, which causes panic at the reflection step due to obviously unsupported type

jsonschema has the SkipUnsupportedProperties option for that case, which can be enabled by modifying default decoder options, but it not supported by the rest itself
https://github.com/swaggest/jsonschema-go/blob/a12059cd34136a1006ac484eacff11e4c167d071/context.go#L243

Copy link

@llamapreview llamapreview bot left a comment

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 adds error handling for unsupported properties in JSON Schema reflection to prevent panics during decoder initialization, but it introduces potential maintainability and testing gaps that could impact future reliability.

🌟 Strengths

  • Prevents runtime panics when structs contain unsupported types, enhancing system stability for affected endpoints.
Priority File Category Impact Summary Anchors
P1 request/factory.go Bug Prevents decoder initialization panics from unsupported types symbol:DecoderFactory method:makeDefaultDecoder
P2 request/factory.go Maintainability Error equality may break with wrapped errors -
P2 request/factory.go Testing Missing tests for skip property handling -

🔍 Notable Themes

  • Error handling could be strengthened to be more resilient against future changes in dependency implementations.
  • Additional test coverage is necessary to validate the new code path and ensure consistent behavior.

📈 Risk Diagram

This diagram illustrates the new error handling logic for unsupported properties during JSON Schema reflection and its associated risks.

sequenceDiagram
    participant DF as DecoderFactory
    participant JSR as JSONSchema Reflector
    DF->>JSR: Reflect(vi)
    JSR-->>DF: err or schema
    alt err == ErrSkipProperty
        DF->>DF: return
    else
        DF->>DF: panic(err)
    end
    note over DF: R1(P1): New error handling prevents panics but relies on direct error equality
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 on lines 291 to 297
s, err := df.JSONSchemaReflector.Reflect(vi)
if err != nil {
if err == jsonschema.ErrSkipProperty {
return
}
panic(err.Error())
}
Copy link

Choose a reason for hiding this comment

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

P1 | Confidence: High

  • This change enables graceful handling of jsonschema.ErrSkipProperty during JSON Schema reflection in default value processing. Without this fix, any struct field with unsupported types would cause a panic during decoder initialization, breaking the entire request processing pipeline for affected endpoints. The change preserves existing panic behavior for other errors while allowing proper skipping of unsupported properties.
  • The error comparison uses direct equality check with jsonschema.ErrSkipProperty, which could be fragile if the error value implementation changes in the future. Consider using errors.Is() for more robust error handling.
  • The PR doesn't include test coverage for the new error handling path. Tests should verify that structs with unsupported properties don't panic when ErrSkipProperty occurs and that default value processing continues normally for supported fields.
Suggested change
s, err := df.JSONSchemaReflector.Reflect(vi)
if err != nil {
if err == jsonschema.ErrSkipProperty {
return
}
panic(err.Error())
}
s, err := df.JSONSchemaReflector.Reflect(vi)
if err != nil {
if errors.Is(err, jsonschema.ErrSkipProperty) {
return
}
panic(err.Error())
}

Evidence: path:web/service.go, symbol:DecoderFactory, method:makeDefaultDecoder

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