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

MATGONZALEZ: define default None in non required params in Routes for… #693

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Generated by API Builder - https://www.apibuilder.io
# Service version: 0.3.47

GET /echoes controllers.Echoes.get(foo: _root_.scala.Option[String], optional_messages: _root_.scala.Option[List[String]], required_messages: List[String])
GET /echoes/arrays-only controllers.Echoes.getArraysOnly(optional_messages: _root_.scala.Option[List[String]], required_messages: List[String])
GET /echoes controllers.Echoes.get(foo: _root_.scala.Option[String] ?= None, optional_messages: _root_.scala.Option[List[String]] ?= None, required_messages: List[String])
GET /echoes/arrays-only controllers.Echoes.getArraysOnly(optional_messages: _root_.scala.Option[List[String]] ?= None, required_messages: List[String])
GET /groups/:organization controllers.Groups.getByOrganization(organization: _root_.java.util.UUID)
POST /members controllers.Members.post()
GET /members controllers.Members.get(guid: _root_.scala.Option[_root_.java.util.UUID], organization_guid: _root_.scala.Option[_root_.java.util.UUID], user_guid: _root_.scala.Option[_root_.java.util.UUID], role: _root_.scala.Option[String])
GET /members controllers.Members.get(guid: _root_.scala.Option[_root_.java.util.UUID] ?= None, organization_guid: _root_.scala.Option[_root_.java.util.UUID] ?= None, user_guid: _root_.scala.Option[_root_.java.util.UUID] ?= None, role: _root_.scala.Option[String] ?= None)
GET /members/:organization controllers.Members.getByOrganization(organization: _root_.java.util.UUID)
POST /members/:organization/members_bulk controllers.Members.postMembersBulkByOrganization(organization: _root_.java.util.UUID)
POST /organizations controllers.Organizations.post()
GET /organizations controllers.Organizations.get(guid: _root_.scala.Option[_root_.java.util.UUID], name: _root_.scala.Option[String])
GET /organizations controllers.Organizations.get(guid: _root_.scala.Option[_root_.java.util.UUID] ?= None, name: _root_.scala.Option[String] ?= None)
GET /organizations/:guid controllers.Organizations.getByGuid(guid: _root_.java.util.UUID)
POST /users controllers.Users.post()
GET /users controllers.Users.get(guid: _root_.scala.Option[_root_.java.util.UUID], organization_guids: _root_.scala.Option[List[Long]], age_group: _root_.scala.Option[io.apibuilder.reference.api.v0.models.AgeGroup], email: _root_.scala.Option[String], active: Boolean ?= true)
GET /users controllers.Users.get(guid: _root_.scala.Option[_root_.java.util.UUID] ?= None, organization_guids: _root_.scala.Option[List[Long]] ?= None, age_group: _root_.scala.Option[io.apibuilder.reference.api.v0.models.AgeGroup] ?= None, email: _root_.scala.Option[String] ?= None, active: Boolean ?= true)
GET /users/:age_group controllers.Users.getByAgeGroup(age_group: io.apibuilder.reference.api.v0.models.AgeGroup)
POST /users/noop controllers.Users.postNoop()
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ private[models] case class Play2Route(
case ScalaDatatype.Option(_) => None
case p: ScalaPrimitive => Some("?= " + defaultForPrimitive(p, d))
}
).orElse(
param.datatype match {
case ScalaDatatype.Option(_) => Some("?= None")
Copy link
Collaborator

@gheine gheine Mar 22, 2024

Choose a reason for hiding this comment

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

Not sure we want to provide a default for all Options here (unsure if/what this might break). How about we only provide the default for ScalaDatatype.Option(ScalaDatatype.List(_)) and ScalaDatatype.Option(ScalaDatatype.Map(_))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i tested it with a Optional[Long] and there is no need to force the default to None, so as you say only keeping it to List and Map on the meantime,

case _ => None
}
)
).flatten.mkString(" ")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Play2RouteGeneratorSpec extends AnyFunSpec with Matchers {
val op = getScalaMethod(ssd, "Echoes", Method.Get, "/echoes")
val r = Play2Route(ssd, op, echoResource)
r.method should be("controllers.Echoes.get")
r.params.mkString(", ") should be("foo: _root_.scala.Option[String], optional_messages: _root_.scala.Option[List[String]], required_messages: List[String]")
r.params.mkString(", ") should be("foo: _root_.scala.Option[String] ?= None, optional_messages: _root_.scala.Option[List[String]] ?= None, required_messages: List[String]")

Play2RouteGenerator(InvocationForm(service)).invoke() match {
case Left(errors) => fail(errors.mkString(", "))
Expand Down Expand Up @@ -118,7 +118,7 @@ class Play2RouteGeneratorSpec extends AnyFunSpec with Matchers {
r.verb should be(Method.Get)
r.url should be("/users")
r.method should be("controllers.Users.get")
r.params.mkString(", ") should be("guid: _root_.scala.Option[_root_.java.util.UUID], email: _root_.scala.Option[String], token: _root_.scala.Option[String]")
r.params.mkString(", ") should be("guid: _root_.scala.Option[_root_.java.util.UUID] ?= None, email: _root_.scala.Option[String] ?= None, token: _root_.scala.Option[String] ?= None")
}

it("GET w/ path, guid path param, no additional parameters") {
Expand Down