{"id":15091418,"url":"https://github.com/crdsonnet/crdsonnet","last_synced_at":"2025-04-12T06:31:43.694Z","repository":{"id":62659725,"uuid":"432319706","full_name":"crdsonnet/crdsonnet","owner":"crdsonnet","description":"A library to generate a runtime Jsonnet library directly from JSON Schemas, CRDs or OpenAPI components.","archived":false,"fork":false,"pushed_at":"2024-04-21T11:30:30.000Z","size":524,"stargazers_count":18,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-21T12:56:23.409Z","etag":null,"topics":["crds","json-schema","jsonnet","jsonnet-lib","openapi-specification"],"latest_commit_sha":null,"homepage":"","language":"Jsonnet","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/crdsonnet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":"supportmatrix.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-26T22:57:46.000Z","updated_at":"2024-05-29T22:30:06.679Z","dependencies_parsed_at":"2024-05-29T22:30:05.186Z","dependency_job_id":"c08c2dea-77ff-45d2-9855-7fd768ad4bcc","html_url":"https://github.com/crdsonnet/crdsonnet","commit_stats":null,"previous_names":["crdsonnet/crdsonnet"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crdsonnet%2Fcrdsonnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crdsonnet%2Fcrdsonnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crdsonnet%2Fcrdsonnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crdsonnet%2Fcrdsonnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crdsonnet","download_url":"https://codeload.github.com/crdsonnet/crdsonnet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248529675,"owners_count":21119556,"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":["crds","json-schema","jsonnet","jsonnet-lib","openapi-specification"],"created_at":"2024-09-25T10:41:00.573Z","updated_at":"2025-04-12T06:31:40.178Z","avatar_url":"https://github.com/crdsonnet.png","language":"Jsonnet","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CRDsonnet\n\nGenerate a *runtime* Jsonnet library directly from JSON Schemas, CRDs or OpenAPI components.\n\n\u003e This project is actively used in several projects, most notably [Grafonnet](https://github.com/grafana/grafonnet). It can be consider in a usable state for production projects.\n\n## Install\n\n```console\njb install https://github.com/crdsonnet/crdsonnet/crdsonnet\n```\n\n## Usage\n\n### Static rendering\n\nThe static render engine generates the Jsonnet AST representation, calling `toString()` on the result will return the actual Jsonnet:\n\n```jsonnet\n// static.libsonnet\nlocal crdsonnet = import 'github.com/crdsonnet/crdsonnet/crdsonnet/main.libsonnet';\n\nlocal schema = {\n  type: 'object',\n  properties: {\n    name: {\n      type: 'string',\n    },\n  },\n};\n\nlocal processor = crdsonnet.processor.new('ast');\n\ncrdsonnet.schema.render('person', schema, processor).toString()\n```\n\nUse the `-S` flag to treat the output as a string and pipe it into `jsonnetfmt` for a clean output:\n\n\n```console\n\u003e jsonnet -S -J vendor static.libsonnet | jsonnetfmt -\n```\n\nThe output looks like this:\n\n```jsonnet\n{\n  person+:\n    {\n      '#withName': { 'function': { args: [{ default: null, enums: null, name: 'value', type: ['string'] }], help: '' } },\n      withName(value): {\n        name: value,\n      },\n    },\n}\n```\n\n### Dynamic rendering\n\nDynamic rendering can generate an in-memory runtime library. This can be useful when quickly iterating on a schema and don't want to make a static rendering on each change. However it makes debugging harder and it can become slow on big schemas.\n\n```jsonnet\nlocal crdsonnet = import 'github.com/crdsonnet/crdsonnet/crdsonnet/main.libsonnet';\n\nlocal schema = {\n  type: 'object',\n  properties: {\n    name: {\n      type: 'string',\n    },\n  },\n};\n\nlocal lib = crdsonnet.schema.render('person', schema);\n\nlib.person.withName('John')\n```\n\n\n### Generate documentation\n\nCRDsonnet generates libraries with documentation included. It leverages [docsonnet](https://github.com/jsonnet-libs/docsonnet).\n\nTo render the docs, a top-level package needs to be defined:\n\n```jsonnet\n// docs.libsonnet\nlocal d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet';\n\nlocal example =\n  (import './main.libsonnet')\n  + {\n    '#':\n      d.package.new(\n        'example',\n        'github.com/example/example',\n        'Jsonnet library for example',\n        'main.libsonnet',\n      ),\n  };\n\nd.render(example)\n```\n\n```console\njsonnet -J vendor -S -c -m docs docs.libsonnet\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrdsonnet%2Fcrdsonnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrdsonnet%2Fcrdsonnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrdsonnet%2Fcrdsonnet/lists"}