diff --git a/src/main/java/com/wordnik/swagger/codegen/CodegenModel.java b/src/main/java/com/wordnik/swagger/codegen/CodegenModel.java index 7dcb491dda1..776cce9cdc7 100644 --- a/src/main/java/com/wordnik/swagger/codegen/CodegenModel.java +++ b/src/main/java/com/wordnik/swagger/codegen/CodegenModel.java @@ -11,4 +11,5 @@ public class CodegenModel { public String defaultValue; public List vars = new ArrayList(); public Set imports = new HashSet(); + public Boolean hasVars, emptyVars; } \ No newline at end of file diff --git a/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java b/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java index c715cfe6b41..e06497f7900 100644 --- a/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java +++ b/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java @@ -353,7 +353,8 @@ public class DefaultCodegen { m.imports.add(containerType); } } - if(impl.getProperties() != null) { + if(impl.getProperties() != null && impl.getProperties().size() > 0) { + m.hasVars = true; for(String key: impl.getProperties().keySet()) { Property prop = impl.getProperties().get(key); @@ -396,6 +397,9 @@ public class DefaultCodegen { } } } + else { + m.emptyVars = true; + } } return m; } diff --git a/src/main/resources/objc/model-body.mustache b/src/main/resources/objc/model-body.mustache index 6ffe52eb1b1..43555d48a19 100644 --- a/src/main/resources/objc/model-body.mustache +++ b/src/main/resources/objc/model-body.mustache @@ -3,15 +3,16 @@ #import "SWGDate.h" #import "{{classname}}.h" -@implementation {{classname}} +@implementation {{classname}}{{#parent}}: {{parent}}{{/parent}} +{{#hasVars}} -(id){{#vars}}{{name}}: ({{datatype}}) {{name}}{{^hasMore}} { {{/hasMore}} {{/vars}} {{#vars}}_{{name}} = {{name}}; {{/vars}} return self; } - +{{/hasVars}} -(id) initWithValues:(NSDictionary*)dict { self = [super init]; diff --git a/src/main/resources/objc/model-header.mustache b/src/main/resources/objc/model-header.mustache index de4b085e000..e8dc61316e0 100644 --- a/src/main/resources/objc/model-header.mustache +++ b/src/main/resources/objc/model-header.mustache @@ -11,10 +11,11 @@ {{#vars}} @property(nonatomic) {{datatype}} {{name}}; {{#description}}/* {{{description}}} {{#isNotRequired}}[optional]{{/isNotRequired}} */{{/description}}{{newline}} {{/vars}} +{{#hasVars}} - (id) {{#vars}}{{name}}: ({{datatype}}) {{name}}{{#hasMore}} {{/hasMore}}{{^hasMore}};{{/hasMore}} {{/vars}} -{{newline}} +{{/hasVars}} - (id) initWithValues: (NSDictionary*)dict; - (NSDictionary*) asDictionary; {{newline}}