From c3a876ef4e65e7041000a4fd1e37a583383a6512 Mon Sep 17 00:00:00 2001 From: Michael Bryzek Date: Tue, 30 Jul 2024 21:54:17 +0200 Subject: [PATCH 1/2] wip --- .../app/ApicollectiveApibuilderSpecV0Client.scala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/generated/app/ApicollectiveApibuilderSpecV0Client.scala b/generated/app/ApicollectiveApibuilderSpecV0Client.scala index 461b713fa..b5cb03524 100644 --- a/generated/app/ApicollectiveApibuilderSpecV0Client.scala +++ b/generated/app/ApicollectiveApibuilderSpecV0Client.scala @@ -457,6 +457,8 @@ package io.apibuilder.spec.v0.models { package io.apibuilder.spec.v0.models { + import play.api.libs.json.JsObject + package object json { import play.api.libs.json.__ import play.api.libs.json.JsString @@ -1390,6 +1392,7 @@ package io.apibuilder.spec.v0.models { } implicit def jsonReadsApibuilderSpecResponseCode[T <: io.apibuilder.spec.v0.models.ResponseCode]: play.api.libs.json.Reads[T] = (json: play.api.libs.json.JsValue) => { + println(s"jsonReadsApibuilderSpecResponseCode: $json") Seq( jsonReadsApibuilderSpecResponseCodeInt.reads(json).map(_.asInstanceOf[T]), jsonReadsApibuilderSpecResponseCodeOption.reads(json).map(_.asInstanceOf[T]) @@ -1416,7 +1419,14 @@ package io.apibuilder.spec.v0.models { obj match { case x: io.apibuilder.spec.v0.models.ResponseCodeInt => play.api.libs.json.Json.obj("integer" -> play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsNumber(x.value))) case x: io.apibuilder.spec.v0.models.ResponseCodeOption => play.api.libs.json.Json.obj("response_code_option" -> play.api.libs.json.JsString(x.toString)) - case x: io.apibuilder.spec.v0.models.ResponseCodeUndefinedType => sys.error(s"The type[io.apibuilder.spec.v0.models.ResponseCodeUndefinedType] should never be serialized") + case x: io.apibuilder.spec.v0.models.ResponseCodeUndefinedType => { + scala.util.Try { + play.api.libs.json.Json.parse(x.description).asInstanceOf[play.api.libs.json.JsObject] + } match { + case scala.util.Success(o) => o + case scala.util.Failure(_) => sys.error(s"The type[io.apibuilder.spec.v0.models.ResponseCodeUndefinedType] should never be serialized") + } + } } } From d0e3db7b3356bcf98140ddeed44e08f5f4aacefe Mon Sep 17 00:00:00 2001 From: Michael Bryzek Date: Tue, 30 Jul 2024 22:02:53 +0200 Subject: [PATCH 2/2] wip --- .../ApicollectiveApibuilderSpecV0Client.scala | 13 +- .../ApicollectiveApibuilderTaskV0Client.scala | 137 ++++++------------ .../ApicollectiveApibuilderSpecV0Models.scala | 17 ++- 3 files changed, 69 insertions(+), 98 deletions(-) diff --git a/generated/app/ApicollectiveApibuilderSpecV0Client.scala b/generated/app/ApicollectiveApibuilderSpecV0Client.scala index b5cb03524..2fef1ce82 100644 --- a/generated/app/ApicollectiveApibuilderSpecV0Client.scala +++ b/generated/app/ApicollectiveApibuilderSpecV0Client.scala @@ -1,7 +1,7 @@ /** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.16.53 - * User agent: apibuilder app.apibuilder.io/apicollective/apibuilder-spec/latest/play_2_9_scala_3_client + * User agent: apibuilder localhost 9000/apicollective/apibuilder-spec/latest/play_2_9_scala_3_client */ package io.apibuilder.spec.v0.models { @@ -457,8 +457,6 @@ package io.apibuilder.spec.v0.models { package io.apibuilder.spec.v0.models { - import play.api.libs.json.JsObject - package object json { import play.api.libs.json.__ import play.api.libs.json.JsString @@ -1392,7 +1390,6 @@ package io.apibuilder.spec.v0.models { } implicit def jsonReadsApibuilderSpecResponseCode[T <: io.apibuilder.spec.v0.models.ResponseCode]: play.api.libs.json.Reads[T] = (json: play.api.libs.json.JsValue) => { - println(s"jsonReadsApibuilderSpecResponseCode: $json") Seq( jsonReadsApibuilderSpecResponseCodeInt.reads(json).map(_.asInstanceOf[T]), jsonReadsApibuilderSpecResponseCodeOption.reads(json).map(_.asInstanceOf[T]) @@ -1419,12 +1416,16 @@ package io.apibuilder.spec.v0.models { obj match { case x: io.apibuilder.spec.v0.models.ResponseCodeInt => play.api.libs.json.Json.obj("integer" -> play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsNumber(x.value))) case x: io.apibuilder.spec.v0.models.ResponseCodeOption => play.api.libs.json.Json.obj("response_code_option" -> play.api.libs.json.JsString(x.toString)) + case x: io.apibuilder.spec.v0.models.ResponseCodeUndefinedType => { scala.util.Try { + // If we received a JSON object - echo it back. This is a workaround for a bug in + // serialization for unions w/out discriminators where they sometimes have the + // type wrapper and sometimes do not play.api.libs.json.Json.parse(x.description).asInstanceOf[play.api.libs.json.JsObject] } match { case scala.util.Success(o) => o - case scala.util.Failure(_) => sys.error(s"The type[io.apibuilder.spec.v0.models.ResponseCodeUndefinedType] should never be serialized") + case scala.util.Failure(_) => sys.error("The type[io.apibuilder.spec.v0.models.ResponseCodeUndefinedType] should never be serialized") } } } @@ -1574,7 +1575,7 @@ package io.apibuilder.spec.v0 { object Constants { val Namespace = "io.apibuilder.spec.v0" - val UserAgent = "apibuilder app.apibuilder.io/apicollective/apibuilder-spec/latest/play_2_9_scala_3_client" + val UserAgent = "apibuilder localhost 9000/apicollective/apibuilder-spec/latest/play_2_9_scala_3_client" val Version = "0.16.53" val VersionMajor = 0 diff --git a/generated/app/ApicollectiveApibuilderTaskV0Client.scala b/generated/app/ApicollectiveApibuilderTaskV0Client.scala index e16223600..44a65d5bb 100644 --- a/generated/app/ApicollectiveApibuilderTaskV0Client.scala +++ b/generated/app/ApicollectiveApibuilderTaskV0Client.scala @@ -1,41 +1,11 @@ /** * Generated by API Builder - https://www.apibuilder.io - * Service version: 0.16.50 + * Service version: 0.16.53 * User agent: apibuilder localhost 9000/apicollective/apibuilder-task/latest/play_2_9_scala_3_client */ package io.apibuilder.task.v0.models { - sealed trait EmailData extends _root_.scala.Product with _root_.scala.Serializable { - def emailDataDiscriminator: EmailDataDiscriminator - - } - - /** - * Defines the valid discriminator values for the type EmailData - */ - sealed trait EmailDataDiscriminator extends _root_.scala.Product with _root_.scala.Serializable - - object EmailDataDiscriminator { - - case object EmailDataApplicationCreated extends EmailDataDiscriminator { override def toString = "email_data_application_created" } - case object EmailDataEmailVerificationCreated extends EmailDataDiscriminator { override def toString = "email_data_email_verification_created" } - case object EmailDataMembershipCreated extends EmailDataDiscriminator { override def toString = "email_data_membership_created" } - case object EmailDataMembershipRequestCreated extends EmailDataDiscriminator { override def toString = "email_data_membership_request_created" } - case object EmailDataMembershipRequestAccepted extends EmailDataDiscriminator { override def toString = "email_data_membership_request_accepted" } - case object EmailDataMembershipRequestDeclined extends EmailDataDiscriminator { override def toString = "email_data_membership_request_declined" } - case object EmailDataPasswordResetRequestCreated extends EmailDataDiscriminator { override def toString = "email_data_password_reset_request_created" } - - final case class UNDEFINED(override val toString: String) extends EmailDataDiscriminator - - val all: scala.List[EmailDataDiscriminator] = scala.List(EmailDataApplicationCreated, EmailDataEmailVerificationCreated, EmailDataMembershipCreated, EmailDataMembershipRequestCreated, EmailDataMembershipRequestAccepted, EmailDataMembershipRequestDeclined, EmailDataPasswordResetRequestCreated) - - private val byName: Map[String, EmailDataDiscriminator] = all.map(x => x.toString.toLowerCase -> x).toMap - - def apply(value: String): EmailDataDiscriminator = fromString(value).getOrElse(UNDEFINED(value)) - - def fromString(value: String): _root_.scala.Option[EmailDataDiscriminator] = byName.get(value.toLowerCase) - - } + sealed trait EmailData extends _root_.scala.Product with _root_.scala.Serializable final case class DiffVersionData( oldVersionGuid: _root_.java.util.UUID, newVersionGuid: _root_.java.util.UUID @@ -43,48 +13,34 @@ package io.apibuilder.task.v0.models { final case class EmailDataApplicationCreated( applicationGuid: _root_.java.util.UUID - ) extends EmailData { - override val emailDataDiscriminator: EmailDataDiscriminator = EmailDataDiscriminator.EmailDataApplicationCreated - } + ) extends EmailData final case class EmailDataEmailVerificationCreated( guid: _root_.java.util.UUID - ) extends EmailData { - override val emailDataDiscriminator: EmailDataDiscriminator = EmailDataDiscriminator.EmailDataEmailVerificationCreated - } + ) extends EmailData final case class EmailDataMembershipCreated( guid: _root_.java.util.UUID - ) extends EmailData { - override val emailDataDiscriminator: EmailDataDiscriminator = EmailDataDiscriminator.EmailDataMembershipCreated - } + ) extends EmailData final case class EmailDataMembershipRequestAccepted( organizationGuid: _root_.java.util.UUID, userGuid: _root_.java.util.UUID, role: io.apibuilder.common.v0.models.MembershipRole - ) extends EmailData { - override val emailDataDiscriminator: EmailDataDiscriminator = EmailDataDiscriminator.EmailDataMembershipRequestAccepted - } + ) extends EmailData final case class EmailDataMembershipRequestCreated( guid: _root_.java.util.UUID - ) extends EmailData { - override val emailDataDiscriminator: EmailDataDiscriminator = EmailDataDiscriminator.EmailDataMembershipRequestCreated - } + ) extends EmailData final case class EmailDataMembershipRequestDeclined( organizationGuid: _root_.java.util.UUID, userGuid: _root_.java.util.UUID - ) extends EmailData { - override val emailDataDiscriminator: EmailDataDiscriminator = EmailDataDiscriminator.EmailDataMembershipRequestDeclined - } + ) extends EmailData final case class EmailDataPasswordResetRequestCreated( guid: _root_.java.util.UUID - ) extends EmailData { - override val emailDataDiscriminator: EmailDataDiscriminator = EmailDataDiscriminator.EmailDataPasswordResetRequestCreated - } + ) extends EmailData /** * Provides future compatibility in clients - in the future, when a type is added @@ -97,9 +53,7 @@ package io.apibuilder.task.v0.models { final case class EmailDataUndefinedType( description: String - ) extends EmailData { - override val emailDataDiscriminator: EmailDataDiscriminator = EmailDataDiscriminator.UNDEFINED(description) - } + ) extends EmailData sealed trait TaskType extends _root_.scala.Product with _root_.scala.Serializable object TaskType { @@ -236,7 +190,7 @@ package io.apibuilder.task.v0.models { def jsObjectEmailDataApplicationCreated(obj: io.apibuilder.task.v0.models.EmailDataApplicationCreated): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "application_guid" -> play.api.libs.json.JsString(obj.applicationGuid.toString) - ) ++ play.api.libs.json.Json.obj("discriminator" -> "email_data_application_created") + ) } def jsonWritesApibuilderTaskEmailDataApplicationCreated: play.api.libs.json.Writes[EmailDataApplicationCreated] = { @@ -252,7 +206,7 @@ package io.apibuilder.task.v0.models { def jsObjectEmailDataEmailVerificationCreated(obj: io.apibuilder.task.v0.models.EmailDataEmailVerificationCreated): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "guid" -> play.api.libs.json.JsString(obj.guid.toString) - ) ++ play.api.libs.json.Json.obj("discriminator" -> "email_data_email_verification_created") + ) } def jsonWritesApibuilderTaskEmailDataEmailVerificationCreated: play.api.libs.json.Writes[EmailDataEmailVerificationCreated] = { @@ -268,7 +222,7 @@ package io.apibuilder.task.v0.models { def jsObjectEmailDataMembershipCreated(obj: io.apibuilder.task.v0.models.EmailDataMembershipCreated): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "guid" -> play.api.libs.json.JsString(obj.guid.toString) - ) ++ play.api.libs.json.Json.obj("discriminator" -> "email_data_membership_created") + ) } def jsonWritesApibuilderTaskEmailDataMembershipCreated: play.api.libs.json.Writes[EmailDataMembershipCreated] = { @@ -290,7 +244,7 @@ package io.apibuilder.task.v0.models { "organization_guid" -> play.api.libs.json.JsString(obj.organizationGuid.toString), "user_guid" -> play.api.libs.json.JsString(obj.userGuid.toString), "role" -> play.api.libs.json.JsString(obj.role.toString) - ) ++ play.api.libs.json.Json.obj("discriminator" -> "email_data_membership_request_accepted") + ) } def jsonWritesApibuilderTaskEmailDataMembershipRequestAccepted: play.api.libs.json.Writes[EmailDataMembershipRequestAccepted] = { @@ -306,7 +260,7 @@ package io.apibuilder.task.v0.models { def jsObjectEmailDataMembershipRequestCreated(obj: io.apibuilder.task.v0.models.EmailDataMembershipRequestCreated): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "guid" -> play.api.libs.json.JsString(obj.guid.toString) - ) ++ play.api.libs.json.Json.obj("discriminator" -> "email_data_membership_request_created") + ) } def jsonWritesApibuilderTaskEmailDataMembershipRequestCreated: play.api.libs.json.Writes[EmailDataMembershipRequestCreated] = { @@ -326,7 +280,7 @@ package io.apibuilder.task.v0.models { play.api.libs.json.Json.obj( "organization_guid" -> play.api.libs.json.JsString(obj.organizationGuid.toString), "user_guid" -> play.api.libs.json.JsString(obj.userGuid.toString) - ) ++ play.api.libs.json.Json.obj("discriminator" -> "email_data_membership_request_declined") + ) } def jsonWritesApibuilderTaskEmailDataMembershipRequestDeclined: play.api.libs.json.Writes[EmailDataMembershipRequestDeclined] = { @@ -342,7 +296,7 @@ package io.apibuilder.task.v0.models { def jsObjectEmailDataPasswordResetRequestCreated(obj: io.apibuilder.task.v0.models.EmailDataPasswordResetRequestCreated): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "guid" -> play.api.libs.json.JsString(obj.guid.toString) - ) ++ play.api.libs.json.Json.obj("discriminator" -> "email_data_password_reset_request_created") + ) } def jsonWritesApibuilderTaskEmailDataPasswordResetRequestCreated: play.api.libs.json.Writes[EmailDataPasswordResetRequestCreated] = { @@ -351,26 +305,22 @@ package io.apibuilder.task.v0.models { } } - implicit def jsonReadsApibuilderTaskEmailData[T <: io.apibuilder.task.v0.models.EmailData]: play.api.libs.json.Reads[T] = (js: play.api.libs.json.JsValue) => { - def readDiscriminator(discriminator: String) = { - discriminator match { - case "email_data_application_created" => io.apibuilder.task.v0.models.json.jsonReadsApibuilderTaskEmailDataApplicationCreated.reads(js) - case "email_data_email_verification_created" => io.apibuilder.task.v0.models.json.jsonReadsApibuilderTaskEmailDataEmailVerificationCreated.reads(js) - case "email_data_membership_created" => io.apibuilder.task.v0.models.json.jsonReadsApibuilderTaskEmailDataMembershipCreated.reads(js) - case "email_data_membership_request_created" => io.apibuilder.task.v0.models.json.jsonReadsApibuilderTaskEmailDataMembershipRequestCreated.reads(js) - case "email_data_membership_request_accepted" => io.apibuilder.task.v0.models.json.jsonReadsApibuilderTaskEmailDataMembershipRequestAccepted.reads(js) - case "email_data_membership_request_declined" => io.apibuilder.task.v0.models.json.jsonReadsApibuilderTaskEmailDataMembershipRequestDeclined.reads(js) - case "email_data_password_reset_request_created" => io.apibuilder.task.v0.models.json.jsonReadsApibuilderTaskEmailDataPasswordResetRequestCreated.reads(js) - case other => play.api.libs.json.JsSuccess(io.apibuilder.task.v0.models.EmailDataUndefinedType(other)) - } - } - (js \ "discriminator").validate[String] match { - case e: play.api.libs.json.JsError => e - case s: play.api.libs.json.JsSuccess[String] => readDiscriminator(s.value).map(_.asInstanceOf[T]) + implicit def jsonReadsApibuilderTaskEmailData[T <: io.apibuilder.task.v0.models.EmailData]: play.api.libs.json.Reads[T] = (json: play.api.libs.json.JsValue) => { + Seq( + jsonReadsApibuilderTaskEmailDataApplicationCreated.reads(json).map(_.asInstanceOf[T]), + jsonReadsApibuilderTaskEmailDataEmailVerificationCreated.reads(json).map(_.asInstanceOf[T]), + jsonReadsApibuilderTaskEmailDataMembershipCreated.reads(json).map(_.asInstanceOf[T]), + jsonReadsApibuilderTaskEmailDataMembershipRequestCreated.reads(json).map(_.asInstanceOf[T]), + jsonReadsApibuilderTaskEmailDataMembershipRequestAccepted.reads(json).map(_.asInstanceOf[T]), + jsonReadsApibuilderTaskEmailDataMembershipRequestDeclined.reads(json).map(_.asInstanceOf[T]), + jsonReadsApibuilderTaskEmailDataPasswordResetRequestCreated.reads(json).map(_.asInstanceOf[T]) + ).view.find(_.isSuccess).getOrElse { + play.api.libs.json.JsSuccess(EmailDataUndefinedType(json.toString).asInstanceOf[T]) } } + implicit def jsonReadsApibuilderTaskEmailDataSeq[T <: io.apibuilder.task.v0.models.EmailData]: play.api.libs.json.Reads[Seq[T]] = { case a: play.api.libs.json.JsArray => { val all: Seq[play.api.libs.json.JsResult[io.apibuilder.task.v0.models.EmailData]] = a.value.map(jsonReadsApibuilderTaskEmailData.reads).toSeq @@ -385,15 +335,24 @@ package io.apibuilder.task.v0.models { def jsObjectEmailData(obj: io.apibuilder.task.v0.models.EmailData): play.api.libs.json.JsObject = { obj match { - case x: io.apibuilder.task.v0.models.EmailDataApplicationCreated => io.apibuilder.task.v0.models.json.jsObjectEmailDataApplicationCreated(x) - case x: io.apibuilder.task.v0.models.EmailDataEmailVerificationCreated => io.apibuilder.task.v0.models.json.jsObjectEmailDataEmailVerificationCreated(x) - case x: io.apibuilder.task.v0.models.EmailDataMembershipCreated => io.apibuilder.task.v0.models.json.jsObjectEmailDataMembershipCreated(x) - case x: io.apibuilder.task.v0.models.EmailDataMembershipRequestCreated => io.apibuilder.task.v0.models.json.jsObjectEmailDataMembershipRequestCreated(x) - case x: io.apibuilder.task.v0.models.EmailDataMembershipRequestAccepted => io.apibuilder.task.v0.models.json.jsObjectEmailDataMembershipRequestAccepted(x) - case x: io.apibuilder.task.v0.models.EmailDataMembershipRequestDeclined => io.apibuilder.task.v0.models.json.jsObjectEmailDataMembershipRequestDeclined(x) - case x: io.apibuilder.task.v0.models.EmailDataPasswordResetRequestCreated => io.apibuilder.task.v0.models.json.jsObjectEmailDataPasswordResetRequestCreated(x) - case other => { - sys.error(s"The type[${other.getClass.getName}] has no JSON writer") + case x: io.apibuilder.task.v0.models.EmailDataApplicationCreated => play.api.libs.json.Json.obj("email_data_application_created" -> io.apibuilder.task.v0.models.json.jsObjectEmailDataApplicationCreated(x)) + case x: io.apibuilder.task.v0.models.EmailDataEmailVerificationCreated => play.api.libs.json.Json.obj("email_data_email_verification_created" -> io.apibuilder.task.v0.models.json.jsObjectEmailDataEmailVerificationCreated(x)) + case x: io.apibuilder.task.v0.models.EmailDataMembershipCreated => play.api.libs.json.Json.obj("email_data_membership_created" -> io.apibuilder.task.v0.models.json.jsObjectEmailDataMembershipCreated(x)) + case x: io.apibuilder.task.v0.models.EmailDataMembershipRequestCreated => play.api.libs.json.Json.obj("email_data_membership_request_created" -> io.apibuilder.task.v0.models.json.jsObjectEmailDataMembershipRequestCreated(x)) + case x: io.apibuilder.task.v0.models.EmailDataMembershipRequestAccepted => play.api.libs.json.Json.obj("email_data_membership_request_accepted" -> io.apibuilder.task.v0.models.json.jsObjectEmailDataMembershipRequestAccepted(x)) + case x: io.apibuilder.task.v0.models.EmailDataMembershipRequestDeclined => play.api.libs.json.Json.obj("email_data_membership_request_declined" -> io.apibuilder.task.v0.models.json.jsObjectEmailDataMembershipRequestDeclined(x)) + case x: io.apibuilder.task.v0.models.EmailDataPasswordResetRequestCreated => play.api.libs.json.Json.obj("email_data_password_reset_request_created" -> io.apibuilder.task.v0.models.json.jsObjectEmailDataPasswordResetRequestCreated(x)) + + case x: io.apibuilder.task.v0.models.EmailDataUndefinedType => { + scala.util.Try { + // If we received a JSON object - echo it back. This is a workaround for a bug in + // serialization for unions w/out discriminators where they sometimes have the + // type wrapper and sometimes do not + play.api.libs.json.Json.parse(x.description).asInstanceOf[play.api.libs.json.JsObject] + } match { + case scala.util.Success(o) => o + case scala.util.Failure(_) => sys.error("The type[io.apibuilder.task.v0.models.EmailDataUndefinedType] should never be serialized") + } } } } @@ -525,7 +484,7 @@ package io.apibuilder.task.v0 { val Namespace = "io.apibuilder.task.v0" val UserAgent = "apibuilder localhost 9000/apicollective/apibuilder-task/latest/play_2_9_scala_3_client" - val Version = "0.16.50" + val Version = "0.16.53" val VersionMajor = 0 } diff --git a/lib/src/main/scala/generated/ApicollectiveApibuilderSpecV0Models.scala b/lib/src/main/scala/generated/ApicollectiveApibuilderSpecV0Models.scala index 36564f7fb..698baf1bc 100644 --- a/lib/src/main/scala/generated/ApicollectiveApibuilderSpecV0Models.scala +++ b/lib/src/main/scala/generated/ApicollectiveApibuilderSpecV0Models.scala @@ -1,7 +1,7 @@ /** * Generated by API Builder - https://www.apibuilder.io - * Service version: 0.16.50 - * User agent: apibuilder app.apibuilder.io/apicollective/apibuilder-spec/latest/play_2_x_standalone_json + * Service version: 0.16.53 + * User agent: apibuilder localhost 9000/apicollective/apibuilder-spec/latest/play_2_x_standalone_json */ package io.apibuilder.spec.v0.models { @@ -1403,7 +1403,18 @@ package io.apibuilder.spec.v0.models { obj match { case x: io.apibuilder.spec.v0.models.ResponseCodeInt => play.api.libs.json.Json.obj("integer" -> play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsNumber(x.value))) case x: io.apibuilder.spec.v0.models.ResponseCodeOption => play.api.libs.json.Json.obj("response_code_option" -> play.api.libs.json.JsString(x.toString)) - case x: io.apibuilder.spec.v0.models.ResponseCodeUndefinedType => sys.error(s"The type[io.apibuilder.spec.v0.models.ResponseCodeUndefinedType] should never be serialized") + + case x: io.apibuilder.spec.v0.models.ResponseCodeUndefinedType => { + scala.util.Try { + // If we received a JSON object - echo it back. This is a workaround for a bug in + // serialization for unions w/out discriminators where they sometimes have the + // type wrapper and sometimes do not + play.api.libs.json.Json.parse(x.description).asInstanceOf[play.api.libs.json.JsObject] + } match { + case scala.util.Success(o) => o + case scala.util.Failure(_) => sys.error("The type[io.apibuilder.spec.v0.models.ResponseCodeUndefinedType] should never be serialized") + } + } } } implicit def jsonWritesApibuilderSpecResponseCode: play.api.libs.json.Writes[ResponseCode] = {