-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: wsdl option ignoreAttributesUndefined #904
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: jamienich <jamie.nicholson@gmail.com>
Signed-off-by: jamienich <jamie.nicholson@gmail.com>
Pull Request Test Coverage Report for Build 11771217283Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jamienich, thanks so much for your contribution.
I've given this PR some thought and have some minor change requests if that's ok 👇
@@ -0,0 +1,99 @@ | |||
// Copyright IBM Corp. 2017. All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Copyright IBM Corp. 2017. All Rights Reserved. | |
// Copyright LoopBack contributors 2024 |
if (val === null ||(val === undefined && this.options.ignoreAttributesUndefined == true)) { | ||
if (descriptor.isNillable ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though about this for a while; The naming is a little unintuitive.
My suggestion is jsonUndefinedAsXmlNil
:
- It informs the flow of the conversion (JSON->XML)
- It clearly states what it does (Coerce JSON
undefined
as XMLxsi:nil
)
The only thing missing is stating that the XML element must be defined as nillable
, but that can be covered by documentation.
if (val === null ||(val === undefined && this.options.ignoreAttributesUndefined == true)) { | |
if (descriptor.isNillable ) { | |
if (val === null ||(val === undefined && this.options.jsonUndefinedAsXmlNil == true)) { | |
if (descriptor.isNillable) { |
2024-11-11, Version 4.1.6 | ||
========================= | ||
|
||
Placeholder for package maintainer | ||
|
||
* feat: Override default strong-soap behaviour when mapping undefined element values to self closing tags (<tag/> instead of <tag xsi:nil=true></tag>. Option is ignoreAttributesUndefined, to enable option set to false. (Jamie Nicholson) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to manually update this file.
It is auto-generated by strong-tools
as part of our publishing workflow.
### Mapping of undefined element values | ||
|
||
When the wsdl attribute nillable="true" it set, JSON values will map to null and XML values map to nillable='true' unless ignoreAttributesUndefined is set to false. When ignoreAttributesUndefined is set to false undefined element values will map to a self closing tag i.e. <tag/> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we reword this?
### Mapping of undefined element values | |
When the wsdl attribute nillable="true" it set, JSON values will map to null and XML values map to nillable='true' unless ignoreAttributesUndefined is set to false. When ignoreAttributesUndefined is set to false undefined element values will map to a self closing tag i.e. <tag/> | |
### Mapping of JSON `undefined` values | |
For XML elements that are marked as `nillable` in their descriptor, JSON `undefined` is mapped to `<tag xsi:nil="true" />` by default. | |
Setting `jsonUndefinedAsXmlNil: false` will cause JSON `undefined` to be mapped to a `<tag/>`. |
Description
Added feature, new wsdl option ignoreAttributesUndefined, when set to false undefined attribute values will be mapped to xml self closing tags i.e. with no values. Only nulls will set XML attribute value to xsi:nil="true" when nillable="true" is defined in the wsdl.
Related issues
None.
Checklist
guide