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

Generic derivation of enumeration schemas #184

Open
julienrf opened this issue Nov 16, 2018 · 0 comments
Open

Generic derivation of enumeration schemas #184

julienrf opened this issue Nov 16, 2018 · 0 comments

Comments

@julienrf
Copy link
Member

julienrf commented Nov 16, 2018

#183 added support for enumerations in the algebra. However, generic derivation of schemas only produces oneOf schemas instead of enumerations. We could improve our derivation mechanism to return an enumeration schema for sealed traits having case objects only.

One approach could be to test whether a Coproduct is an enumeration in an implicit rule with a higher priority than the current rule for coproducts (genericTagged):

implicit def genericEnumeration[A, R](implicit
  gen: LabelledGeneric.Aux[A, R],
  enum: GenericEnum[R],
  ct: ClassTag[A]
): GenericEnum[R] =

Where GenericEnum is defined as follows:

trait GenericEnum[A] extends GenericJsonSchema[A] {
  def jsonSchema: Enum[A]
}

And its derivation rule checks that all the elements of the coproduct are singleton objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant