{"id":16139399,"url":"https://github.com/networkop/yang-to-cue","last_synced_at":"2025-07-24T11:34:07.533Z","repository":{"id":48175161,"uuid":"516677326","full_name":"networkop/yang-to-cue","owner":"networkop","description":"Importing YANG definitions into CUE","archived":false,"fork":false,"pushed_at":"2022-12-06T16:59:59.000Z","size":3593,"stargazers_count":10,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-02T17:22:26.373Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/networkop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-22T08:48:37.000Z","updated_at":"2025-02-02T11:31:02.000Z","dependencies_parsed_at":"2023-01-23T10:45:55.872Z","dependency_job_id":null,"html_url":"https://github.com/networkop/yang-to-cue","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/networkop/yang-to-cue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networkop%2Fyang-to-cue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networkop%2Fyang-to-cue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networkop%2Fyang-to-cue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networkop%2Fyang-to-cue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/networkop","download_url":"https://codeload.github.com/networkop/yang-to-cue/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networkop%2Fyang-to-cue/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266834840,"owners_count":23992263,"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","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-10-09T23:48:57.496Z","updated_at":"2025-07-24T11:34:07.458Z","avatar_url":"https://github.com/networkop.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Working with YANG-based APIs from CUE\n\n* Importing YANG definitions into CUE\n* Building and validating payloads\n* Applying device configuration using CUE scripting\n\n\n1. Initialise a Go module and add the ygot package\n\n```\ngo mod init yang.to.cue\ngo get github.com/openconfig/ygot/generator\n```\n\n2. Get a local copy of the required YANG models\n\n```\ngit clone --depth=1 https://github.com/YangModels/yang.git\ngit clone https://github.com/openconfig/public openconfig\ncurl -o yang/arista.yang https://raw.githubusercontent.com/aristanetworks/yang/master/EOS-4.25.1F/release/openconfig/models/interfaces/arista-intf-augments.yang\n```\n\n3. Generate types with ygot\n\n```\nmkdir pkg\n\ngo run github.com/openconfig/ygot/generator \\\n-path=openconfig \\\n-generate_fakeroot \\\n-fakeroot_name=device \\\n-output_file=pkg/yang.go \\\n-compress_paths=false \\\n-exclude_modules=ietf-interfaces,openconfig-mpls,openconfig-isis,openconfig-evpn \\\n-include_descriptions=false \\\n-include_model_data=false \\\n-package_name=yang \\\n-exclude_state \\\nopenconfig/release/models/interfaces/openconfig-if-ip.yang \\\nopenconfig/release/models/bgp/openconfig-bgp.yang \\\nopenconfig/release/models/network-instance/openconfig-network-instance.yang \\\nyang/arista.yang\n```\n\n4. (Optional) Generate a JSON payload using ygot\n\n```\ngo run main.go\n```\n\nThis generates the `./go.json` file\n\n\n\n5. Modify YGOT types for CUE\n\n```\n# replace 'path' tags with 'json'\nsed -i -E 's/path:\"(\\S+)\"/json:\"\\1\"/' pkg/yang.go\n# replace Go maps with slices\nsed -i -E 's/map\\[.*\\]\\*(\\S+)/\\[\\]\\*\\1/' pkg/yang.go\n```\n\n\n6. Init CUE modules\n\n```\ncue mod init yang.cue\n```\n\n7. Import Go types into CUE\n\n```\ncue get go yang.to.cue/pkg/...\n```\n\nThe generated file is located in `cue.mod/gen/yang.to.cue/pkg/yang_go_gen.cue`\n\n8.  Modify CUE definitions\n\n* Patch existing ENUM definitions\n* Make all struct fields optional, since some types are incorrectly marked as required by 'cue go get'\n* (Optionally) Import YANG list definitions from ygot Go package and inject additional validation logic into CUE definitions\n\n```\n# regenerate ygot package\ngo run github.com/openconfig/ygot/generator \\\n-path=openconfig \\\n-generate_fakeroot \\\n-fakeroot_name=device \\\n-output_file=pkg/yang.go \\\n-compress_paths=false \\\n-exclude_modules=ietf-interfaces,openconfig-mpls,openconfig-isis,openconfig-evpn \\\n-include_descriptions=false \\\n-include_model_data=false \\\n-package_name=yang \\\n-exclude_state \\\nopenconfig/release/models/interfaces/openconfig-if-ip.yang \\\nopenconfig/release/models/bgp/openconfig-bgp.yang \\\nopenconfig/release/models/network-instance/openconfig-network-instance.yang \\\nyang/arista.yang\n\ngo run post-import.go\n```\n\n\n\u003e From here on, you work exclusively with CUE definitions and can safely delete `./openconfig` and `./yang` directories with YANG models and `./pkg` containing ygot types.\n\n9. Write some CUE based on the generated definitions\n\n```\ncat values.cue\n```\n\n10. Check the that values are correct by evaluating them\n\n```\ncue eval values.cue --out=json\n```\n\n11. Check the that validation works against an incorrect data\n\n```\n# mismatch betweek YangList.key and YangList.Config.Key\ncue eval bad/mismatch.cue --out=json\n\n# duplicate entry in YangList\ncue eval bad/duplicate.cue --out=json\n\n# misspelled/incorrect entry\ncue eval bad/undefined.cue --out=json\n```\n\n\n12. Check and update the test device details\n\n```\ncat gnmi_tool.cue\n```\n\n13. Apply the configuration\n\n```\ncue apply\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetworkop%2Fyang-to-cue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetworkop%2Fyang-to-cue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetworkop%2Fyang-to-cue/lists"}