diff --git a/lib/core/versions/1.0/DocumentComposer.ts b/lib/core/versions/1.0/DocumentComposer.ts index 673d23c9e..631490ff0 100644 --- a/lib/core/versions/1.0/DocumentComposer.ts +++ b/lib/core/versions/1.0/DocumentComposer.ts @@ -345,22 +345,26 @@ export default class DocumentComposer { } // `serviceEndpoint` validations. - const serviceEndpoint = service.serviceEndpoint; - if (typeof serviceEndpoint === 'string') { - const uri = URI.parse(service.serviceEndpoint); - if (uri.error !== undefined) { - throw new SidetreeError( - ErrorCode.DocumentComposerPatchServiceEndpointStringNotValidUri, - `Service endpoint string '${serviceEndpoint}' is not a valid URI.` - ); - } - } else if (typeof serviceEndpoint === 'object') { - // Allow `object` type only if it is not an array. - if (Array.isArray(serviceEndpoint)) { - throw new SidetreeError(ErrorCode.DocumentComposerPatchServiceEndpointCannotBeAnArray); + // transform URI strings and JSON objects into array so that we can run validations more easily + const serviceEndpointValueAsArray = Array.isArray(service.serviceEndpoint) ? service.serviceEndpoint : [service.serviceEndpoint]; + for (const serviceEndpoint of serviceEndpointValueAsArray) { + // serviceEndpoint itself must be URI string or non-array object + if (typeof serviceEndpoint === 'string') { + const uri = URI.parse(serviceEndpoint); + if (uri.error !== undefined) { + throw new SidetreeError( + ErrorCode.DocumentComposerPatchServiceEndpointStringNotValidUri, + `Service endpoint string '${serviceEndpoint}' is not a valid URI.` + ); + } + } else if (typeof serviceEndpoint === 'object') { + // Allow `object` type only if it is not an array. + if (Array.isArray(serviceEndpoint)) { + throw new SidetreeError(ErrorCode.DocumentComposerPatchServiceEndpointCannotBeAnArray); + } + } else { + throw new SidetreeError(ErrorCode.DocumentComposerPatchServiceEndpointMustBeStringOrNonArrayObject); } - } else { - throw new SidetreeError(ErrorCode.DocumentComposerPatchServiceEndpointMustBeStringOrNonArrayObject); } } } diff --git a/lib/core/versions/1.0/models/ServiceModel.ts b/lib/core/versions/1.0/models/ServiceModel.ts index 6429897ea..45c81bf3a 100644 --- a/lib/core/versions/1.0/models/ServiceModel.ts +++ b/lib/core/versions/1.0/models/ServiceModel.ts @@ -4,5 +4,5 @@ export default interface ServiceModel { id: string; type: string; - serviceEndpoint: string | object; + serviceEndpoint: string | object | Array; }