Adds support for <xs:choice minOccurs="0" maxOccurs="unbounded"/> cases.#1496
Adds support for <xs:choice minOccurs="0" maxOccurs="unbounded"/> cases.#14964name wants to merge 1 commit into
Conversation
That PR fixes <xsd:choice minOccurs="0" maxOccurs="unbounded"/> behavior. Before that, the WSDL marshaller could resolve this only as two (or more) separate type lists. The following JSON object has two separate lists of As and Bs:
Assuming we have the following definitions of some Document:
<>
<!-- Parent document WSDL definition -->
<xsd:element name="someOtherProperty" type="ct:SomeOtherType"/>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="a" type="ct:A"/>
<xsd:element name="b" type="ct:B"/>
</xsd:choice>
</>
// Old behavior
{
// Parent document JSON representation
someOtherProperty: { ... SomeOtherType-type object ... },
a: [ { ... A-type object 1 ... }, { ... A-type object 2 ... }, ...],
b: [ { ... B-type object 1 ... }, { ... B-type object 2 ... }, { ... B-type object 3 ... }, ...],
}
that resulted into:
<>
<!-- Parent document XML representation -->
<someOtherProperty> ... SomeOtherType properties ... </someOtherProperty>
<a> ... A-type properties 1 ... </a>
<a> ... A-type properties 2 ... </a>
<b> ... B-type properties 1 ... </b>
<b> ... B-type properties 2 ... </b>
<b> ... B-type properties 3 ... </b>
</>
In case we want to preserve the choice children order for the following JSON object:
// New behavior
{
// Parent document JSON representation
someOtherProperty: { ... SomeOtherType-type object ... },
'$sequence': [ // <- Note this special transparent key that wraps a flat array object
a: { ... A-type object 1 ... },
b: { ... B-type object 1 ... },
b: { ... B-type object 2 ... },
a: { ... A-type object 2 ... },
b: { ... B-type object 3 ... },
]
}
to be encoded as:
<>
<!-- Parent document XML representation -->
<someOtherProperty> ... SomeOtherType properties ... </someOtherProperty>
<a> ... A-type properties 1 ... </a> <!-- Note that As and Bs tags are on the same level with someOtherProperty -->
<b> ... B-type properties 1 ... </b>
<b> ... B-type properties 2 ... </b>
<a> ... A-type properties 2 ... </a> <!-- Note that we can mix As and Bs order now -->
<b> ... B-type properties 3 ... </b>
</>
In case of interfere with $sequence property of some SOAP Service property, the special key name can be replaced with options arrayWithChoiceTag: string value.
📝 WalkthroughWalkthroughThis PR adds support for custom array choice tag configuration during SOAP XML marshaling. A new optional ChangesArray Choice Tag Customization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/wsdl-parse-test.js`:
- Around line 159-161: The test is using def.findSchemaType to look up the
element "getDataResponse" but that element has an anonymous complex type, so
change both lookups to use def.findSchemaObject('getDataResponse',
'http://test-soap.com/api/mixedsequence') instead of def.findSchemaType; update
the two occurrences around the current getDataResponse assertions (the call at
the earlier block and the similar call at the later block around lines 231-233)
so the test queries the schema object (element) rather than searching for a
named type.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 88fff7ac-e81b-419d-856b-704aa6b2b01f
📒 Files selected for processing (4)
src/types.tssrc/wsdl/index.tstest/wsdl-parse-test.jstest/wsdl/complex/mixed-sequence.wsdl
| if (null === def.findSchemaType('getDataResponse', 'http://test-soap.com/api/mixedsequence')) { | ||
| return done('Unable to find "getDataResponse" complex type'); | ||
| } |
There was a problem hiding this comment.
Use findSchemaObject for getDataResponse lookup.
Line 159 and Line 231 call findSchemaType, but getDataResponse is an element with an anonymous complex type in mixed-sequence.wsdl, so this lookup is incorrect.
💡 Proposed fix
- if (null === def.findSchemaType('getDataResponse', 'http://test-soap.com/api/mixedsequence')) {
- return done('Unable to find "getDataResponse" complex type');
+ if (null === def.findSchemaObject('http://test-soap.com/api/mixedsequence', 'getDataResponse')) {
+ return done('Unable to find "getDataResponse" schema object');
}
@@
- if (null === def.findSchemaType('getDataResponse', 'http://test-soap.com/api/mixedsequence')) {
- return done('Unable to find "getDataResponse" complex type');
+ if (null === def.findSchemaObject('http://test-soap.com/api/mixedsequence', 'getDataResponse')) {
+ return done('Unable to find "getDataResponse" schema object');
}Also applies to: 231-233
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/wsdl-parse-test.js` around lines 159 - 161, The test is using
def.findSchemaType to look up the element "getDataResponse" but that element has
an anonymous complex type, so change both lookups to use
def.findSchemaObject('getDataResponse',
'http://test-soap.com/api/mixedsequence') instead of def.findSchemaType; update
the two occurrences around the current getDataResponse assertions (the call at
the earlier block and the similar call at the later block around lines 231-233)
so the test queries the schema object (element) rather than searching for a
named type.
|
Hi @4name. thanks for the PR. I am a bit overcomited atm, but this PR is on my backlog. I will have a look as soon as I can, Thanks. Also, need to silent that CodeRabbit, too much noise from it. |
|
Hi @w666! Thank you for the notice, take your time. Please let me know if there is anything that needs to be improved in that PR. |
That PR fixes <xsd:choice minOccurs="0" maxOccurs="unbounded"/> behavior. Before that, the WSDL marshaller could resolve this only as two (or more) separate type lists. The following JSON object has two separate lists of As and Bs:
Assuming we have the following definitions of some Document:
// Old behavior
that resulted into:
In case we want to preserve the choice children order for the following JSON object:
// New behavior
to be encoded as:
In case of interfere with $sequence property of some SOAP Service property, the special key name can be replaced with options arrayWithChoiceTag: string value.
Summary by CodeRabbit
Release Notes
arrayWithChoiceTagconfiguration option for customizing XML serialization of polymorphic array elements in SOAP operations.