Skip to content

Add yaml package

Choose a tag to compare

@name212 name212 released this 16 Jan 17:45
· 19 commits to main since this release
378b2dc

Add:

  • yaml package:
    Add Errors primitives.
    It contains primary Validator struct for validate yaml documents with apiVersion and kind fields. Now Validator wrap validation and another errors with special pre-defined errors which handle is need with errors.Is.
    It was migrated SchemaStore from 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.
    • PreValidator for additional validation before validate by schema. For example we validate ModuleConfig resources in dhctl, but every module config has it own validation schema for settings field. This settings should validate before validate entry document, because validation by schema only validate ModuleConfig document as is (that document present settings, version field) and settings will not validate by own settings schema.
    • extensions validators, like x-rules for validate separated fields by own validation functions. For example, in dhctl we validate ssh private key in ConnectionConfig using 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/v1alpha1 to deckhouse.io/v1.
    • LoadSchemas for parse and load schemas from io.Reader to []openapi/*spec.Schema (schema can contains multiple apiVersions). Warning! In LoadSchemas we add disallow additional properties if it was not set.

    Also, we added some utils functions:

    • SplitYAML* for split content on multiple documents by \n---\n separator.
    • Unmarshal wrapper for yaml.Unmarshal but this function is generic and return result as return, not by argument pointer.