Skip to content

Commit

Permalink
support with optional props when null is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsontom committed Nov 19, 2024
1 parent a5c7f1f commit f65d8b1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions dsl/src/cli/java-rest-client-jdk/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ export function generateBuilderProperty(node: IndentNode, property: MKeyProperty
node.append('@Override', NL)
node.append(`public ${typePrefix ? `${typePrefix}.`: ''}Builder ${property.name}(${toType(property, artifactConfig, fqn)} ${property.name}) {`, NL)
node.indent( methodBody => {
if( property.optional && ! property.nullable && ( isMBuiltinType(property.type) && ! isJavaPrimitive(property.type) ) ) {
methodBody.append(`if( ${property.name} == null ) {`, NL);
methodBody.indent( block => block.append('return this;', NL))
methodBody.append('}',NL);
}
if( property.array ) {
if( property.variant === 'builtin' && isMBuiltinType(property.type) ) {
methodBody.append(`${builtinBuilderArrayJSONAccess({ type: property.type, name: property.name })});`, NL)
Expand Down Expand Up @@ -180,3 +185,16 @@ export function builtinBuilderAccess(property: { type: MBuiltinType, name: strin
return `$builder.add("${property.name}", ${property.name}.toString())`;
}
}

function isJavaPrimitive(type: MBuiltinType) {
switch(type) {
case 'boolean':
case 'double':
case 'float':
case 'int':
case 'long':
case 'short':
return true;
}
return false;
}

0 comments on commit f65d8b1

Please sign in to comment.