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

Conversation

Matuco17
Copy link
Contributor

The issue is the following

When looking to define non required params, the api builder doesn't give the option to define a default, so on some methods, the params are taking different than expect

Example:
when param is defined with { "name": "values", "type": "[string]", "required": false}The route generation is:values: root.scala.Option[List[String]And if in the call the param is not passed, the values red side the Controller code isSome(List())instead ofNone`

The fix will add as default for every non required param a None as default in the route using the ?= None part

… Play taking into account the default cannot be defined by api definition
@@ -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,

… it the forcing default is not needed for scalars
Copy link
Collaborator

@gheine gheine left a comment

Choose a reason for hiding this comment

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

Thank you @Matuco17!

@gheine gheine merged commit d792060 into apicollective:main Mar 22, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants