Skip to content

Commit

Permalink
Update apibuilder-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
mbryzek committed Jul 30, 2024
1 parent ad8b17c commit 723fbdc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
46 changes: 29 additions & 17 deletions api/app/models/VersionsModel.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package models

import builder.api_json.upgrades.ServiceParser
import cats.data.Validated.{Invalid, Valid}
import cats.data.ValidatedNec
import cats.implicits._
import db.{ApplicationsDao, Authorization, InternalVersion, OrganizationsDao}
Expand All @@ -20,6 +21,16 @@ class VersionsModel @Inject()(
}

def toModels(versions: Seq[InternalVersion]): Seq[Version] = {
validateModels(versions) match {
case Invalid(e) => {
println(s"Could not convert versions to models: ${e.toNonEmptyList.toList.mkString(", ")}")
Nil
}
case Valid(versions) => versions
}
}

private def validateModels(versions: Seq[InternalVersion]): ValidatedNec[String, Seq[Version]] = {
val applications = applicationsDao.findAll(
Authorization.All,
guids = Some(versions.map(_.applicationGuid)),
Expand All @@ -32,25 +43,26 @@ class VersionsModel @Inject()(
limit = None
).map { o => o.guid -> o }.toMap

versions.flatMap { v =>
versions.map { v =>
(
applications.get(v.applicationGuid).flatMap { app =>
organizations.get(app.organizationGuid).flatMap { org =>
service(v).toOption.map { svc =>
Version(
guid = v.guid,
organization = Reference(guid = org.guid, key = org.key),
application = Reference(guid = app.guid, key = app.key),
version = v.version,
original = v.original,
service = svc,
audit = v.audit
)
}
applications.get(v.applicationGuid).toValidNec("Cannot find application").andThen { app =>
organizations.get(app.organizationGuid).toValidNec("Cannot find organization").map { org =>
(org, app)
}
}
)
}
},
service(v)
).mapN { case ((org, app), svc) =>
Version(
guid = v.guid,
organization = Reference(guid = org.guid, key = org.key),
application = Reference(guid = app.guid, key = app.key),
version = v.version,
original = v.original,
service = svc,
audit = v.audit
)
}
}.sequence
}

private def service(v: InternalVersion): ValidatedNec[String, Service] = {
Expand Down
14 changes: 7 additions & 7 deletions generated/app/ApicollectiveApibuilderSpecV0Client.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Generated by API Builder - https://www.apibuilder.io
* Service version: 0.16.50
* Service version: 0.16.53
* User agent: apibuilder app.apibuilder.io/apicollective/apibuilder-spec/latest/play_2_9_scala_3_client
*/
package io.apibuilder.spec.v0.models {
Expand Down Expand Up @@ -1390,12 +1390,12 @@ 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) => {
val default = jsonReadsApibuilderSpecResponseCodeInt.reads(json).map(_.asInstanceOf[T])
val all: Seq[play.api.libs.json.JsResult[T]] = Seq(
default,
Seq(
jsonReadsApibuilderSpecResponseCodeInt.reads(json).map(_.asInstanceOf[T]),
jsonReadsApibuilderSpecResponseCodeOption.reads(json).map(_.asInstanceOf[T])
)
all.view.find(_.isSuccess).getOrElse(default)
).view.find(_.isSuccess).getOrElse {
play.api.libs.json.JsSuccess(ResponseCodeUndefinedType(json.toString).asInstanceOf[T])
}
}


Expand Down Expand Up @@ -1565,7 +1565,7 @@ package io.apibuilder.spec.v0 {

val Namespace = "io.apibuilder.spec.v0"
val UserAgent = "apibuilder app.apibuilder.io/apicollective/apibuilder-spec/latest/play_2_9_scala_3_client"
val Version = "0.16.50"
val Version = "0.16.53"
val VersionMajor = 0

}
Expand Down

0 comments on commit 723fbdc

Please sign in to comment.