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
Nested ClassesModifier and TypeClassDescriptionstatic final classA specializedSpecthat also has a name.static final classstatic enumstatic final classExtra information to be attached to any generatedValidationExceptionstatic final class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddOption(String name, Spec.OptionType type) Add anSpec.Optionto this spec.voidallowUnknownKeys(boolean allowUnknownKeys) booleancontainsOption(String name) Returns true if this spec contains the specified option.static SpecCreates a spec object based on a option descriptors.getAliases(Spec.Option option) booleanmaskSecrets(Map<String, Object> unsafeArgs) Returns a copy of the given arguments but with all secret arguments masked as*****.voidmutuallyExclusive(String... keys) Specify a set of keys that are mutually exclusive. i.e. at most one of them may be specified.voidremoveOption(String name) Remove anSpec.Optionfrom this spec.removeSecrets(Map<String, Object> unsafeArgs) Returns a copy of the given arguments but with all secret arguments recursively removed.voidrequireOneOf(String... keys) Specify a set of keys of which at least one must be specified.voidrequireTogether(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.Optionto this spec.- Throws:
IllegalArgumentException- if an option with this name is already defined.
-
removeOption
Remove anSpec.Optionfrom 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.WhenConditionfor 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
-