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

Update ServiceEndpoint to support sets and maps #485

Merged
merged 8 commits into from
Nov 9, 2021

Conversation

cycraig
Copy link
Contributor

@cycraig cycraig commented Nov 5, 2021

Description of change

Update the serviceEndpoint field of Service to allow an ordered set or map as well as the current single URL. Note that "ordered" refers to maintaining the order of insertion, not comparison.

/// An endpoint or set of endpoints specified in a [`Service`].
///
/// [Specification](https://www.w3.org/TR/did-core/#dfn-serviceendpoint)
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[serde(untagged)]
pub enum ServiceEndpoint {
  One(Url),
  Set(OrderedSet<Url>),
  Map(IndexMap<String, OrderedSet<Url>>),
  // TODO: enforce set/map is non-empty?
}

This is in line with the DID specification: https://www.w3.org/TR/did-core/#dfn-serviceendpoint

The value of the serviceEndpoint property MUST be a string, a map, or a set composed of one or more strings and/or maps. All string values MUST be valid URIs conforming to [RFC3986] and normalized according to the Normalization and Comparison rules in RFC3986 and to any normalization rules in its applicable URI scheme specification.

One thing to note is that this PR allows empty sets and maps while the spec specifies "one or more". This is mostly due to ergonomics to avoid clunky wrapping types but can be changed if necessary.

Also according to the spec, we should allow nested maps in serviceEndpoint sets and maps too. Considering that would complicate the Rust types and usability quite a bit, it was decided not to support nested maps at this time.

Links to any relevant issues

Resolves issue #447.

Type of change

Add an x to the boxes that are relevant to your changes.

  • Bug fix (a non-breaking change which fixes an issue)
  • Enhancement (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Fix

How the change has been tested

Describe the tests that you ran to verify your changes.
Make sure to provide instructions for the maintainer as well as any relevant configurations.

Change checklist

Add an x to the boxes that are relevant to your changes.

  • I have followed the contribution guidelines for this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@cycraig cycraig added Enhancement New feature or improvement to an existing feature Breaking change A change to the API that requires a major release. Part of "Changed" section in changelog labels Nov 5, 2021
@cycraig cycraig changed the title Add ServiceEndpoint sets Add ServiceEndpoint sets and maps Nov 8, 2021
@cycraig cycraig marked this pull request as ready for review November 8, 2021 12:27
Copy link
Contributor

@olivereanderson olivereanderson left a comment

Choose a reason for hiding this comment

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

Good work. Appreciate the new tests to the changed/new functionality.

@cycraig cycraig merged commit e05ca5b into dev Nov 9, 2021
@cycraig cycraig deleted the feat/service-endpoint-set branch November 9, 2021 07:59
@cycraig cycraig changed the title Add ServiceEndpoint sets and maps Update ServiceEndpoint to support sets and maps Dec 15, 2021
@cycraig cycraig added Rust Related to the core Rust code. Becomes part of the Rust changelog. Wasm Related to Wasm bindings. Becomes part of the Wasm changelog labels Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking change A change to the API that requires a major release. Part of "Changed" section in changelog Enhancement New feature or improvement to an existing feature Rust Related to the core Rust code. Becomes part of the Rust changelog. Wasm Related to Wasm bindings. Becomes part of the Wasm changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants