Skip to content

Fixing #24, #25 and #30 #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: feature/refactor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions metajson/JSONScheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ def getClassName(self):

print "error : " + self.type_name + " has no Class Name."
return ""

def getFileClassName(self):
if self.rootBaseType() == "object" :
className = self.type_name.upper()
className = self.projectPrefix + className[:1] + self.type_name[1:] + self.objectSuffix
return className
print "error : " + self.type_name + " has no Class Name."
return ""

def getMachineClassName(self):

Expand Down
26 changes: 14 additions & 12 deletions metajson/SourceCodeGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def meta_property(self, schemeObj):
if hasRegex:
meta_hash['regex'] = regex

if schemeObj.rootBaseType() == "string" or schemeObj.rootBaseType() == "data":
hasMax, maxLength = schemeObj.getMaxLength()
if hasMax:
meta_hash['maxLength'] = maxLength
Expand All @@ -102,14 +103,14 @@ def meta_property(self, schemeObj):
if hasMin:
meta_hash['minLength'] = minLength

if schemeObj.rootBaseType() == "number":
hasMax, maxLength = schemeObj.getMaxValue()
if schemeObj.rootBaseType() == "number" or schemeObj.rootBaseType() == "date":
hasMax, maxValue = schemeObj.getMaxValue()
if hasMax:
meta_hash['maxValue'] = maxLength
meta_hash['maxValue'] = str(maxValue)

hasMin, minLength = schemeObj.getMinValue()
hasMin, minValue = schemeObj.getMinValue()
if hasMin:
meta_hash['minValue'] = minLength
meta_hash['minValue'] = str(minValue)

if schemeObj.rootBaseType() == "array":
hasMax, maxLength = schemeObj.getMaxCount()
Expand Down Expand Up @@ -221,7 +222,8 @@ def process_properties(self, propObj, undefined = False) :
hasRegex, regex = propObj.getRegex()
if hasRegex:
propertyHash['regex'] = regex


if propObj.rootBaseType() == "string" or propObj.rootBaseType() == "data":
hasMax, maxLength = propObj.getMaxLength()
if hasMax:
propertyHash['maxLength'] = maxLength
Expand All @@ -230,14 +232,14 @@ def process_properties(self, propObj, undefined = False) :
if hasMin:
propertyHash['minLength'] = minLength

if propObj.rootBaseType() == "number":
hasMax, maxLength = propObj.getMaxValue()
if propObj.rootBaseType() == "number" or propObj.rootBaseType() == "date":
hasMax, maxValue = propObj.getMaxValue()
if hasMax:
propertyHash['maxValue'] = maxLength
propertyHash['maxValue'] = str(maxValue)

hasMin, minLength = propObj.getMinValue()
hasMin, minValue = propObj.getMinValue()
if hasMin:
propertyHash['minValue'] = minLength
propertyHash['minValue'] = str(minValue)

if propObj.rootBaseType() == "array":
hasMax, maxLength = propObj.getMaxCount()
Expand Down Expand Up @@ -313,7 +315,7 @@ def render(self, schemeObj, template_content) :
hashParams["_snakecase"] = self.lambda_snakecase
hashParams["_upper_snakecase"] = self.lambda_upper_snakecase
if schemeObj.getScheme(schemeObj.base_type):
hashParams['baseClassName'] = schemeObj.getScheme(schemeObj.base_type).getClassName()
hashParams['baseClassName'] = schemeObj.getScheme(schemeObj.base_type).getFileClassName()

if schemeObj.base_type == 'object':
hashParams['baseTypeIsObject'] = True
Expand Down
2 changes: 1 addition & 1 deletion metajson/readJSON.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def main(argv=sys.argv):
for template_filename in templateCodeGen.json_template_files:
template = open(template_filename)
content = codeGen.render(obj, template.read())
file = templateCodeGen.create_template_output_file(template_filename, obj.getClassName())
file = templateCodeGen.create_template_output_file(template_filename, obj.getFileClassName())
try:
file.write(content)
finally :
Expand Down
8 changes: 7 additions & 1 deletion samples/product.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[
{
"name": "base",
"description": "Base class for all JSON Objects",
"base-type": "object"
},
{
"name" : "sender",
"base-type" : "object",
Expand Down Expand Up @@ -107,7 +112,8 @@
"name" : "type",
"base-type" : "number",
"description" : "the type of product",
"required" : 1
"required" : 1,
"minValue" : 0
},
{
"name" : "advantage",
Expand Down
6 changes: 5 additions & 1 deletion samples/product.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
-
name: base
base-type: object
description: 'Base class for all JSON Objects'
-
name: sender
base-type: object
Expand Down Expand Up @@ -30,4 +34,4 @@
name: ProductDetail
base-type: object
description: 'Product details.'
property: [{ name: type, base-type: number, description: 'the type of product', required: 1 }, { name: advantage, base-type: number, required: 1 }, { name: teaserURL, base-type: string, description: 'teaser image url of product', required: 1 }, { name: telephoneFlatrate, base-type: string, description: 'telephone Flatrate option string' }, { name: includeHardware, base-type: boolean, required: 1 }, { name: senderInfo, base-type: senderGroup }, { name: anyProperty, base-type: any, required: 1 }, { name: title, base-type: [titleString, string], description: 'the title of product', required: 1 }, { name: download, base-type: [number, string], description: 'download speed (Mbit/s)', required: 1 }, { name: upload, base-type: [number, string], description: 'upload speed (Mbit/s)', required: 1 }]
property: [{ name: type, base-type: number, description: 'the type of product', required: 1, minValue: 0 }, { name: advantage, base-type: number, required: 1 }, { name: teaserURL, base-type: string, description: 'teaser image url of product', required: 1 }, { name: telephoneFlatrate, base-type: string, description: 'telephone Flatrate option string' }, { name: includeHardware, base-type: boolean, required: 1 }, { name: senderInfo, base-type: senderGroup }, { name: anyProperty, base-type: any, required: 1 }, { name: title, base-type: [titleString, string], description: 'the title of product', required: 1 }, { name: download, base-type: [number, string], description: 'download speed (Mbit/s)', required: 1 }, { name: upload, base-type: [number, string], description: 'upload speed (Mbit/s)', required: 1 }]
18 changes: 18 additions & 0 deletions test/data/product/AbstractInterfaceFiles/_BaseJSONObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// _BaseJSONObject.h
//
// Created by MetaJSONParser.
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved.

#import <Foundation/Foundation.h>

@class BaseJSONObject;

@interface _BaseJSONObject : NSObject <NSCoding>


+ (BaseJSONObject *)baseWithDictionary:(NSDictionary *)dic withError:(NSError **)error;
- (id)initWithDictionary:(NSDictionary *)dic withError:(NSError **)error;
- (NSDictionary *)propertyDictionary;

@end
57 changes: 57 additions & 0 deletions test/data/product/AbstractInterfaceFiles/_BaseJSONObject.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// _BaseJSONObject.m
//
// Created by MetaJSONParser.
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved.

#import "APIParser.h"
#import "NSString+RegExValidation.h"
#import "BaseJSONObject.h"


@implementation _BaseJSONObject

#pragma mark - factory

+ (BaseJSONObject *)baseWithDictionary:(NSDictionary *)dic withError:(NSError **)error
{
return [[BaseJSONObject alloc] initWithDictionary:dic withError:error];
}

#pragma mark - initialize
- (id)initWithDictionary:(NSDictionary *)dic withError:(NSError **)error
{
self = [super init];
if (self) {
}
return self;
}

#pragma mark - getter

#pragma mark - NSCoding

- (void)encodeWithCoder:(NSCoder*)coder
{
[super encodeWithCoder:coder];
}

- (id)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
return self;
}

#pragma mark - Object Info
- (NSDictionary *)propertyDictionary
{
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
return dic;
}

- (NSString *)description
{
return [[self propertyDictionary] description];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ - (id)initWithDictionary:(NSDictionary *)dic withError:(NSError **)error
if (*error) {
return self;
}
if (self.type.length < 0) {
NSDictionary *userInfo = @{@"propertyName" : @"type",
@"key" : @"type",
@"reason" : @"min value validation error",
@"objectClass" : NSStringFromClass([self class])
};
*error = [NSError errorWithDomain:kErrorDomain_parser code:kErrorDomain_parser_valueIsNotValid userInfo:userInfo];
NSLog(@"%@", *error);
return self;
}

self.advantage = [APIParser numberFromResponseDictionary:dic forKey:@"advantage" acceptNil:NO error:error];
if (*error) {
return self;
Expand Down
10 changes: 10 additions & 0 deletions test/data/product/BaseJSONObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// BaseJSONObject.h
//
// Created by MetaJSONParser.
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved.

#import "_BaseJSONObject.h"
@interface BaseJSONObject : _BaseJSONObject

@end
15 changes: 15 additions & 0 deletions test/data/product/BaseJSONObject.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// BaseJSONObject.m
//
// Created by MetaJSONParser.
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved.

#import "BaseJSONObject.h"

@interface BaseJSONObject ()

@end

@implementation BaseJSONObject

@end