Skip to content

Commit

Permalink
Merge pull request #161 from swagger-api/not_empty_helper
Browse files Browse the repository at this point in the history
Not empty helper
  • Loading branch information
HugoMario authored Sep 3, 2018
2 parents 92dadca + bf93df5 commit 67aa6e8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.swagger.codegen.v3.generators.handlebars.HasNotHelper;
import io.swagger.codegen.v3.generators.handlebars.IsHelper;
import io.swagger.codegen.v3.generators.handlebars.IsNotHelper;
import io.swagger.codegen.v3.generators.handlebars.NotEmptyHelper;
import io.swagger.codegen.v3.generators.handlebars.StringUtilHelper;
import io.swagger.codegen.v3.templates.HandlebarTemplateEngine;
import io.swagger.codegen.v3.templates.TemplateEngine;
Expand Down Expand Up @@ -3336,6 +3337,7 @@ public void addHandlebarHelpers(Handlebars handlebars) {
handlebars.registerHelper(HasNotHelper.NAME, new HasNotHelper());
handlebars.registerHelper(BracesHelper.NAME, new BracesHelper());
handlebars.registerHelper(BaseItemsHelper.NAME, new BaseItemsHelper());
handlebars.registerHelper(NotEmptyHelper.NAME, new NotEmptyHelper());
handlebars.registerHelpers(new StringUtilHelper());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.swagger.codegen.v3.generators.handlebars;

import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;

import java.io.IOException;
import java.util.Collection;

public class NotEmptyHelper implements Helper<Collection> {
public static final String NAME = "notEmpty";

@Override
public Object apply(Collection collection, Options options) throws IOException {
final Options.Buffer buffer = options.buffer();

if (collection == null || collection.isEmpty()) {
buffer.append(options.inverse());
} else {
buffer.append(options.fn());
}
return buffer;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/v2/JavaJaxRS/pojo.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali

@Override
public int hashCode() {
return Objects.hash({{#vars}}{{name}}{{#has this 'more'}}, {{/has}}{{/vars}}{{#parentModel}}{{#has this 'vars'}}, {{/has}}super.hashCode(){{/parentModel}});
return Objects.hash({{#vars}}{{name}}{{#has this 'more'}}, {{/has}}{{/vars}}{{#parentModel}}{{#has ../this 'vars'}}, {{/has}}super.hashCode(){{/parentModel}});
}

{{/supportJava6}}
Expand Down

0 comments on commit 67aa6e8

Please sign in to comment.