Improve .create-api.yml
loading to understand single values or booleans for set/array options
#111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When deserialising the yaml or json configuration options, we're decoding into the types defined on the properties within
ConfigOptions
. This means that on sets an arrays, you must define an array in json or yaml even if there is only one item. For example:or
While this isn't a huge deal, we could be a bit more lenient here. And that's what this change does. When the type is a
Set
or anArray
, it'll also attempt to decode the property as a single value and if its present, it'll wrap it in a collection and return it.It allows the user to simplify their configuration like so:
It makes the config file a bit more readable.
In addition, I also wanted to go one step further for cases where the value within the
Set
/Array
is a fixed set of options. In this case, we can annotate them asCaseIterable
which will also allow us to represent the value using booleans.true
beingOption.allCases
andfalse
being[]
.For example:
The above will be parsed as
[.classes, .structs]
and the result will be that we generate all properties as mutable regardless of type (exactly what you would expect from settingmutableProperties
totrue
).You can do the inverse as well:
Which reads "no mutable properties" and like you expect, the object decoded value is
[]
, which would result in everything beinglet
.