Allow empty contact objects
According to the spec the contact object can be empty (it doesn't have any required properties). Previously, the markup generation failed in that situation due to an empty paragraph being generated. This change fixes that.
This commit is contained in:
@@ -115,7 +115,7 @@ public class OverviewDocumentBuilder extends MarkupDocumentBuilder {
|
||||
}
|
||||
|
||||
private void buildContactInfoSection(Contact contact) {
|
||||
if(contact != null){
|
||||
if(contact != null && (isNotBlank(contact.getName()) || isNotBlank(contact.getEmail()))){
|
||||
this.markupDocBuilder.sectionTitleLevel2(CONTACT_INFORMATION);
|
||||
MarkupDocBuilder paragraph = copyMarkupDocBuilder();
|
||||
if(isNotBlank(contact.getName())){
|
||||
|
||||
@@ -549,4 +549,27 @@ public class AsciidocConverterTest {
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/response_headers").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversionWithResponseHeaders.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithEmptyContactUsingJSON() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_emptycontact.json").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/emptycontact");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/emptycontact").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversionWithEmptyContactUsingJSON.html");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
= Empty Contact
|
||||
|
||||
|
||||
[[_overview]]
|
||||
== Overview
|
||||
|
||||
=== Version information
|
||||
[%hardbreaks]
|
||||
_Version_ : 1.0
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
|
||||
9
src/test/resources/json/swagger_emptycontact.json
Normal file
9
src/test/resources/json/swagger_emptycontact.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "Empty Contact",
|
||||
"contact": {},
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {}
|
||||
}
|
||||
Reference in New Issue
Block a user