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

Default values are ignored #1427

Open
andiskrauklis opened this issue Mar 18, 2022 · 1 comment
Open

Default values are ignored #1427

andiskrauklis opened this issue Mar 18, 2022 · 1 comment
Labels
help wanted Easy to moderately difficult issues that don't require deep knowledge or architectural thought question A question about usage, not necessarily requiring code changes. May involve documentation.

Comments

@andiskrauklis
Copy link

I'm having a problem with a default value.

version: sbt-guardrail:0.69.0.1

Definition

properties:
  fieldOne:
    type: String
  fieldTwo:
    type: Boolean
    default: false

Generated code

case class Something(fieldOne: String, fieldTwo: Boolean = false)

So far, so good.

However, once I POST JSON without a value

{
  "fieldOne": "test"
}

I get the error
Attempt to decode value on failed cursor: DownField(fieldTwo)

@blast-hardcheese
Copy link
Member

Hello @andiskrauklis, I've been punting on this issue for a while (since #197, actually).

The challenge is that the default parameters are not known by the Decoder[Something] instance.

Additionally, should we apply the default value on the server (on decode but not encode)? What about the client (on decode but not encode)?

What might be a reasonable middleground would be to have a def defaults: JsonObject in the companion, then use deepMerge before attempting to decode, but I've never had a use for this feature, so I don't have any intuition around what is correct.

@blast-hardcheese blast-hardcheese added help wanted Easy to moderately difficult issues that don't require deep knowledge or architectural thought question A question about usage, not necessarily requiring code changes. May involve documentation. labels Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Easy to moderately difficult issues that don't require deep knowledge or architectural thought question A question about usage, not necessarily requiring code changes. May involve documentation.
Projects
None yet
Development

No branches or pull requests

2 participants