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

to not override values if additional proeprties already present #18500

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,11 @@ void configureGeneratorProperties() {
// set OpenAPI to make these available to all methods
config.setOpenAPI(openAPI);

if (!config.additionalProperties().containsKey("generatorVersion")) {
config.additionalProperties().put("generatorVersion", ImplementationVersion.read());
}
config.additionalProperties().put("generatedDate", ZonedDateTime.now().toString());
config.additionalProperties().put("generatedYear", String.valueOf(ZonedDateTime.now().getYear()));
config.additionalProperties().put("generatorClass", config.getClass().getName());
config.additionalProperties().put("inputSpec", config.getInputSpec());
config.additionalProperties().putIfAbsent("generatorVersion", ImplementationVersion.read());
config.additionalProperties().putIfAbsent("generatedDate", ZonedDateTime.now().toString());
config.additionalProperties().putIfAbsent("generatedYear", String.valueOf(ZonedDateTime.now().getYear()));
config.additionalProperties().putIfAbsent("generatorClass", config.getClass().getName());
config.additionalProperties().putIfAbsent("inputSpec", config.getInputSpec());

if (openAPI.getExtensions() != null) {
config.vendorExtensions().putAll(openAPI.getExtensions());
Expand All @@ -322,59 +320,59 @@ private void configureOpenAPIInfo() {
return;
}
if (info.getTitle() != null) {
config.additionalProperties().put("appName", config.escapeText(info.getTitle()));
config.additionalProperties().putIfAbsent("appName", config.escapeText(info.getTitle()));
}
if (info.getVersion() != null) {
config.additionalProperties().put("appVersion", config.escapeText(info.getVersion()));
config.additionalProperties().putIfAbsent("appVersion", config.escapeText(info.getVersion()));
} else {
LOGGER.error("Missing required field info version. Default appVersion set to 1.0.0");
config.additionalProperties().put("appVersion", "1.0.0");
config.additionalProperties().putIfAbsent("appVersion", "1.0.0");
}

if (StringUtils.isEmpty(info.getDescription())) {
// set a default description if none if provided
config.additionalProperties().put("appDescription",
config.additionalProperties().putIfAbsent("appDescription",
"No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)");
config.additionalProperties().put("appDescriptionWithNewLines", config.additionalProperties().get("appDescription"));
config.additionalProperties().put("unescapedAppDescription", "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)");
config.additionalProperties().putIfAbsent("appDescriptionWithNewLines", config.additionalProperties().get("appDescription"));
config.additionalProperties().putIfAbsent("unescapedAppDescription", "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)");
} else {
config.additionalProperties().put("appDescription", config.escapeText(info.getDescription()));
config.additionalProperties().put("appDescriptionWithNewLines", config.escapeTextWhileAllowingNewLines(info.getDescription()));
config.additionalProperties().put("unescapedAppDescription", info.getDescription());
config.additionalProperties().putIfAbsent("appDescription", config.escapeText(info.getDescription()));
config.additionalProperties().putIfAbsent("appDescriptionWithNewLines", config.escapeTextWhileAllowingNewLines(info.getDescription()));
config.additionalProperties().putIfAbsent("unescapedAppDescription", info.getDescription());
}

if (info.getContact() != null) {
Contact contact = info.getContact();
if (contact.getEmail() != null) {
config.additionalProperties().put("infoEmail", config.escapeText(contact.getEmail()));
config.additionalProperties().putIfAbsent("infoEmail", config.escapeText(contact.getEmail()));
}
if (contact.getName() != null) {
config.additionalProperties().put("infoName", config.escapeText(contact.getName()));
config.additionalProperties().putIfAbsent("infoName", config.escapeText(contact.getName()));
}
if (contact.getUrl() != null) {
config.additionalProperties().put("infoUrl", config.escapeText(contact.getUrl()));
config.additionalProperties().putIfAbsent("infoUrl", config.escapeText(contact.getUrl()));
}
}

if (info.getLicense() != null) {
License license = info.getLicense();
if (license.getName() != null) {
config.additionalProperties().put("licenseInfo", config.escapeText(license.getName()));
config.additionalProperties().putIfAbsent("licenseInfo", config.escapeText(license.getName()));
}
if (license.getUrl() != null) {
config.additionalProperties().put("licenseUrl", config.escapeText(license.getUrl()));
config.additionalProperties().putIfAbsent("licenseUrl", config.escapeText(license.getUrl()));
}
}

if (info.getVersion() != null) {
config.additionalProperties().put("version", config.escapeText(info.getVersion()));
config.additionalProperties().putIfAbsent("version", config.escapeText(info.getVersion()));
} else {
LOGGER.error("Missing required field info version. Default version set to 1.0.0");
config.additionalProperties().put("version", "1.0.0");
config.additionalProperties().putIfAbsent("version", "1.0.0");
}

if (info.getTermsOfService() != null) {
config.additionalProperties().put("termsOfService", config.escapeText(info.getTermsOfService()));
config.additionalProperties().putIfAbsent("termsOfService", config.escapeText(info.getTermsOfService()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void testGenerateIndexAsciidocMarkupContent() throws Exception {
markupFileGenerated = true;
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
// check on some basic asciidoc markup content
Assert.assertEquals("", markupContent);
Assert.assertTrue(markupContent.contains("= ping test"),
"expected = header in: " + markupContent.substring(0, 50));
Assert.assertTrue(markupContent.contains(":toc: "),
Expand Down