Skip to content

Comments

Enhance schema generation to always reference flowParser for interceptor list#2815

Merged
predic8 merged 2 commits intomasterfrom
json-schema-enhancement
Feb 23, 2026
Merged

Enhance schema generation to always reference flowParser for interceptor list#2815
predic8 merged 2 commits intomasterfrom
json-schema-enhancement

Conversation

@christiangoerdes
Copy link
Collaborator

@christiangoerdes christiangoerdes commented Feb 23, 2026

Summary by CodeRabbit

  • Refactor
    • Enhanced internal schema generation logic for more reliable handling of complex parser scenarios and edge cases.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 23, 2026

📝 Walkthrough

Walkthrough

Refactors flowParser detection and attachment logic in JSON schema generation. Instead of hard-coded "flow" property names, the code now uses type-based checks to identify when a flowParser should be generated, and dynamically routes flowParser references to the correct property names within list or object schemas.

Changes

Cohort / File(s) Summary
JsonSchemaGenerator flowParser Refactoring
annot/src/main/java/com/predic8/membrane/annot/generator/JsonSchemaGenerator.java
Introduces type-based flowParser detection via shouldGenerateFlowParserType (evaluating list status, WebSocket case, and Interceptor matching). Updates createParser to return flowParser definitions for eligible children in noEnvelope contexts. Modifies processList to route flowParser references through addFlowParserRef. Changes addFlowParserRef signature to accept parent schema and property name, enabling dynamic attachment to SchemaArray items or SchemaObject properties using the provided property name instead of fixed "flow".

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 Behold, the flowParser now awakens—
No longer bound by "flow" name forsaken,
Type-based wisdom guides the schema's way,
Property names dance where references play!
A rabbit approves of this dynamic refrain.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: enhancing schema generation to always reference flowParser for interceptor lists, which aligns with the core modifications in JsonSchemaGenerator.java.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch json-schema-enhancement

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@christiangoerdes
Copy link
Collaborator Author

/ok-to-test

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
annot/src/main/java/com/predic8/membrane/annot/generator/JsonSchemaGenerator.java (1)

119-135: ⚠️ Potential issue | 🟠 Major

Ensure flowParser definition is always created when referenced from a noEnvelope element.

When a noEnvelope element with an Interceptor-typed child calls shouldGenerateFlowParserType(), it returns a reference to #/$defs/flowParser (line 132) but never calls processMCChilds, which is the only code path that creates the definition via addFlowParserRef. While the framework's existing elements (Proxy, Transport) ensure the definition is created before noEnvelope elements are processed, this relies on an implicit assumption about which elements exist in the model. If a minimal schema contains only noEnvelope elements with Interceptor children, the definition would never be created.

Suggested fix: Eagerly create the flowParser definition

In the noEnvelope block when shouldGenerateFlowParserType(child) is true, ensure the definition exists:

             if (shouldGenerateFlowParserType(child)) {
+                if (!flowDefCreated) {
+                    var sos = getSchemaObjects(m, main, child);
+                    schema.definition(array("flowParser").items(anyOf(sos)));
+                    flowDefCreated = true;
+                }
                 return ref(parserName).ref("#/$defs/flowParser");
             }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@annot/src/main/java/com/predic8/membrane/annot/generator/JsonSchemaGenerator.java`
around lines 119 - 135, The noEnvelope branch returns a reference to
"#/$defs/flowParser" when shouldGenerateFlowParserType(child) is true but never
creates that definition; update the block in JsonSchemaGenerator (around
elementInfo.noEnvelope handling) to eagerly ensure the flowParser definition is
added before returning the ref—either by invoking the same code path that
creates it (call processMCChilds or addFlowParserRef with the child and
appropriate SchemaArray) or explicitly calling addFlowParserRef(parserName/main)
so flowParser is defined whenever shouldGenerateFlowParserType(child) is true
prior to returning ref(parserName).ref("#/$defs/flowParser").
🧹 Nitpick comments (1)
annot/src/main/java/com/predic8/membrane/annot/generator/JsonSchemaGenerator.java (1)

288-293: Minor: getSchemaObjects is computed on every Interceptor-typed list child, but only the first result is used.

At line 291, getSchemaObjects(m, main, cei) is called each time, but addFlowParserRef discards it when flowDefCreated is already true (line 396). Consider guarding with flowDefCreated:

Suggested optimization
             if (shouldGenerateFlowParserType(cei)) {
-                processList(i, so, cei, getSchemaObjects(m, main, cei));
+                var sos = flowDefCreated ? null : getSchemaObjects(m, main, cei);
+                processList(i, so, cei, sos);
                 continue;
             }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@annot/src/main/java/com/predic8/membrane/annot/generator/JsonSchemaGenerator.java`
around lines 288 - 293, The call to getSchemaObjects(m, main, cei) is being
recomputed for every Interceptor-typed child even after flowDefCreated is true
and its result is ignored; to fix, introduce a local variable (e.g.,
schemaObjects) that is lazily initialized and only assigned by calling
getSchemaObjects(m, main, cei) when flowDefCreated is false, then pass that
variable into processList(i, so, cei, schemaObjects) instead of calling
getSchemaObjects each time; reference functions/classes: getSchemaObjects,
shouldGenerateFlowParserType, processList, addFlowParserRef, and the
flowDefCreated flag.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In
`@annot/src/main/java/com/predic8/membrane/annot/generator/JsonSchemaGenerator.java`:
- Around line 119-135: The noEnvelope branch returns a reference to
"#/$defs/flowParser" when shouldGenerateFlowParserType(child) is true but never
creates that definition; update the block in JsonSchemaGenerator (around
elementInfo.noEnvelope handling) to eagerly ensure the flowParser definition is
added before returning the ref—either by invoking the same code path that
creates it (call processMCChilds or addFlowParserRef with the child and
appropriate SchemaArray) or explicitly calling addFlowParserRef(parserName/main)
so flowParser is defined whenever shouldGenerateFlowParserType(child) is true
prior to returning ref(parserName).ref("#/$defs/flowParser").

---

Nitpick comments:
In
`@annot/src/main/java/com/predic8/membrane/annot/generator/JsonSchemaGenerator.java`:
- Around line 288-293: The call to getSchemaObjects(m, main, cei) is being
recomputed for every Interceptor-typed child even after flowDefCreated is true
and its result is ignored; to fix, introduce a local variable (e.g.,
schemaObjects) that is lazily initialized and only assigned by calling
getSchemaObjects(m, main, cei) when flowDefCreated is false, then pass that
variable into processList(i, so, cei, schemaObjects) instead of calling
getSchemaObjects each time; reference functions/classes: getSchemaObjects,
shouldGenerateFlowParserType, processList, addFlowParserRef, and the
flowDefCreated flag.
ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9808f44 and ffeefa8.

📒 Files selected for processing (1)
  • annot/src/main/java/com/predic8/membrane/annot/generator/JsonSchemaGenerator.java

@membrane-ci-server
Copy link

This pull request needs "/ok-to-test" from an authorized committer.

@predic8 predic8 merged commit 6c5f687 into master Feb 23, 2026
5 checks passed
@predic8 predic8 deleted the json-schema-enhancement branch February 23, 2026 10:25
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.

2 participants