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
|
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. |
w666
left a comment
There was a problem hiding this comment.
Thanks for the PR, changes make sense. Unfortunately we should keep this disabled by default, so it does not break someones code.
| const item = obj[i]; | ||
| const arrayAttr = this.processAttributes(item, nsContext); | ||
| const isArrayWithChoiceTagContainer = name === this.options.arrayWithChoiceTag; | ||
| const arrayAttr = isArrayWithChoiceTagContainer ? '' : this.processAttributes(item, nsContext); |
There was a problem hiding this comment.
New behaviour should be disabled by default, because it may break someones code. This, unfortunately, will disable default value, but will keep this backwards compatible with current implementation.
| preserveWhitespace?: boolean; | ||
| /** provides support for nonstandard array semantics. If true, JSON arrays of the form {list: [{elem: 1}, {elem: 2}]} are marshalled into xml as <list><elem>1</elem></list> <list><elem>2</elem></list>. If false, marshalls into <list> <elem>1</elem> <elem>2</elem> </list>. Default: true. */ | ||
| namespaceArrayElements?: boolean; | ||
| /** provides support for array with choice semantics. If array key matches, JSON arrays of the form {$sequence: [{elem: 1}, {elem: 2}]} are marshalled into xml as <elem>1</elem><elem>2</elem>. Default: $sequence. */ |
There was a problem hiding this comment.
| /** provides support for array with choice semantics. If array key matches, JSON arrays of the form {$sequence: [{elem: 1}, {elem: 2}]} are marshalled into xml as <elem>1</elem><elem>2</elem>. Default: $sequence. */ | |
| /** provides support for array with choice semantics. If array key matches, JSON arrays of the form {$sequence: [{elem: 1}, {elem: 2}]} are marshalled into xml as <elem>1</elem><elem>2</elem> where $sequence is example value for the option. Disabled if option is not set. Example value: $sequence. */ |
| ); | ||
| }); | ||
|
|
||
| it('should parse complex wsdls with mixed choice and minOccurs maxOccurs with default $sequence', function (done) { |
There was a problem hiding this comment.
This test should be converted to option is not set to make sure we keep original behaviour by default.
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.