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:
Horst Gutmann
2016-08-04 10:00:33 +02:00
parent 2367d86eb7
commit 4850673b96
7 changed files with 51 additions and 1 deletions

View File

@@ -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())){

View File

@@ -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");
}
}

View File

@@ -0,0 +1,12 @@
= Empty Contact
[[_overview]]
== Overview
=== Version information
[%hardbreaks]
_Version_ : 1.0

View File

@@ -0,0 +1,2 @@

View File

@@ -0,0 +1,2 @@

View File

@@ -0,0 +1,9 @@
{
"swagger": "2.0",
"info": {
"title": "Empty Contact",
"contact": {},
"version": "1.0"
},
"paths": {}
}