Skip to content
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

Fix for Issue 346 #364

Open
wants to merge 2 commits into
base: master
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
5 changes: 5 additions & 0 deletions filters/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ function identifierName(str) {
}
filter.identifierName = identifierName;

function methodName(str) {
return scsLib.getMethodName(str);
}
filter.methodName = methodName;

function indent1(numTabs) {
return indent(numTabs);
}
Expand Down
12 changes: 12 additions & 0 deletions lib/scsLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ class ScsLib {
return ret;
}

// This returns a valid method name fro an identifier.
getMethodName(name) {
let ret = _.camelCase(name);
ret = _.upperFirst(ret);

if (ScsLib.javaKeywords.has(ret)) {
ret = `_${ret}`;
}

return ret;
}
Comment on lines +30 to +40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused at first because a method shouldn't start with a capital letter, but I see a 'get' or 'set' is prepended to this name in the template. Maybe calling this getMethodNameSuffix would make that clearer.
Also, since this is so close to being the same as getClassName or getIdentifierName, I wonder if we can use those instead. Calling both getClassName and getIdentifierName would do it, but that's weird. Maybe calling getIdentifierName and doing _.upperFirst() is fine.


// This returns the value of a param, or specification extension if the param isn't set.
// If neither is set and the required flag is true, it throws an error.
getParamOrExtension(info, params, paramName, extensionName, description, example, required) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"jest": "^27.0.4"
},
"generator": {
"generator": ">=1.8.6 <=2.3.0",
"generator": ">=1.8.6 <=2.6.0",
"parameters": {
"actuator": {
"description": "If present, it adds the dependencies for spring-boot-starter-web, spring-boot-starter-actuator and micrometer-registry-prometheus.",
Expand Down
6 changes: 6 additions & 0 deletions partials/all-args-constructor
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
{%- set propModelClass = {schema: prop, schemaName: name} | getModelClass %}
{%- set realClassName = propModelClass.getClassName() %}
{%- set variableName = realClassName | identifierName %}
{%- if name != variableName -%}
{%- set variableName = name | identifierName -%}
{%- endif -%}
{%- set typeInfo = [name, realClassName, prop] | fixType %}
{%- set type = typeInfo[0] -%}
{%- if first -%}
Expand All @@ -23,6 +26,9 @@
{%- set propModelClass = {schema: prop, schemaName: name} | getModelClass %}
{%- set realClassName = propModelClass.getClassName() %}
{%- set variableName = realClassName | identifierName -%}
{%- if name != variableName -%}
{%- set variableName = name | identifierName -%}
{%- endif -%}
{{ indent3 }}this.{{ variableName }} = {{ variableName }};
{% endfor -%}
{{ indent2 }}}
Expand Down
19 changes: 16 additions & 3 deletions partials/java-class
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
{%- set propModelClass = {schema: prop, schemaName: name} | getModelClass %}
{%- set realClassName = propModelClass.getClassName() %}
{%- set variableName = realClassName | identifierName -%}
{%- if name != variableName -%}
{%- set variableName = name | identifierName -%}
{%- endif -%}
{%- set typeInfo = [realClassName, realClassName, prop] | fixType -%}
{%- set type = typeInfo[0] %}
{% if variableName !== name -%}
Expand All @@ -43,15 +46,19 @@
{%- for name, prop in properties %}
{%- set propModelClass = {schema: prop, schemaName: name} | getModelClass %}
{%- set realClassName = propModelClass.getClassName() %}
{%- set realMethodName = name | methodName -%}
{%- set variableName = realClassName | identifierName -%}
{%- if name != variableName -%}
{%- set variableName = name | identifierName -%}
{%- endif -%}
{%- set typeInfo = [name, realClassName, prop] | fixType -%}
{% set type = typeInfo[0] -%}
{% set isArrayOfObjects = typeInfo[1] %}
{{ indent2 }}public {{ type }} get{{- realClassName }}() {
{{ indent2 }}public {{ type }} get{{- realMethodName }}() {
{{ indent3 }}return {{ variableName }};
{{ indent2 }}}

{{ indent2 }}public {{ className }} set{{- realClassName }}({{ type }} {{ variableName }}) {
{{ indent2 }}public {{ className }} set{{- realMethodName }}({{ type }} {{ variableName }}) {
{{ indent3 }}this.{{-variableName }} = {{ variableName }};
{{ indent3 }}return this;
{{ indent2 }}}
Expand All @@ -65,16 +72,22 @@
{%- endif %}
{# Enums #}
{%- if prop.enum() %}
{{ indent2 }}public static enum {{ type }} { {{ prop.enum() }} }
{{ indent2 }}public static enum {{ type }} {
{{ indent3 }} {{ prop.enum() }}
{{ indent2 }}};
{%- endif %}
{%- endfor -%}
{{ indent2 }}

{{ indent2 }}public String toString() {
{{ indent3 }}return "{{ className }} ["
{%- for name, prop in properties %}
{%- set propModelClass = {schema: prop, schemaName: name} | getModelClass %}
{%- set realClassName = propModelClass.getClassName() %}
{%- set variableName = realClassName | identifierName %}
{%- if name != variableName -%}
{%- set variableName = name | identifierName -%}
{%- endif -%}
{%- set typeInfo = [realClassName, realClassName, prop] | fixType -%}
{%- set type = typeInfo[0] %}
{{ indent3 }}+ " {{ variableName }}: " + {{ variableName }}
Expand Down
17 changes: 8 additions & 9 deletions test/__snapshots__/integration.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1007,24 +1007,23 @@ public class SentAt {
}

public SentAt (
SubObject subObject) {
this.subObject = subObject;
SubObject propertySubobject) {
this.propertySubobject = propertySubobject;
}

@JsonProperty(\\"propertySubobject\\")
private SubObject subObject;
public SubObject getSubObject() {
return subObject;
private SubObject propertySubobject;
public SubObject getPropertySubobject() {
return propertySubobject;
}

public SentAt setSubObject(SubObject subObject) {
this.subObject = subObject;
public SentAt setPropertySubobject(SubObject propertySubobject) {
this.propertySubobject = propertySubobject;
return this;
}

public String toString() {
return \\"SentAt [\\"
+ \\" subObject: \\" + subObject
+ \\" propertySubobject: \\" + propertySubobject
+ \\" ]\\";
}
}
Expand Down
Loading