Git Product home page Git Product logo

jstsm's Introduction

JSTSM

JSON Schema To Swift Model

./jstsm -s model.json -> Model.swift

Handled

  • basic types
    • string -> String
    • integer -> Int
    • number -> Double
    • boolean -> Bool
  • array type
  • $ref
  • required -> Optional
  • header (with --has-header)
    • project (with -p | --project )
    • author (with -a | --author )
    • company (with -c | --company )
  • class Or struct (with --use-struct)
  • extends custom schema key (with $ref) for inheritance (with --enable-extends)

TODO

  • allOf, anyOf, oneOf ..
  • pass dir as source and transform recursively *.json files

Help

./jstsm -h

Exemple

Basic.json file

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "title": "",
    "description": "",
    "properties": {
        "string": { "type": "string" },
        "optString": { "type": "string" },
        "optInteger": { "type": "integer" },
        "optNumber": { "type": "number" },
        "boolean": { "type": "boolean" },
        "optBoolean": { "type": "boolean" }
    },
    "required": ["string", "boolean"]
}

node index.js -s json_schemas/basic.json -a Me -p MyProject -c MyCompany --use-struct

Basic.swift output file

//
//  Basic.swift
//  MyProject
//
//  Created by Me on 07/04/16.
//  Copyright © 2016 MyCompany. All rights reserved.
//
//  This file has been generated, modify it at your own risks!
//

struct Basic {

  // MARK: - Properties

  let string: String
  let optString: String?
  let optInteger: Int?
  let optNumber: Double?
  let boolean: Bool
  let optBoolean: Bool?

  // MARK: - Inits

  init?(json: [String: AnyObject]) {
  
    self.string = json["string"] as! String
    self.optString = json["optString"] as? String
    self.optInteger = json["optInteger"] as? Int
    self.optNumber = json["optNumber"] as? Double
    self.boolean = json["boolean"] as! Bool
    self.optBoolean = json["optBoolean"] as? Bool
  }

}

jstsm's People

Contributors

akabab avatar

Watchers

 avatar  avatar

Forkers

topchyalexey

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.