forked from loafle/openapi-generator-original
to not override values if additional proeprties already present
This commit is contained in:
parent
d45b1c8f37
commit
a6efa58341
@ -292,13 +292,11 @@ public class DefaultGenerator implements Generator {
|
|||||||
// set OpenAPI to make these available to all methods
|
// set OpenAPI to make these available to all methods
|
||||||
config.setOpenAPI(openAPI);
|
config.setOpenAPI(openAPI);
|
||||||
|
|
||||||
if (!config.additionalProperties().containsKey("generatorVersion")) {
|
config.additionalProperties().putIfAbsent("generatorVersion", ImplementationVersion.read());
|
||||||
config.additionalProperties().put("generatorVersion", ImplementationVersion.read());
|
config.additionalProperties().putIfAbsent("generatedDate", ZonedDateTime.now().toString());
|
||||||
}
|
config.additionalProperties().putIfAbsent("generatedYear", String.valueOf(ZonedDateTime.now().getYear()));
|
||||||
config.additionalProperties().put("generatedDate", ZonedDateTime.now().toString());
|
config.additionalProperties().putIfAbsent("generatorClass", config.getClass().getName());
|
||||||
config.additionalProperties().put("generatedYear", String.valueOf(ZonedDateTime.now().getYear()));
|
config.additionalProperties().putIfAbsent("inputSpec", config.getInputSpec());
|
||||||
config.additionalProperties().put("generatorClass", config.getClass().getName());
|
|
||||||
config.additionalProperties().put("inputSpec", config.getInputSpec());
|
|
||||||
|
|
||||||
if (openAPI.getExtensions() != null) {
|
if (openAPI.getExtensions() != null) {
|
||||||
config.vendorExtensions().putAll(openAPI.getExtensions());
|
config.vendorExtensions().putAll(openAPI.getExtensions());
|
||||||
@ -322,59 +320,59 @@ public class DefaultGenerator implements Generator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (info.getTitle() != null) {
|
if (info.getTitle() != null) {
|
||||||
config.additionalProperties().put("appName", config.escapeText(info.getTitle()));
|
config.additionalProperties().putIfAbsent("appName", config.escapeText(info.getTitle()));
|
||||||
}
|
}
|
||||||
if (info.getVersion() != null) {
|
if (info.getVersion() != null) {
|
||||||
config.additionalProperties().put("appVersion", config.escapeText(info.getVersion()));
|
config.additionalProperties().putIfAbsent("appVersion", config.escapeText(info.getVersion()));
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error("Missing required field info version. Default appVersion set to 1.0.0");
|
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())) {
|
if (StringUtils.isEmpty(info.getDescription())) {
|
||||||
// set a default description if none if provided
|
// 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)");
|
"No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)");
|
||||||
config.additionalProperties().put("appDescriptionWithNewLines", config.additionalProperties().get("appDescription"));
|
config.additionalProperties().putIfAbsent("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("unescapedAppDescription", "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)");
|
||||||
} else {
|
} else {
|
||||||
config.additionalProperties().put("appDescription", config.escapeText(info.getDescription()));
|
config.additionalProperties().putIfAbsent("appDescription", config.escapeText(info.getDescription()));
|
||||||
config.additionalProperties().put("appDescriptionWithNewLines", config.escapeTextWhileAllowingNewLines(info.getDescription()));
|
config.additionalProperties().putIfAbsent("appDescriptionWithNewLines", config.escapeTextWhileAllowingNewLines(info.getDescription()));
|
||||||
config.additionalProperties().put("unescapedAppDescription", info.getDescription());
|
config.additionalProperties().putIfAbsent("unescapedAppDescription", info.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.getContact() != null) {
|
if (info.getContact() != null) {
|
||||||
Contact contact = info.getContact();
|
Contact contact = info.getContact();
|
||||||
if (contact.getEmail() != null) {
|
if (contact.getEmail() != null) {
|
||||||
config.additionalProperties().put("infoEmail", config.escapeText(contact.getEmail()));
|
config.additionalProperties().putIfAbsent("infoEmail", config.escapeText(contact.getEmail()));
|
||||||
}
|
}
|
||||||
if (contact.getName() != null) {
|
if (contact.getName() != null) {
|
||||||
config.additionalProperties().put("infoName", config.escapeText(contact.getName()));
|
config.additionalProperties().putIfAbsent("infoName", config.escapeText(contact.getName()));
|
||||||
}
|
}
|
||||||
if (contact.getUrl() != null) {
|
if (contact.getUrl() != null) {
|
||||||
config.additionalProperties().put("infoUrl", config.escapeText(contact.getUrl()));
|
config.additionalProperties().putIfAbsent("infoUrl", config.escapeText(contact.getUrl()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.getLicense() != null) {
|
if (info.getLicense() != null) {
|
||||||
License license = info.getLicense();
|
License license = info.getLicense();
|
||||||
if (license.getName() != null) {
|
if (license.getName() != null) {
|
||||||
config.additionalProperties().put("licenseInfo", config.escapeText(license.getName()));
|
config.additionalProperties().putIfAbsent("licenseInfo", config.escapeText(license.getName()));
|
||||||
}
|
}
|
||||||
if (license.getUrl() != null) {
|
if (license.getUrl() != null) {
|
||||||
config.additionalProperties().put("licenseUrl", config.escapeText(license.getUrl()));
|
config.additionalProperties().putIfAbsent("licenseUrl", config.escapeText(license.getUrl()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.getVersion() != null) {
|
if (info.getVersion() != null) {
|
||||||
config.additionalProperties().put("version", config.escapeText(info.getVersion()));
|
config.additionalProperties().putIfAbsent("version", config.escapeText(info.getVersion()));
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error("Missing required field info version. Default version set to 1.0.0");
|
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) {
|
if (info.getTermsOfService() != null) {
|
||||||
config.additionalProperties().put("termsOfService", config.escapeText(info.getTermsOfService()));
|
config.additionalProperties().putIfAbsent("termsOfService", config.escapeText(info.getTermsOfService()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ public class AsciidocGeneratorTest {
|
|||||||
markupFileGenerated = true;
|
markupFileGenerated = true;
|
||||||
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||||
// check on some basic asciidoc markup content
|
// check on some basic asciidoc markup content
|
||||||
|
Assert.assertEquals("", markupContent);
|
||||||
Assert.assertTrue(markupContent.contains("= ping test"),
|
Assert.assertTrue(markupContent.contains("= ping test"),
|
||||||
"expected = header in: " + markupContent.substring(0, 50));
|
"expected = header in: " + markupContent.substring(0, 50));
|
||||||
Assert.assertTrue(markupContent.contains(":toc: "),
|
Assert.assertTrue(markupContent.contains(":toc: "),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user