Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

cknadler/nidyx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Chris Knadler
Jul 13, 2016
75150a1 · Jul 13, 2016
May 22, 2015
Jul 13, 2016
Jul 12, 2016
Jul 12, 2016
Feb 28, 2016
Mar 16, 2015
Feb 28, 2016
Jul 12, 2016
Dec 22, 2013
Jul 13, 2016
Sep 8, 2015
Mar 3, 2016
Mar 3, 2016
May 22, 2015
Feb 28, 2016

Repository files navigation

Nidyx Gem Version Build Status Code Climate Documentation

JSON Schema ⇒ Model

Nidyx generates Objective-C models from JSON Schema. It can also generate models with JSONModel support.

Install

$ gem install nidyx

Usage

usage: nidyx [-h] [--version]
       nidyx <schema> [-n] [-a author] [-c company] [-p project]
             [-o directory] [-x prefix]
             [--json-model] # objc specific

    -a, --author AUTHOR              Author's name
    -c, --company COMPANY            Company's name
    -p, --project PROJECT            Project's name
    -o, --output DIRECTORY           Output models to a specific directory
    -x, --class-prefix PREFIX        Add a prefix to generated model names
    -n, --no-comments                Generate without header comments
        --json-model                 Generate with JSONModel support
    -h, --help                       Print usage information
        --version                    Print version

Nidyx generates plain Objective-C models from JSON Schema. It can also generate
models with JSONModel support.

Examples
========

Generate models for a given schema.

  $ nidyx example.json.schema

Specify an ouput directory and a class prefix:

  $ nidyx example.json.schema -x ClassPrefix -o /path/to/output/directory

Generate with JSONModel support and optional documentation:

  $ nidyx example.json.schema --json-model -a "Your Name" -p "Project Name"

Features

JSON Schema draft 4 support:

Nidyx exclusively supports JSON Schema draft 4. All previous drafts are not supported intentionally.

Examples

Examples are run with the following unless otherwise specified:

$ nidyx example.json.schema Example

Simple Properties

{
  "properties": {
    "key": { "type": "string" },
    "value": { "type": "string" }
  }
}
// ExampleModel.h
@interface ExampleModel
@property (strong, nonatomic) NSString* key;
@property (strong, nonatomic) NSString* value;
@end

Refs and Nested Properties

{
  "properties": {
    "id": {
      "type": "object",
      "properties": {
        "key": { "type": "string" },
        "hash": { "type": "string" }
      }
    },
    "value":  { "$ref": "#/definitions/obj" }
  },
  "definitions": {
    "obj": {
      "type": "object",
      "properties": {
        "banner": { "$ref": "#/definitions/banner" },
        "name": { "type": "string" },
        "count": { "type": "integer" }
      }
    },
    "banner": { "type": "string" }
  }
}
// ExampleModel.h
#import "ExampleIdModel.h"
#import "ExampleObjModel.h"
@interface ExampleModel
@property (strong, nonatomic) ExampleIdModel* id;
@property (strong, nonatomic) ExampleObjModel* value;
@end

// ExampleIdModel.h
@interface ExampleIdModel
@property (strong, nonatomic) NSString* key;
@property (strong, nonatomic) NSString* hash;
@end

// ExampleObjModel.h
@interface ExampleObjModel
@property (strong, nonatomic) NSString* banner;
@property (strong, nonatomic) NSString* name;
@property (assign, nonatomic) NSInteger count;
@end

Caveats

  • The following is omitted from the beginning of all JSON examples:
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
  • .m files are also omitted from all examples

License

MIT.

About

JSON Schema -> Objective-C model generator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published