fix: undesired null or empty parameters are now removed from configuredProperties upon submitting POST and PUT requests
@@ -2,10 +2,7 @@ import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { ApiHttpService } from '@syndesis/ui/platform';
-import {
- ApiConnectors,
- ApiConnectorData, CustomConnectorRequest
-} from './api-connector.models';
+import { ApiConnectors, ApiConnectorData, CustomConnectorRequest } from './api-connector.models';
@Injectable()
export class ApiConnectorService {
@@ -40,12 +37,14 @@ export class ApiConnectorService {
createCustomConnector(customConnectorRequest: CustomConnectorRequest): Observable<any> {
const apiHttpService = this.apiHttpService.setEndpointUrl('submitCustomConnector');
- const [connectorSettings, icon, specification] = [
+ const [rawConnectorSettings, icon, specification] = [
customConnectorRequest,
customConnectorRequest.iconFile,
customConnectorRequest.specificationFile
];
+ const connectorSettings = this.sanitizeCustomConnectorRequest(rawConnectorSettings);
+
if (specification || icon) {
const payload = specification && icon ? { specification, icon } : { specification } || { icon };
return apiHttpService.upload(payload, { connectorSettings });
@@ -56,11 +55,13 @@ export class ApiConnectorService {
updateCustomConnector(customConnectorRequest: CustomConnectorRequest): Observable<any> {
const apiHttpService = this.apiHttpService.setEndpointUrl('selectApiConnector', { id: customConnectorRequest.id });
- const [connector, icon] = [
+ const [rawConnector, icon] = [
customConnectorRequest,
customConnectorRequest.iconFile
];
+ const connector = this.sanitizeCustomConnectorRequest(rawConnector);
+
if (icon) {
return apiHttpService.upload({ icon }, { connector }, 'PUT');
} else {
@@ -73,4 +74,22 @@ export class ApiConnectorService {
.setEndpointUrl('selectApiConnector', { id })
.delete<any>();
}
+
+ // Custom connector requests need to be sanitized prior to be submitted to the API
+ // Please read: https://github.com/syndesisio/syndesis/issues/980
+ private sanitizeCustomConnectorRequest(customConnector: CustomConnectorRequest): CustomConnectorRequest {
+ const configuredProperties = { ...customConnector.configuredProperties };
+
+ for (const key in configuredProperties) {
+ if (configuredProperties.hasOwnProperty(key)) {
+ if (configuredProperties[key] == null
+ || configuredProperties[key] == undefined
+ || configuredProperties[key] === '') {
+ delete configuredProperties[key];
+ }
+ }
+ }
+
+ return { ...customConnector, configuredProperties };
+ }
}
