From e46b2785d036b2f6920eea9aefb5a93307618231 Mon Sep 17 00:00:00 2001 From: Ryan O'Neill Date: Mon, 6 May 2019 18:55:01 +0000 Subject: [PATCH] scrooge-generator: Provide Implementation for ServicePerEndpoint.filtered Problem / Solution Classes which extend `ServicePerEndpoint` are not provided with a working implementation of its `filtered` method. This can be confusing for users who attempt to apply a TypeAgnostic filter and find that it does't work without overriding the `filtered` method to provide a concrete implementation. Compounding the problem is that using `ServicePerEndpoint.apply` does return an instance with a working `filtered` method. So, let's delegate the implementation of the extension to the companion object. JIRA Issues: CSL-8042 Differential Revision: https://phabricator.twitter.biz/D309920 --- CHANGELOG.rst | 3 +++ .../twitter/scrooge/test/gold/thriftscala/GoldService.scala | 6 ++++-- .../scrooge/test/gold/thriftscala/PlatinumService.scala | 6 ++++-- .../src/main/resources/scalagen/service.mustache | 6 ++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c67d3ed87..70841c7c8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,9 @@ Note that ``PHAB_ID=#`` and ``RB_ID=#`` correspond to associated messages in com Unreleased ---------- +* scrooge-generator: Extensions of (ReqRep)ServicePerEndpoint now provide a proper `filtered` + method by default. ``PHAB_ID=D309920`` + 19.4.0 ------ diff --git a/scrooge-generator-tests/src/test/resources/gold_file_output_scala/com/twitter/scrooge/test/gold/thriftscala/GoldService.scala b/scrooge-generator-tests/src/test/resources/gold_file_output_scala/com/twitter/scrooge/test/gold/thriftscala/GoldService.scala index 94691e435..2d338f3ab 100644 --- a/scrooge-generator-tests/src/test/resources/gold_file_output_scala/com/twitter/scrooge/test/gold/thriftscala/GoldService.scala +++ b/scrooge-generator-tests/src/test/resources/gold_file_output_scala/com/twitter/scrooge/test/gold/thriftscala/GoldService.scala @@ -66,7 +66,8 @@ object GoldService extends _root_.com.twitter.finagle.thrift.GeneratedThriftServ * Prepends the given type-agnostic `Filter` to all of the `Services` * and returns a copy of the `ServicePerEndpoint` now including the filter. */ - def filtered(filter: _root_.com.twitter.finagle.Filter.TypeAgnostic): ServicePerEndpoint = this + def filtered(filter: _root_.com.twitter.finagle.Filter.TypeAgnostic): ServicePerEndpoint = + ServicePerEndpoint.apply(doGreatThings).filtered(filter) /** * Converts the `ServicePerEndpoint` to a `GeneratedThriftService`. @@ -92,7 +93,8 @@ object GoldService extends _root_.com.twitter.finagle.thrift.GeneratedThriftServ * Prepends the given type-agnostic `Filter` to all of the `Services` * and returns a copy of the `ServicePerEndpoint` now including the filter. */ - def filtered(filter: com.twitter.finagle.Filter.TypeAgnostic): ReqRepServicePerEndpoint = this + def filtered(filter: com.twitter.finagle.Filter.TypeAgnostic): ReqRepServicePerEndpoint = + ReqRepServicePerEndpoint.apply(doGreatThings).filtered(filter) /** * Converts the `ServicePerEndpoint` to a `GeneratedThriftService`. diff --git a/scrooge-generator-tests/src/test/resources/gold_file_output_scala/com/twitter/scrooge/test/gold/thriftscala/PlatinumService.scala b/scrooge-generator-tests/src/test/resources/gold_file_output_scala/com/twitter/scrooge/test/gold/thriftscala/PlatinumService.scala index 25596742a..3da9033ec 100644 --- a/scrooge-generator-tests/src/test/resources/gold_file_output_scala/com/twitter/scrooge/test/gold/thriftscala/PlatinumService.scala +++ b/scrooge-generator-tests/src/test/resources/gold_file_output_scala/com/twitter/scrooge/test/gold/thriftscala/PlatinumService.scala @@ -66,7 +66,8 @@ object PlatinumService extends _root_.com.twitter.finagle.thrift.GeneratedThrift * Prepends the given type-agnostic `Filter` to all of the `Services` * and returns a copy of the `ServicePerEndpoint` now including the filter. */ - override def filtered(filter: _root_.com.twitter.finagle.Filter.TypeAgnostic): ServicePerEndpoint = this + override def filtered(filter: _root_.com.twitter.finagle.Filter.TypeAgnostic): ServicePerEndpoint = + ServicePerEndpoint.apply(moreCoolThings, doGreatThings).filtered(filter) /** * Converts the `ServicePerEndpoint` to a `GeneratedThriftService`. @@ -94,7 +95,8 @@ object PlatinumService extends _root_.com.twitter.finagle.thrift.GeneratedThrift * Prepends the given type-agnostic `Filter` to all of the `Services` * and returns a copy of the `ServicePerEndpoint` now including the filter. */ - override def filtered(filter: com.twitter.finagle.Filter.TypeAgnostic): ReqRepServicePerEndpoint = this + override def filtered(filter: com.twitter.finagle.Filter.TypeAgnostic): ReqRepServicePerEndpoint = + ReqRepServicePerEndpoint.apply(moreCoolThings, doGreatThings).filtered(filter) /** * Converts the `ServicePerEndpoint` to a `GeneratedThriftService`. diff --git a/scrooge-generator/src/main/resources/scalagen/service.mustache b/scrooge-generator/src/main/resources/scalagen/service.mustache index c84126e96..969c24620 100644 --- a/scrooge-generator/src/main/resources/scalagen/service.mustache +++ b/scrooge-generator/src/main/resources/scalagen/service.mustache @@ -90,7 +90,8 @@ object {{ServiceName}} {{#withFinagle}}extends _root_.com.twitter.finagle.thrift * Prepends the given type-agnostic `Filter` to all of the `Services` * and returns a copy of the `ServicePerEndpoint` now including the filter. */ - {{#parent}}override {{/parent}}def filtered(filter: _root_.com.twitter.finagle.Filter.TypeAgnostic): ServicePerEndpoint = this + {{#parent}}override {{/parent}}def filtered(filter: _root_.com.twitter.finagle.Filter.TypeAgnostic): ServicePerEndpoint = + ServicePerEndpoint.apply({{#inheritedFunctions}}{{dedupedFuncName}}{{/inheritedFunctions|, }}).filtered(filter) /** * Converts the `ServicePerEndpoint` to a `GeneratedThriftService`. @@ -126,7 +127,8 @@ object {{ServiceName}} {{#withFinagle}}extends _root_.com.twitter.finagle.thrift * Prepends the given type-agnostic `Filter` to all of the `Services` * and returns a copy of the `ServicePerEndpoint` now including the filter. */ - {{#parent}}override {{/parent}}def filtered(filter: com.twitter.finagle.Filter.TypeAgnostic): ReqRepServicePerEndpoint = this + {{#parent}}override {{/parent}}def filtered(filter: com.twitter.finagle.Filter.TypeAgnostic): ReqRepServicePerEndpoint = + ReqRepServicePerEndpoint.apply({{#inheritedFunctions}}{{dedupedFuncName}}{{/inheritedFunctions|, }}).filtered(filter) /** * Converts the `ServicePerEndpoint` to a `GeneratedThriftService`.