1 /*
2  *  Make.org Core API
3  *  Copyright (C) 2021 Make.org
4  *
5  * This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU Affero General Public License as
7  *  published by the Free Software Foundation, either version 3 of the
8  *  License, or (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU Affero General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Affero General Public License
16  *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  *
18  */
19 
20 package org.make.api.operation
21 
22 import enumeratum.{Circe, Enum, EnumEntry}
23 import io.circe.{Codec, Decoder, Encoder}
24 import io.circe.generic.semiauto.deriveCodec
25 import io.swagger.annotations.ApiModelProperty
26 import org.make.core.operation.ResultsLink
27 
28 import scala.annotation.meta.field
29 
30 final case class ResultsLinkResponse(
31   @(ApiModelProperty @field)(
32     dataType = "string",
33     required = true,
34     allowableValues = ResultsLinkKind.swaggerAllowableValues
35   )
36   kind: ResultsLinkKind,
37   value: String
38 )
39 object ResultsLinkResponse {
40   def apply(resultsLink: ResultsLink): ResultsLinkResponse = resultsLink match {
41     case ResultsLink.External(url)   => ResultsLinkResponse(ResultsLinkKind.External, url.toString)
42     case ResultsLink.Internal(value) => ResultsLinkResponse(ResultsLinkKind.Internal, value)
43   }
44   implicit val codec: Codec[ResultsLinkResponse] = deriveCodec
45 }
46 
47 sealed abstract class ResultsLinkKind extends EnumEntry
48 
49 object ResultsLinkKind extends Enum[ResultsLinkKind] {
50 
51   case object External extends ResultsLinkKind
52   case object Internal extends ResultsLinkKind
53 
54   override val values: IndexedSeq[ResultsLinkKind] = findValues
55   final val swaggerAllowableValues = "External,Internal"
56 
57   implicit val decoder: Decoder[ResultsLinkKind] = Circe.decodeCaseInsensitive(this)
58   implicit val encoder: Encoder[ResultsLinkKind] = Circe.encoderLowercase(this)
59 
60 }
Line Stmt Id Pos Tree Symbol Tests Code
41 29538 1406 - 1465 Apply org.make.api.operation.ResultsLinkResponse.apply ResultsLinkResponse.apply(ResultsLinkKind.External, url.toString())
41 30016 1452 - 1464 Apply java.net.URI.toString url.toString()
41 28567 1426 - 1450 Select org.make.api.operation.ResultsLinkKind.External ResultsLinkKind.External
42 28708 1526 - 1550 Select org.make.api.operation.ResultsLinkKind.Internal org.make.api.question.questionapitest ResultsLinkKind.Internal
42 30152 1506 - 1558 Apply org.make.api.operation.ResultsLinkResponse.apply org.make.api.question.questionapitest ResultsLinkResponse.apply(ResultsLinkKind.Internal, value)
44 29264 1614 - 1625 ApplyToImplicitArgs io.circe.generic.semiauto.deriveCodec io.circe.generic.semiauto.deriveCodec[org.make.api.operation.ResultsLinkResponse]({ val inst$macro$12: io.circe.generic.codec.DerivedAsObjectCodec[org.make.api.operation.ResultsLinkResponse] = { final class anon$lazy$macro$11 extends AnyRef with Serializable { def <init>(): anon$lazy$macro$11 = { anon$lazy$macro$11.super.<init>(); () }; <stable> <accessor> lazy val inst$macro$1: io.circe.generic.codec.DerivedAsObjectCodec[org.make.api.operation.ResultsLinkResponse] = codec.this.DerivedAsObjectCodec.deriveCodec[org.make.api.operation.ResultsLinkResponse, shapeless.labelled.FieldType[Symbol @@ String("kind"),org.make.api.operation.ResultsLinkKind] :: shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out](shapeless.this.LabelledGeneric.materializeProduct[org.make.api.operation.ResultsLinkResponse, (Symbol @@ String("kind")) :: (Symbol @@ String("value")) :: shapeless.HNil, org.make.api.operation.ResultsLinkKind :: String :: shapeless.HNil, shapeless.labelled.FieldType[Symbol @@ String("kind"),org.make.api.operation.ResultsLinkKind] :: shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out](DefaultSymbolicLabelling.instance[org.make.api.operation.ResultsLinkResponse, (Symbol @@ String("kind")) :: (Symbol @@ String("value")) :: shapeless.HNil](::.apply[Symbol @@ String("kind"), (Symbol @@ String("value")) :: shapeless.HNil.type](scala.Symbol.apply("kind").asInstanceOf[Symbol @@ String("kind")], ::.apply[Symbol @@ String("value"), shapeless.HNil.type](scala.Symbol.apply("value").asInstanceOf[Symbol @@ String("value")], HNil))), Generic.instance[org.make.api.operation.ResultsLinkResponse, org.make.api.operation.ResultsLinkKind :: String :: shapeless.HNil](((x0$3: org.make.api.operation.ResultsLinkResponse) => x0$3 match { case (kind: org.make.api.operation.ResultsLinkKind, value: String): org.make.api.operation.ResultsLinkResponse((kind$macro$8 @ _), (value$macro$9 @ _)) => ::.apply[org.make.api.operation.ResultsLinkKind, String :: shapeless.HNil.type](kind$macro$8, ::.apply[String, shapeless.HNil.type](value$macro$9, HNil)).asInstanceOf[org.make.api.operation.ResultsLinkKind :: String :: shapeless.HNil] }), ((x0$4: org.make.api.operation.ResultsLinkKind :: String :: shapeless.HNil) => x0$4 match { case (head: org.make.api.operation.ResultsLinkKind, tail: String :: shapeless.HNil): org.make.api.operation.ResultsLinkKind :: String :: shapeless.HNil((kind$macro$6 @ _), (head: String, tail: shapeless.HNil): String :: shapeless.HNil((value$macro$7 @ _), HNil)) => operation.this.ResultsLinkResponse.apply(kind$macro$6, value$macro$7) })), hlist.this.ZipWithKeys.hconsZipWithKeys[Symbol @@ String("kind"), org.make.api.operation.ResultsLinkKind, (Symbol @@ String("value")) :: shapeless.HNil, String :: shapeless.HNil, shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out](hlist.this.ZipWithKeys.hconsZipWithKeys[Symbol @@ String("value"), String, shapeless.HNil, shapeless.HNil, shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out](hlist.this.ZipWithKeys.hnilZipWithKeys, Witness.mkWitness[Symbol with shapeless.tag.Tagged[String("value")]](scala.Symbol.apply("value").asInstanceOf[Symbol @@ String("value")].asInstanceOf[Symbol with shapeless.tag.Tagged[String("value")]])), Witness.mkWitness[Symbol with shapeless.tag.Tagged[String("kind")]](scala.Symbol.apply("kind").asInstanceOf[Symbol @@ String("kind")].asInstanceOf[Symbol with shapeless.tag.Tagged[String("kind")]])), scala.this.<:<.refl[shapeless.labelled.FieldType[Symbol @@ String("kind"),org.make.api.operation.ResultsLinkKind] :: shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out]), shapeless.Lazy.apply[io.circe.generic.codec.ReprAsObjectCodec[shapeless.labelled.FieldType[Symbol @@ String("kind"),org.make.api.operation.ResultsLinkKind] :: shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out]](anon$lazy$macro$11.this.inst$macro$10)).asInstanceOf[io.circe.generic.codec.DerivedAsObjectCodec[org.make.api.operation.ResultsLinkResponse]]; <stable> <accessor> lazy val inst$macro$10: io.circe.generic.codec.ReprAsObjectCodec[shapeless.labelled.FieldType[Symbol @@ String("kind"),org.make.api.operation.ResultsLinkKind] :: shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out] = ({ final class $anon extends io.circe.generic.codec.ReprAsObjectCodec[shapeless.labelled.FieldType[Symbol @@ String("kind"),org.make.api.operation.ResultsLinkKind] :: shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out] { def <init>(): <$anon: io.circe.generic.codec.ReprAsObjectCodec[shapeless.labelled.FieldType[Symbol @@ String("kind"),org.make.api.operation.ResultsLinkKind] :: shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out]> = { $anon.super.<init>(); () }; private[this] val circeGenericDecoderForkind: io.circe.Decoder[org.make.api.operation.ResultsLinkKind] = operation.this.ResultsLinkKind.decoder; private[this] val circeGenericDecoderForvalue: io.circe.Decoder[String] = circe.this.Decoder.decodeString; private[this] val circeGenericEncoderForkind: io.circe.Encoder[org.make.api.operation.ResultsLinkKind] = operation.this.ResultsLinkKind.encoder; private[this] val circeGenericEncoderForvalue: io.circe.Encoder[String] = circe.this.Encoder.encodeString; final def encodeObject(a: shapeless.labelled.FieldType[Symbol @@ String("kind"),org.make.api.operation.ResultsLinkKind] :: shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out): io.circe.JsonObject = a match { case (head: shapeless.labelled.FieldType[Symbol @@ String("kind"),org.make.api.operation.ResultsLinkKind], tail: shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out): shapeless.labelled.FieldType[Symbol @@ String("kind"),org.make.api.operation.ResultsLinkKind] :: shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out((circeGenericHListBindingForkind @ _), (head: shapeless.labelled.FieldType[Symbol @@ String("value"),String], tail: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out): shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out((circeGenericHListBindingForvalue @ _), shapeless.HNil)) => io.circe.JsonObject.fromIterable(scala.collection.immutable.Vector.apply[(String, io.circe.Json)](scala.Tuple2.apply[String, io.circe.Json]("kind", $anon.this.circeGenericEncoderForkind.apply(circeGenericHListBindingForkind)), scala.Tuple2.apply[String, io.circe.Json]("value", $anon.this.circeGenericEncoderForvalue.apply(circeGenericHListBindingForvalue)))) }; final def apply(c: io.circe.HCursor): io.circe.Decoder.Result[shapeless.labelled.FieldType[Symbol @@ String("kind"),org.make.api.operation.ResultsLinkKind] :: shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out] = ReprDecoder.consResults[io.circe.Decoder.Result, Symbol @@ String("kind"), org.make.api.operation.ResultsLinkKind, shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out]($anon.this.circeGenericDecoderForkind.tryDecode(c.downField("kind")), ReprDecoder.consResults[io.circe.Decoder.Result, Symbol @@ String("value"), String, shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out]($anon.this.circeGenericDecoderForvalue.tryDecode(c.downField("value")), ReprDecoder.hnilResult)(io.circe.Decoder.resultInstance))(io.circe.Decoder.resultInstance); final override def decodeAccumulating(c: io.circe.HCursor): io.circe.Decoder.AccumulatingResult[shapeless.labelled.FieldType[Symbol @@ String("kind"),org.make.api.operation.ResultsLinkKind] :: shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out] = ReprDecoder.consResults[io.circe.Decoder.AccumulatingResult, Symbol @@ String("kind"), org.make.api.operation.ResultsLinkKind, shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out]($anon.this.circeGenericDecoderForkind.tryDecodeAccumulating(c.downField("kind")), ReprDecoder.consResults[io.circe.Decoder.AccumulatingResult, Symbol @@ String("value"), String, shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out]($anon.this.circeGenericDecoderForvalue.tryDecodeAccumulating(c.downField("value")), ReprDecoder.hnilResultAccumulating)(io.circe.Decoder.accumulatingResultInstance))(io.circe.Decoder.accumulatingResultInstance) }; new $anon() }: io.circe.generic.codec.ReprAsObjectCodec[shapeless.labelled.FieldType[Symbol @@ String("kind"),org.make.api.operation.ResultsLinkKind] :: shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out]).asInstanceOf[io.circe.generic.codec.ReprAsObjectCodec[shapeless.labelled.FieldType[Symbol @@ String("kind"),org.make.api.operation.ResultsLinkKind] :: shapeless.labelled.FieldType[Symbol @@ String("value"),String] :: shapeless.ops.hlist.ZipWithKeys.hnilZipWithKeys.Out]] }; new anon$lazy$macro$11().inst$macro$1 }; shapeless.Lazy.apply[io.circe.generic.codec.DerivedAsObjectCodec[org.make.api.operation.ResultsLinkResponse]](inst$macro$12) })
55 28502 1938 - 1957 Literal <nosymbol> "External,Internal"
57 30208 2010 - 2043 Apply enumeratum.Circe.decodeCaseInsensitive org.make.api.operation.defaultmoderationoperationofquestionapicomponenttest enumeratum.Circe.decodeCaseInsensitive[org.make.api.operation.ResultsLinkKind](this)
58 29411 2095 - 2123 Apply enumeratum.Circe.encoderLowercase org.make.api.operation.defaultmoderationoperationofquestionapicomponenttest enumeratum.Circe.encoderLowercase[org.make.api.operation.ResultsLinkKind](this)