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

No preview data generated when @Dowel data class has default values #21

Closed
savvasdalkitsis opened this issue Feb 23, 2024 · 7 comments · Fixed by #32
Closed

No preview data generated when @Dowel data class has default values #21

savvasdalkitsis opened this issue Feb 23, 2024 · 7 comments · Fixed by #32
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@savvasdalkitsis
Copy link

Library Version: 0..8.0

Describe the Bug:
assuming a class:

data class Test(
    val name: String = "",
    val age: Int? = null,
)

The generated provider class only contains empty constructor invocations, generating the same data for each entry.

If you remove the default values, the correct provider class is generated

@jayasuryat
Copy link
Owner

jayasuryat commented Feb 26, 2024

Yes, right now @Dowel ignores all the properties with default values for code-generation.

I can see how this might be inconvenient in certain use-cases.


I think code generation could be added for properties with default values, given, their types are supported by Dowel. Otherwise, could back-off to rely on the existing behaviour.

I don't have any immediate concerns with the above mentioned approach, will think through different cases, and if everything checks out, will add support for this in the next release.

@jayasuryat jayasuryat added this to the v0.9.0 milestone Feb 26, 2024
@mohsen-biglari
Copy link

A suggestion for including this functionality could be a new param for @Dowel to be able to toggle this behavior. Something like:

@Dowel(ignoreDefaultValues: Boolean, ...)

@jayasuryat
Copy link
Owner

Yep, @mohsen-biglari, that should work.


I'm also thinking if having this configuration at a property level would be needed or not.

For example,

@Dowel(count = 30, ignoreDefaultValues = true)
data class Person(
    val id: Long = 1L,
    val name: String,
    val bio: String?,
    @DrawableRes val avatar: Int = R.drawable.ic_launcher_foreground,
)

In this example, I may want to generate random values for the id property, but would want to keep the avatar as is with the default value.

@savvasdalkitsis what do you think?

@savvasdalkitsis
Copy link
Author

I would probably name the property something like preserveDefaultValues or doNotOverrideDefaultValues to make it clear what will happen but looks good otherwise

@jayasuryat
Copy link
Owner

@savvasdalkitsis, my question is, do you see it as necessary to configure this at the property level, or is class-declaration level configuration sufficient?

@jayasuryat jayasuryat self-assigned this May 5, 2024
@jayasuryat jayasuryat added the enhancement New feature or request label May 5, 2024
@jayasuryat jayasuryat linked a pull request May 5, 2024 that will close this issue
3 tasks
jayasuryat added a commit that referenced this issue May 5, 2024
jayasuryat added a commit that referenced this issue May 5, 2024
jayasuryat added a commit that referenced this issue May 5, 2024
(#21) Add support for overriding default values
@jayasuryat
Copy link
Owner

@savvasdalkitsis, this has been implemented and would be part of the next release.


For now, this solution only addresses this configurability at a class level.

I'm still evaluating the need for this configurability at a property level, which if needed would be an additive change, anyway.

@jayasuryat
Copy link
Owner

@savvasdalkitsis this has been released as part of the v0.9.0 release. Check it out whenever you get a chance next!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants