Giter VIP home page Giter VIP logo

drone-libsonnet's Introduction

CRDsonnet

Generate a runtime Jsonnet library directly from JSON Schemas, CRDs or OpenAPI components.

This project is actively used in several projects, most notably Grafonnet. It can be consider in a usable state for production projects.

Install

jb install https://github.com/crdsonnet/crdsonnet/crdsonnet

Usage

Static rendering

The static render engine generates the Jsonnet AST representation, calling toString() on the result will return the actual Jsonnet:

// static.libsonnet
local crdsonnet = import 'github.com/crdsonnet/crdsonnet/crdsonnet/main.libsonnet';

local schema = {
  type: 'object',
  properties: {
    name: {
      type: 'string',
    },
  },
};

local processor = crdsonnet.processor.new('ast');

crdsonnet.schema.render('person', schema, processor).toString()

Use the -S flag to treat the output as a string and pipe it into jsonnetfmt for a clean output:

> jsonnet -S -J vendor static.libsonnet | jsonnetfmt -

The output looks like this:

{
  person+:
    {
      '#withName': { 'function': { args: [{ default: null, enums: null, name: 'value', type: ['string'] }], help: '' } },
      withName(value): {
        name: value,
      },
    },
}

Dynamic rendering

Dynamic 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.

local crdsonnet = import 'github.com/crdsonnet/crdsonnet/crdsonnet/main.libsonnet';

local schema = {
  type: 'object',
  properties: {
    name: {
      type: 'string',
    },
  },
};

local lib = crdsonnet.schema.render('person', schema);

lib.person.withName('John')

Generate documentation

CRDsonnet generates libraries with documentation included. It leverages docsonnet.

To render the docs, a top-level package needs to be defined:

// docs.libsonnet
local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet';

local example =
  (import './main.libsonnet')
  + {
    '#':
      d.package.new(
        'example',
        'github.com/example/example',
        'Jsonnet library for example',
        'main.libsonnet',
      ),
  };

d.render(example)
jsonnet -J vendor -S -c -m docs docs.libsonnet

drone-libsonnet's People

Contributors

dsotirakis avatar duologic avatar jdbaldry avatar jimsheldon avatar mem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.