Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

enrolla/enrolla-sdk-generator

 
 

Repository files navigation

enrolla-cli Build Status npm mit

Compile enrolla customer schemas to classes. Forked and based on https://github.com/bcherny/json-schema-to-typescript

Example

Input:

{
  "title": "Example Schema",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string"
    },
    "lastName": {
      "type": "string"
    },
    "age": {
      "description": "Age in years",
      "type": "integer",
      "minimum": 0
    },
    "hairColor": {
      "enum": ["black", "brown", "blue"],
      "type": "string"
    }
  },
  "additionalProperties": false,
  "required": ["firstName", "lastName"]
}

Output:

import { ConfigClient } from '@enrolla/enrolla-ts'

export class Person {
  constructor(private objectId: string) {}

  firstName(): string {
    return ConfigClient.get(this.objectId, 'firstName')
  }

  lastName(): string {
    return ConfigClient.get(this.objectId, 'lastName')
  }

  /**
   * Age in years
   */
  age(): number | undefined {
    return ConfigClient.get(this.objectId, 'age')
  }

  hairColor(): ('black' | 'brown' | 'blue') | undefined {
    return ConfigClient.get(this.objectId, 'hairColor')
  }
}

Installation

# Using Yarn:
yarn add @enrolla/cli --dev

# Or, using NPM:
npm install @enrolla/cli --save-dev

Usage

enrolla-cli -i schemas/ -o configs/

Packages

No packages published

Languages

  • TypeScript 99.9%
  • JavaScript 0.1%