Add yaml package
Add:
-
yamlpackage:
Add Errors primitives.
It contains primaryValidatorstruct for validate yaml documents withapiVersionandkindfields. NowValidatorwrap validation and another errors with special pre-defined errors which handle is need witherrors.Is.
It was migratedSchemaStorefrom dhctl. But new struct can:- extended with transformers for transform
Schema(for example we add by default disallow additional properties). User can add your own transformers. PreValidatorfor additional validation before validate by schema. For example we validateModuleConfigresources in dhctl, but every module config has it own validation schema forsettingsfield. This settings should validate before validate entry document, because validation by schema only validateModuleConfigdocument as is (that document presentsettings,versionfield) andsettingswill not validate by own settings schema.- extensions validators, like
x-rulesfor validate separated fields by own validation functions. For example, in dhctl we validate ssh private key inConnectionConfigusing parsing go-ssh parse string, for private is valid private key string but not random string. - apiVersion fallbacks. For example old clients can use deleted apiVersion from specs user of library can add fallback from deleted versions for present. By default, we add fallback from version
deckhouse.io/v1alpha1todeckhouse.io/v1. LoadSchemasfor parse and load schemas fromio.Readerto[]openapi/*spec.Schema(schema can contains multiple apiVersions). Warning! InLoadSchemaswe add disallow additional properties if it was not set.
Also, we added some utils functions:
SplitYAML*for split content on multiple documents by\n---\nseparator.Unmarshalwrapper foryaml.Unmarshalbut this function is generic and return result as return, not by argument pointer.
- extended with transformers for transform