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

added option to switch off validation for ConfigBeanFactory use #602

Closed
wants to merge 3 commits into from

Conversation

dhakehurst
Copy link

@dhakehurst dhakehurst commented Dec 3, 2018

Useful in its own right I believe, but this also provides a work around for #440

I have beans that I want instantiated by the config file. But I don't want to set every property of the bean. The bean itself sets default values for some properties. I cannot add the '@optional' annotation to the bean class properties.

switching off the validation allows this.

(I'm using this library for a live project, it is very useful, thanks for all who have contributed towards it.
I need this capability ASAP, and I would rather use an official release over my patched version.)

I have signed the Typesafe Contributor License Agreement online

Copy link
Collaborator

@havocp havocp left a comment

Choose a reason for hiding this comment

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

Thanks!

I would recommend adding tests for some of the main cases to check that they throw in validation mode and don't throw in non-validation mode. Otherwise this will break the first time someone touches this file again, it's an annoyingly hard file to modify reliably.

@@ -4,7 +4,7 @@
// Release tags should follow: http://semver.org/
import scalariform.formatter.preferences._

ThisBuild / git.baseVersion := "1.3.0"
ThisBuild / git.baseVersion := "1.3.4"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is an unrelated change I guess, ideally not in this PR

Copy link
Author

Choose a reason for hiding this comment

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

the current release is 1.3.3, so I don't know why this was set to 1.3.0.
I changed it to 1.3.4, so that my local publication is at a higher version than the release.
(perhaps it should still read 1.3.3 or 1.3.0?)

*
* @param config source of config information
* @param clazz class to be instantiated
* @param validate passing false means that the config will not be validated against the bean's implied schema
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't love the boolean param ( long story https://blog.ometer.com/2011/01/20/boolean-parameters-are-wrong/ , tldr create(config, clazz, false) doesn't read well).

An alternative would be an Options object like ConfigParseOptions / ConfigResolveOptions, or an enum like ValidationMode { NONE, AUTOMATIC } or something.

Copy link
Author

Choose a reason for hiding this comment

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

That would be an acceptable alternative. though I am fine with booleans.

Copy link

@kringol kringol Dec 19, 2018

Choose a reason for hiding this comment

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

I am also looking forward to this feature, since i also need it. Therefore, thanks for your contribution on it :)
But i would also think it would be nicer to have more control on the validation. For example to keep the "type" validation for non-null fields, but ignore the optional/null value check, thus allowing null values but validating the type on non-null ones. And similar.
Currently the boolean is disabling/enabling everything

* Fields are mapped to config by converting the config key to
* camel case. So the key <code>foo-bar</code> becomes JavaBean
* setter <code>setFooBar</code>.
*
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this kinda needs to explain what happens if we disable validation and it's invalid. I believe the answer is stuff gets left as whatever it was set to originally in the bean (stuff does not get assigned). But full-on type errors (assign an integer to a list or something) maybe still throw?

val e = intercept[ConfigException.Parse] {
ConfigFactory.parseReader(configInput)
}
assertThat(e.getMessage, containsString("Expecting end of input or a comma, got '^'"))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

are there changes in this file or just accidental reformatting?

Copy link
Author

Choose a reason for hiding this comment

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

I changed nothing here.

@dhakehurst
Copy link
Author

dhakehurst commented Dec 19, 2018 via email

@kringol
Copy link

kringol commented Dec 20, 2018

Just added a PR to your own fork with some small changes to match the mechanism of other parts of the library and enable future settings if needed, plus a mini test
dhakehurst#1

Thanks :)

Feel free to add to this pull request or superceed it. I have done all i am able to do at this time.

Introduce a bean factory options parameter
@avillev
Copy link

avillev commented Feb 15, 2019

Hello there !! @havocp @dhakehurst
Do we have news about this change? I am very interrested.
Does someone plan to have it merged into the project?

@dhakehurst
Copy link
Author

dhakehurst commented Feb 15, 2019 via email

@kringol
Copy link

kringol commented Feb 19, 2019

I will continue this change on a new PR instead then.
I really want this moving forward and been waiting for it

-> #616

I do not currently have more time to work on this

On Fri, 15 Feb 2019 at 06:21, Arnaud Villevieille @.***> wrote: Hello there !! @havocp https://github.com/havocp @dhakehurst https://github.com/dhakehurst Do we have new about that change? Does someone plan to have it merged into the project? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#602 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AFW7ZZ1fPRsB-tlEFZD9mkC44F4SgNX_ks5vNkPEgaJpZM4Y-eNk .

@havocp
Copy link
Collaborator

havocp commented Feb 21, 2019

Closing this since it moved to #616

@havocp havocp closed this Feb 21, 2019
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.

5 participants