wsdl-tsclient icon indicating copy to clipboard operation
wsdl-tsclient copied to clipboard

[BUG] Missing Attributes

Open starsoccer opened this issue 4 years ago • 7 comments

As of the latest version 1.3.1 code generation now seems to be valid typescript but some attributes seem to be missing when using the generated types.

Example WSDL: https://community.workday.com/sites/default/files/file-hosting/productionapi/Human_Resources/v36.1/Human_Resources.wsdl

Assuming the client has been auto generated it should be possible to initiate a change work contact information which you can see an example below, but some attributes seem to be missing such as the Primary field which exists in the WSDL as an attribute on Type_Data but does not seem to exist in any of the types.

Change_Work_Contact_InformationAsync({
    Change_Work_Contact_Information_Data: {
        Universal_ID_Reference: {ID: ['123']},
        Person_Contact_Information_Data: {
            Person_Email_Information_Data: {
                Email_Information_Data: [{
                    Email_Data: [{
                        Email_Address: '[email protected]',
                    }],
                    Usage_Data: [{
                        Type_Data: [{
                            // Primary Field should be here
                        }]
                    }]
                }]
            }
        }
    }
});

starsoccer avatar Jul 01 '21 17:07 starsoccer

Well, wsdl-tsclient is working correctly. Probably there's problem with node-soap not parsing AttributeElement in ComplexType, I even found out not-merged PR for that https://github.com/vpulim/node-soap/pull/1013

I have to do more investigation.... but right now, there are 3 options that comes to my mind

    1. Creating Issue for node-soap project (they don't have GH Issue)
    1. Updating closed PR 1013
    1. Forking node-soap (which I already did) and implement it there

dderevjanik avatar Jul 01 '21 21:07 dderevjanik

I think it maybe has to do with this part but not sure.

Currently, when supplying JSON args, elements may not contain both child elements and a text value, even though that is allowed in the XML specification.

As for the 3 options it seems to be like the best Option is 2 & 3. Perhaps forking for now and using the fork until the PR is reviewed and hopefully merged at which point it could be switched back.

starsoccer avatar Jul 01 '21 21:07 starsoccer

@dderevjanik I posted on the closed PR and it seems like they are open to merging it if it gets fixed and updated. So if you already have a branch/fork that is updated and working I think you should make a pull request and they will likely accept it.

starsoccer avatar Jul 09 '21 14:07 starsoccer

Does anyone have a working fork?

nadilas avatar Aug 25 '23 16:08 nadilas

Here's a smaller repro:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://example.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://example.com/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://example.com/">
      <s:element name="RequestData">
        <s:complexType>
          <s:attribute name="name" type="s:string"/>
        </s:complexType>
      </s:element>
      <s:element name="ResponseData">
      </s:element>
    </s:schema>
  </wsdl:types>
  <wsdl:message name="RequestMessage">
    <wsdl:part name="parameters" element="tns:RequestData"/>
  </wsdl:message>
  <wsdl:message name="ResponseMessage">
    <wsdl:part name="parameters" element="tns:ResponseData"/>
  </wsdl:message>
  <wsdl:portType name="MyServiceSoap">
    <wsdl:operation name="Submit">
      <wsdl:input message="tns:RequestMessage"/>
      <wsdl:output message="tns:ResponseMessage"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="MyServiceSoap" type="tns:MyServiceSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
  </wsdl:binding>
  <wsdl:service name="MyService">
    <wsdl:port name="MyServiceSoap" binding="tns:MyServiceSoap">
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

icholy avatar Oct 03 '23 16:10 icholy

I'm using the following utility type to add an attributes property to the generated types.

/** 
  * Add an attributes property to all nested object. 
  * See: https://github.com/dderevjanik/wsdl-tsclient/issues/20 
  */ 
 export type WithAttr<T> = T extends object 
         ? { 
                         [P in keyof T]: WithAttr<T[P]>; 
           } & { attributes?: Record<string, any> } 
         : T;

icholy avatar Oct 05 '23 01:10 icholy

@icholy how do you use this WithAttr? because in some sense even something that would have been a string could have attributes too?

roopakv avatar Jan 03 '24 07:01 roopakv