Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jamienich
Copy link

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

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style
    guide

Signed-off-by: jamienich <jamie.nicholson@gmail.com>
Signed-off-by: jamienich <jamie.nicholson@gmail.com>
@jamienich jamienich changed the title Develop feat: wsdl option ignoreAttributesUndefined Nov 11, 2024
@coveralls
Copy link

Pull Request Test Coverage Report for Build 11771217283

Details

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 84.669%

Totals Coverage Status
Change from base Build 11748555209: 0.02%
Covered Lines: 2895
Relevant Lines: 3249

💛 - Coveralls

Copy link
Member

@achrinza achrinza left a 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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Copyright IBM Corp. 2017. All Rights Reserved.
// Copyright LoopBack contributors 2024

Comment on lines +167 to +168
if (val === null ||(val === undefined && this.options.ignoreAttributesUndefined == true)) {
if (descriptor.isNillable ) {
Copy link
Member

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:

  1. It informs the flow of the conversion (JSON->XML)
  2. It clearly states what it does (Coerce JSON undefined as XML xsi:nil)

The only thing missing is stating that the XML element must be defined as nillable, but that can be covered by documentation.

Suggested change
if (val === null ||(val === undefined && this.options.ignoreAttributesUndefined == true)) {
if (descriptor.isNillable ) {
if (val === null ||(val === undefined && this.options.jsonUndefinedAsXmlNil == true)) {
if (descriptor.isNillable) {

Comment on lines +1 to +7
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)

Copy link
Member

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.

Comment on lines +533 to +536
### 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/>

Copy link
Member

Choose a reason for hiding this comment

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

Can we reword this?

Suggested change
### 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/>`.

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.

3 participants