Skip to content

Commit

Permalink
Merge d601d18 into 699b984
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed May 27, 2020
2 parents 699b984 + d601d18 commit 620423f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Readme.md
Expand Up @@ -1191,6 +1191,23 @@ soap.createClient(__dirname+'/wsdl/fixedPath/netsuite.wsdl', options, function(e
});
```

### Overriding import locations

You can override the URIs or paths of imports in the WSDL by specifying a `overrideImportLocation` function in the WSDL options.

```javascript
const options ={
wsdl_options = {
overrideImportLocation: (location) => {
return 'https://127.0.0.1/imported-service.wsdl';
}
}
};
soap.createClient('https://127.0.0.1/service.wsdl', options, function(err, client) {
// your code
});
```
### Specifying the exact namespace definition of the root element
In rare cases, you may want to precisely control the namespace definition that is included in the root element.
Expand Down
4 changes: 4 additions & 0 deletions src/wsdl/index.ts
Expand Up @@ -1169,6 +1169,10 @@ export class WSDL {
includePath = url.resolve(this.uri || '', include.location);
}

if (this.options.wsdl_options !== undefined && typeof this.options.wsdl_options.overrideImportLocation === 'function') {
includePath = this.options.wsdl_options.overrideImportLocation(includePath);
}

const options = _.assign({}, this.options);
// follow supplied ignoredNamespaces option
options.ignoredNamespaces = this._originalIgnoredNamespaces || this.options.ignoredNamespaces;
Expand Down
20 changes: 20 additions & 0 deletions test/wsdl-test.js
Expand Up @@ -51,6 +51,26 @@ describe('WSDL Parser (strict)', () => {
});
});

it('should support the overrideImportLocation option', (done) => {
const options = {
strict: true,
wsdl_options: {
overrideImportLocation: (location) => {
return location.replace('sub.wsdl', 'overridden.wsdl');
}
},
disableCache: true,
};

soap.createClient(__dirname+'/wsdl/wsdlImport/main.wsdl', options, function(err, client){
assert.ifError(err);
assert.deepEqual(Object.keys(client.wsdl.definitions.schemas),
['http://example.com/', 'http://schemas.microsoft.com/2003/10/Serialization/Arrays']);
assert.equal(typeof client.getLatestVersionOverridden, 'function');
done();
});
});

it('should get the parent namespace when parent namespace is empty string', (done) => {
soap.createClient(__dirname+'/wsdl/marketo.wsdl', {strict: true}, function(err, client){
assert.ifError(err);
Expand Down
36 changes: 36 additions & 0 deletions test/wsdl/wsdlImport/overridden.wsdl
@@ -0,0 +1,36 @@
<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="IUserRemoteService" targetNamespace="http://example.com/" xmlns:ns1="http://example.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xs:schema elementFormDefault="unqualified" targetNamespace="http://example.com/" version="1.0" xmlns:tns="http://example.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation="./xsd.xsd" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>

<xs:element name="getLatestVersionOverridden" type="tns:getLatestVersionOverridden" />
<xs:element name="getLatestVersionOverriddenResponse" type="tns:getLatestVersionOverriddenResponse" />

<xs:complexType name="getLatestVersionOverridden">
<xs:sequence />
</xs:complexType>
<xs:complexType name="getLatestVersionOverriddenResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:long" />
</xs:sequence>
</xs:complexType>

</xs:schema>
</wsdl:types>
<wsdl:message name="getLatestVersionOverridden">
<wsdl:part element="ns1:getLatestVersionOverridden" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getLatestVersionOverriddenResponse">
<wsdl:part element="ns1:getLatestVersionOverriddenResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="IUserRemoteService">
<wsdl:operation name="getLatestVersionOverridden">
<wsdl:input message="ns1:getLatestVersionOverridden" name="getLatestVersionOverridden">
</wsdl:input>
<wsdl:output message="ns1:getLatestVersionOverriddenResponse" name="getLatestVersionOverriddenResponse">
</wsdl:output>
</wsdl:operation>

</wsdl:portType>
</wsdl:definitions>

0 comments on commit 620423f

Please sign in to comment.