{"id":20589672,"url":"https://github.com/coreos/vcontext","last_synced_at":"2025-04-14T22:09:04.720Z","repository":{"id":36002854,"uuid":"184817633","full_name":"coreos/vcontext","owner":"coreos","description":"A library for validating json and yaml configs in Go","archived":false,"fork":false,"pushed_at":"2024-01-03T21:11:43.000Z","size":83,"stargazers_count":11,"open_issues_count":4,"forks_count":8,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-14T22:08:47.364Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coreos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"code-of-conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-03T20:40:10.000Z","updated_at":"2024-02-15T10:02:40.000Z","dependencies_parsed_at":"2023-02-17T09:10:14.402Z","dependency_job_id":"20fede01-b2ec-4b50-907c-96996e713518","html_url":"https://github.com/coreos/vcontext","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreos%2Fvcontext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreos%2Fvcontext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreos%2Fvcontext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreos%2Fvcontext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coreos","download_url":"https://codeload.github.com/coreos/vcontext/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248968914,"owners_count":21191162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T07:30:32.629Z","updated_at":"2025-04-14T22:09:04.699Z","avatar_url":"https://github.com/coreos.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## vcontext: Validation with context\n\nvcontext is a library supporting validation of config files parsed from yaml or json with support for giving context as\nto where errors occur. It is composed of multiple semi-independent packages:\n\n - report: a structure for containing multiple errors, warnings, etc. It also contains context (from the path package)\n   for determining where in the config the reports came from (e.g. `$.foo.baz.4.quux`)\n - validate: a package for composing a report by validating go structs.\n - tree: a structure for containing metadata about the location (line/column) of objects in the source of the config\n - json, yaml: packages for generating trees from json or yaml\n - path: a structure for defining how to find json/yaml elements\n\n### Usage:\n\nValidating a config generally involves the following steps:\n1) Unmarshal the yaml or json to a go struct, handle any syntax/type errors\n1) Generate a report by running validate.Validate(yourConfigStruct)\n1) Generate a tree of line/column metadata with [json|yaml].UnmarshalToContext()\n1) Correlate the report to the metadata tree with report.Correlate(). This fills in line and column information from the tree.\n\nThe `validate` package does not require the structs came from json or yaml and will generate reports with context for each\nerror with a path like `$.foo.baz.4.quux`. The validate package walks the structs using reflection, aggregating the results\nof calling any `Validate(c path.ContextPath) report.Report` functions defined on the types it is walking.\n\nTo write validation functions for your types, implement this interface:\n```\nValidate(path.ContextPath) report.Report\n```\non any types you wish to be validated. The ContextPath passed to that function respresents the path to the type being\nvalidated. ContextPath is a `[]interface{}` under the hood. You can append strings or ints to it to be more precise about\nwhere problems occur. \n\nExample:\n```go\ntype MyStruct struct {\n\tMustBePositive int `json:\"mustBePositive\"`\n}\n\nfunc (m MyStruct) Validate(c path.ContextPath) (r report.Report) {\n\tif m.MustBePositive \u003c= 0 {\n\t\t// append the json tag so the report specifies that field is invalid, not the whole struct\n\t\tr.AddOnError(c.Append(\"mustBePositive\"), errors.New(\"mustBePositive was not positive\"))\n\t}\n\treturn\n}\n```\n\n### Notes:\n\n* This project under development and may undergo breaking changes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoreos%2Fvcontext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoreos%2Fvcontext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoreos%2Fvcontext/lists"}