Package org.yamcs
Class Spec
java.lang.Object
org.yamcs.Spec
- Direct Known Subclasses:
Spec.NamedSpec
Specifies the valid structure of a
YConfiguration
instance.
While not strictly 'validation', the spec also allows defining additional metadata like the 'default' keyword which is used in the merged result of a validation.
Furthermore, a spec validation applies a limited set of type transformations.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
A specializedSpec
that also has a name.static final class
static enum
static final class
Extra information to be attached to any generatedValidationException
static final class
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddOption
(String name, Spec.OptionType type) Add anSpec.Option
to this spec.void
allowUnknownKeys
(boolean allowUnknownKeys) boolean
containsOption
(String name) Returns true if this spec contains the specified option.static Spec
Creates a spec object based on a option descriptors.getAliases
(Spec.Option option) boolean
maskSecrets
(Map<String, Object> unsafeArgs) Returns a copy of the given arguments but with all secret arguments masked as*****
.void
mutuallyExclusive
(String... keys) Specify a set of keys that are mutually exclusive. i.e. at most one of them may be specified.void
removeOption
(String name) Remove anSpec.Option
from this spec.removeSecrets
(Map<String, Object> unsafeArgs) Returns a copy of the given arguments but with all secret arguments recursively removed.void
requireOneOf
(String... keys) Specify a set of keys of which at least one must be specified.void
requireTogether
(String... keys) Specify a set of keys that must appear together.Validate the given arguments according to this spec.validate
(YConfiguration args) Validate the given arguments according to this spec.Add a condition that is only verified whenkey.equals(value)
-
Field Details
-
ANY
Spec implementation that allows any key.
-
-
Constructor Details
-
Spec
public Spec()
-
-
Method Details
-
containsOption
Returns true if this spec contains the specified option. -
addOption
Add anSpec.Option
to this spec.- Throws:
IllegalArgumentException
- if an option with this name is already defined.
-
removeOption
Remove anSpec.Option
from this spec. -
allowUnknownKeys
public void allowUnknownKeys(boolean allowUnknownKeys) -
requireOneOf
Specify a set of keys of which at least one must be specified. Note that this not enforce that only one is specified. You can combine this check withmutuallyExclusive(String...)
if that is required. -
requireTogether
Specify a set of keys that must appear together. This check only applies as soon as at least one of these keys has been specified. -
mutuallyExclusive
Specify a set of keys that are mutually exclusive. i.e. at most one of them may be specified. -
when
Add a condition that is only verified whenkey.equals(value)
- Parameters:
key
- the name of an optionvalue
- the value that triggers the conditional check- Returns:
- an instance of
Spec.WhenCondition
for further configuration options
-
validate
Validate the given arguments according to this spec.- Parameters:
args
- the arguments to validate.- Returns:
- the validation result where defaults have been added to the input arguments
- Throws:
ValidationException
- when the specified arguments did not match this specification
-
validate
Validate the given arguments according to this spec.- Parameters:
args
- the arguments to validate, keyed by argument name.- Returns:
- the validation result where defaults have been added to the input arguments
- Throws:
ValidationException
- when the specified arguments did not match this specification
-
getOptions
-
isAllowUnknownKeys
public boolean isAllowUnknownKeys() -
getRequiredOneOfGroups
-
getRequireTogetherGroups
-
getWhenConditions
-
getOption
-
getAliases
-
removeSecrets
Returns a copy of the given arguments but with all secret arguments recursively removed.This method does not validate the arguments, however it will throw random exceptions if the input does not match the expected structure. It is therefore best to validate the arguments before passing them.
-
maskSecrets
Returns a copy of the given arguments but with all secret arguments masked as*****
.This method does not validate the arguments, however it will throw random exceptions if the input does not match the expected structure. It is therefore best to validate the arguments before passing them.
-
fromDescriptor
public static Spec fromDescriptor(Map<String, Map<String, throws ValidationExceptionObject>> optionDescriptors) Creates a spec object based on a option descriptors.- Throws:
ValidationException
-