Giter Club home page Giter Club logo

model-generator's Introduction

Model-Generator

Generate code for basic models from JSON schema.

Languages

  • Java
  • Groovy
  • Kotlin
  • TypeScript
  • T-SQL

To Do

  • unit tests for java and groovy before moving on
  • generate build files in directories

Possible Improvements

  • Constants / final properties ?
  • Serialization
  • Builder methods
  • hashCode, toString, and equals methods
  • Parameterized constructor using 'required' on object properties
  • On a similar note, call parameterized super constructor

Specification

A couple of new properties were added to add more functionality.

  • extends - extend from other object in another schema
  • primitive - array: T[] or List ; numbers: Float or float; Integer or int
  • parseTo - attempt a parse to non-standard JSON schema types (BigDecimal, Long, Byte, etc)
    • If parsing fails on a field, it falls back to whatever is specified in type
{
  "id": "http://json-schema.org/thing",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Book",
  "description": "A book",
  "type": "object",
  "extends": {
    "$ref": "Common/Thing.json" // relative to schema directory
  },
  "properties": {
    "genres": {
      "type": "array",
      "items": {
        "type": "string", // String.class
        "maxItems": 10,   // String[10] init in constructor
        "primitive": true // true= T[], false/null= List<T>
      }
    },
    "pageLength": {
      "type": "integer",  // Integer.class
      "parseTo": "Long",  // attempt parse to Long.class
      "default": 25       // default value to 25 in constructor
    },
    "isbn": {
      "type": "string"
    },
    "author": {
      "$ref": "Common/Person.json" // Person.class relative to schema directory
    },
    "price": {
      "type": "number",    // Float.class
      "parseTo": "decimal" // attempt parse to BigDecimal for currency handling, falls back to Float if failed
    }
  }
}

Commands

  • Run tests python -m unittest

References

model-generator's People

Contributors

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