Skip to content

Commit e3a955c

Browse files
committed
Add null and empty check before adding value to additionalProperties
1 parent 8c74a48 commit e3a955c

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

src/main/java/io/swagger/codegen/languages/DefaultCodegenConfig.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,23 +166,23 @@ public void processOpts() {
166166

167167
if (additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) {
168168
this.setModelPackage((String) additionalProperties.get(CodegenConstants.MODEL_PACKAGE));
169-
} else {
170-
// not set, use to be passed to template
169+
} else if (StringUtils.isNotEmpty(modelPackage)) {
170+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
171171
additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
172172
}
173173

174174
if (additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
175175
this.setApiPackage((String) additionalProperties.get(CodegenConstants.API_PACKAGE));
176-
} else {
177-
// not set, use to be passed to template
176+
} else if (StringUtils.isNotEmpty(apiPackage)) {
177+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
178178
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
179179
}
180180

181181
if (additionalProperties.containsKey(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG)) {
182182
this.setSortParamsByRequiredFlag(Boolean.valueOf(additionalProperties
183183
.get(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG).toString()));
184-
} else {
185-
// not set, use to be passed to template
184+
} else if (sortParamsByRequiredFlag != null) {
185+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
186186
additionalProperties.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, sortParamsByRequiredFlag);
187187
}
188188

@@ -212,8 +212,8 @@ public void processOpts() {
212212
if (additionalProperties.containsKey(CodegenConstants.HIDE_GENERATION_TIMESTAMP)) {
213213
this.setHideGenerationTimestamp(Boolean.valueOf(additionalProperties
214214
.get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
215-
} else {
216-
//not set, use to be passed to template
215+
} else if(hideGenerationTimestamp != null) {
216+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
217217
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, hideGenerationTimestamp);
218218
}
219219
}

src/main/java/io/swagger/codegen/languages/java/AbstractJavaCodegen.java

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ public void processOpts() {
181181
this.additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, derviedInvokerPackage);
182182
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
183183
LOGGER.info("Invoker Package Name, originally not set, is now dervied from model package name: " + derviedInvokerPackage);
184-
} else {
185-
//not set, use default to be passed to template
184+
} else if (StringUtils.isNotEmpty(invokerPackage)) {
185+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
186186
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
187187
}
188188

@@ -201,88 +201,99 @@ public void processOpts() {
201201

202202
if (additionalProperties.containsKey(CodegenConstants.GROUP_ID)) {
203203
this.setGroupId((String) additionalProperties.get(CodegenConstants.GROUP_ID));
204-
} else {
205-
//not set, use to be passed to template
204+
} else if(StringUtils.isNotEmpty(groupId)) {
205+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
206206
additionalProperties.put(CodegenConstants.GROUP_ID, groupId);
207207
}
208208

209209
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_ID)) {
210210
this.setArtifactId((String) additionalProperties.get(CodegenConstants.ARTIFACT_ID));
211-
} else {
212-
//not set, use to be passed to template
211+
} else if(StringUtils.isNotEmpty(artifactId)) {
212+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
213213
additionalProperties.put(CodegenConstants.ARTIFACT_ID, artifactId);
214214
}
215215

216216
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_VERSION)) {
217217
this.setArtifactVersion((String) additionalProperties.get(CodegenConstants.ARTIFACT_VERSION));
218-
} else {
219-
//not set, use to be passed to template
218+
} else if(StringUtils.isNotEmpty(artifactVersion)) {
219+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
220220
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
221221
}
222222

223223
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_URL)) {
224224
this.setArtifactUrl((String) additionalProperties.get(CodegenConstants.ARTIFACT_URL));
225-
} else {
225+
} else if(StringUtils.isNoneEmpty(artifactUrl)) {
226+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
226227
additionalProperties.put(CodegenConstants.ARTIFACT_URL, artifactUrl);
227228
}
228229

229230
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_DESCRIPTION)) {
230231
this.setArtifactDescription((String) additionalProperties.get(CodegenConstants.ARTIFACT_DESCRIPTION));
231-
} else {
232+
} else if(StringUtils.isNoneEmpty(artifactDescription)) {
233+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
232234
additionalProperties.put(CodegenConstants.ARTIFACT_DESCRIPTION, artifactDescription);
233235
}
234236

235237
if (additionalProperties.containsKey(CodegenConstants.SCM_CONNECTION)) {
236238
this.setScmConnection((String) additionalProperties.get(CodegenConstants.SCM_CONNECTION));
237-
} else {
239+
} else if(StringUtils.isNoneEmpty(scmConnection)) {
240+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
238241
additionalProperties.put(CodegenConstants.SCM_CONNECTION, scmConnection);
239242
}
240243

241244
if (additionalProperties.containsKey(CodegenConstants.SCM_DEVELOPER_CONNECTION)) {
242245
this.setScmDeveloperConnection((String) additionalProperties.get(CodegenConstants.SCM_DEVELOPER_CONNECTION));
243-
} else {
246+
} else if(StringUtils.isNoneEmpty(scmDeveloperConnection)) {
247+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
244248
additionalProperties.put(CodegenConstants.SCM_DEVELOPER_CONNECTION, scmDeveloperConnection);
245249
}
246250

247251
if (additionalProperties.containsKey(CodegenConstants.SCM_URL)) {
248252
this.setScmUrl((String) additionalProperties.get(CodegenConstants.SCM_URL));
249-
} else {
253+
} else if(StringUtils.isNoneEmpty(scmUrl)) {
254+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
250255
additionalProperties.put(CodegenConstants.SCM_URL, scmUrl);
251256
}
252257

253258
if (additionalProperties.containsKey(CodegenConstants.DEVELOPER_NAME)) {
254259
this.setDeveloperName((String) additionalProperties.get(CodegenConstants.DEVELOPER_NAME));
255-
} else {
260+
} else if(StringUtils.isNoneEmpty(developerName)) {
261+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
256262
additionalProperties.put(CodegenConstants.DEVELOPER_NAME, developerName);
257263
}
258264

259265
if (additionalProperties.containsKey(CodegenConstants.DEVELOPER_EMAIL)) {
260266
this.setDeveloperEmail((String) additionalProperties.get(CodegenConstants.DEVELOPER_EMAIL));
261-
} else {
267+
} else if(StringUtils.isNoneEmpty(developerEmail)) {
268+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
262269
additionalProperties.put(CodegenConstants.DEVELOPER_EMAIL, developerEmail);
263270
}
264271

265272
if (additionalProperties.containsKey(CodegenConstants.DEVELOPER_ORGANIZATION)) {
266273
this.setDeveloperOrganization((String) additionalProperties.get(CodegenConstants.DEVELOPER_ORGANIZATION));
267-
} else {
274+
} else if(StringUtils.isNoneEmpty(developerOrganization)) {
275+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
268276
additionalProperties.put(CodegenConstants.DEVELOPER_ORGANIZATION, developerOrganization);
269277
}
270278

271279
if (additionalProperties.containsKey(CodegenConstants.DEVELOPER_ORGANIZATION_URL)) {
272280
this.setDeveloperOrganizationUrl((String) additionalProperties.get(CodegenConstants.DEVELOPER_ORGANIZATION_URL));
273-
} else {
281+
} else if(StringUtils.isNoneEmpty(developerOrganizationUrl)) {
282+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
274283
additionalProperties.put(CodegenConstants.DEVELOPER_ORGANIZATION_URL, developerOrganizationUrl);
275284
}
276285

277286
if (additionalProperties.containsKey(CodegenConstants.LICENSE_NAME)) {
278287
this.setLicenseName((String) additionalProperties.get(CodegenConstants.LICENSE_NAME));
279-
} else {
288+
} else if(StringUtils.isNoneEmpty(licenseName)) {
289+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
280290
additionalProperties.put(CodegenConstants.LICENSE_NAME, licenseName);
281291
}
282292

283293
if (additionalProperties.containsKey(CodegenConstants.LICENSE_URL)) {
284294
this.setLicenseUrl((String) additionalProperties.get(CodegenConstants.LICENSE_URL));
285-
} else {
295+
} else if(StringUtils.isNoneEmpty(licenseUrl)) {
296+
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
286297
additionalProperties.put(CodegenConstants.LICENSE_URL, licenseUrl);
287298
}
288299

0 commit comments

Comments
 (0)