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

Wrap coproducts in Option #198

Merged
merged 4 commits into from Jan 2, 2020
Merged

Wrap coproducts in Option #198

merged 4 commits into from Jan 2, 2020

Conversation

cb372
Copy link
Member

@cb372 cb372 commented Jan 2, 2020

This is so they can be encoded as oneof fields in protobuf using pbdirect (see 47degrees/pbdirect#30).

Also stop wrapping repeated field elements in Option when parsing protobuf protocols.

This is for compatibility with pbdirect. See 47degrees/pbdirect#30
This way it only affects schemas produced from a protobuf definition,
not all schemas.
@@ -50,7 +50,7 @@ object Transform {
case ProtobufF.TEnum(name, symbols, _, _) => TSum(name, symbols.map(SumField.tupled))
case ProtobufF.TMessage(name, fields, _) => TProduct(name, fields.map(f => Field(f.name, f.tpe, f.indices)))
case ProtobufF.TFileDescriptor(values, _, _) => TContaining(values)
case ProtobufF.TOneOf(_, fields) => TCoproduct(fields.map(_.tpe))
case ProtobufF.TOneOf(_, fields) => TOption(A.algebra(TCoproduct(fields.map(_.tpe))))
Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for the noisy diff. This is one of the actual changes.

@@ -197,7 +197,7 @@ object ParseProto {
FieldF.Field(
name = field.getName,
position = field.getNumber,
tpe = repeated[A](fromFieldType(field, files, makeNamedTypesOptional = true)).embed,
tpe = repeated[A](fromFieldType(field, files, makeNamedTypesOptional = false)).embed,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the other change.

@@ -83,7 +83,7 @@ class ProtobufProtocolSpec extends Specification with ScalaCheck {
|@message final case class Book(
| @_root_.pbdirect.pbIndex(1) isbn: _root_.scala.Long,
| @_root_.pbdirect.pbIndex(2) title: _root_.java.lang.String,
| @_root_.pbdirect.pbIndex(3) author: _root_.scala.List[_root_.scala.Option[_root_.com.acme.author.Author]],
| @_root_.pbdirect.pbIndex(3) author: _root_.scala.List[_root_.com.acme.author.Author],
Copy link
Member Author

Choose a reason for hiding this comment

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

This is updating the test.

@cb372 cb372 merged commit 8915bb6 into master Jan 2, 2020
@cb372 cb372 deleted the wrap-coproduct-in-option branch January 2, 2020 11:43
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

Successfully merging this pull request may close these issues.

None yet

2 participants