Coder Social home page Coder Social logo

uppercrust's Introduction

Uppercrust

Inspired by jsonschema2pojo, uppercrust is your trusty companion to generate Mantle compatible model files in Objective-C.

Uppercrust generates two header and two implementation files for each of your models. One set is prefixed with an underscore and is meant to be overwritten whenever the JSON schema changes. The files without underscore extends these classes and can be used to add custom functionality and custom mappings and should only be generated once.

Installation

Install the gem as:

$ gem install uppercrust

Usage

$ uppercrust generate --path {path} --base_only true|false

This generate an output folder with all the JSON files mapped to their Objective-C counterparts.

Say for example, you have a model file named 'article.json'. Running uppercrust will then generate 4 files for you:

  • _Article.h
  • _Article.m
  • Article.h
  • Article.m

Lets look at the following simple example:

{
    "type":"object",
    "$schema":"http://json-schema.org/draft-03/schema",
    "id":"Article",
    "description":"Result object that represents an article.",
    "required":true,
    "additionalProperties":false,
    "properties":{
        "brand":{
            "type":"string",
            "id":"brand",
            "required":true
        },
        "sku":{
            "type":"string",
            "id":"sku",
            "required":true
        }
    }
}

_Article.h:

// DO NOT EDIT. This file is machine-generated and constantly overwritten.
// Make changes to article.h instead.
//
// Result object that represents an article.

#import <Mantle/Mantle.h>


@interface _Article : MTLModel<MTLJSONSerializing>

@property(nonatomic, copy, readonly) NSString *brand;
@property(nonatomic, copy, readonly) NSString *sku;

@end

_Article.m:

// DO NOT EDIT. This file is machine-generated and constantly overwritten.
// Make changes to Article.m instead.

#import "_Article.h"

@implementation _Article

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
   return @{
       @"brand" : @"brand",
       @"sku" : @"sku"
   };
}


@end

Article.h:

#import "_Article.h"

@interface Article : _Article
@end

Article.m:

#import "Article.h"

@implementation Article

@end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

TODO

  • Add tests!
  • Add some special types to the schema since Foundation has a richer vocabulary
  • Add the option to prefix the generated class names

uppercrust's People

Contributors

dependabot-preview[bot] avatar jangorman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

uppercrust's Issues

gem install crust does not work

Hi,

I'm using rbenv, and gems like cocoapods work just fine.

I was able to run gem install crust, it succeeds, but does not install a bin crust.

How can I run it ?

How do I start this framework from starting?

Hi,
As I got this framework link from google, and I want to use this framework to convert the my json data to model class.
As I am not getting the proper information in detail,so I need some more information about where I need to pass the JSON data.
I have installed the gem on my machine.

$ uppercrust generate --path {path} --base_only true|false

In the above command, there is nothing where I pass the json data.
And also I have taken the clone this framework on my machine.

Thanks,
Dinesh S

Undefined method `each' for nil:NilClas

Hi!
Your project is awesome.
I'm having problems when trying to create the file.

/.rvm/gems/ruby-2.1.2/gems/uppercrust-0.0.1/lib/uppercrust/parser.rb:115:in extract_properties': undefined methodeach' for nil:NilClass (NoMethodError)
from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/gems/uppercrust-0.0.1/lib/uppercrust/parser.rb:12:in initialize' from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/gems/uppercrust-0.0.1/lib/uppercrust/generator.rb:35:innew'
from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/gems/uppercrust-0.0.1/lib/uppercrust/generator.rb:35:in block in read_files' from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/gems/uppercrust-0.0.1/lib/uppercrust/generator.rb:33:ineach'
from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/gems/uppercrust-0.0.1/lib/uppercrust/generator.rb:33:in read_files' from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/gems/uppercrust-0.0.1/lib/uppercrust/generator.rb:15:ingenerate'
from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/gems/uppercrust-0.0.1/lib/uppercrust/cli.rb:10:in generate' from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/gems/thor-0.19.1/lib/thor/command.rb:27:inrun'
from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/gems/thor-0.19.1/lib/thor/invocation.rb:126:in invoke_command' from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/gems/thor-0.19.1/lib/thor.rb:359:indispatch'
from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/gems/thor-0.19.1/lib/thor/base.rb:440:in start' from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/gems/uppercrust-0.0.1/bin/uppercrust:3:in<top (required)>'
from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/bin/uppercrust:23:in load' from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/bin/uppercrust:23:in

'
from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in eval' from /Users/jhrochasousa/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in'

What could be ?

Thank you, again.

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.