diff --git a/src/main/java/com/github/kongchen/swagger/docgen/mavenplugin/ApiDocumentMojo.java b/src/main/java/com/github/kongchen/swagger/docgen/mavenplugin/ApiDocumentMojo.java index 82872f054..ad4014ea9 100755 --- a/src/main/java/com/github/kongchen/swagger/docgen/mavenplugin/ApiDocumentMojo.java +++ b/src/main/java/com/github/kongchen/swagger/docgen/mavenplugin/ApiDocumentMojo.java @@ -1,9 +1,10 @@ package com.github.kongchen.swagger.docgen.mavenplugin; -import com.github.kongchen.swagger.docgen.AbstractDocumentSource; -import com.github.kongchen.swagger.docgen.GenerateException; -import io.swagger.util.Json; +import java.io.File; +import java.lang.reflect.Method; +import java.util.List; +import org.apache.commons.lang3.StringUtils; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -15,11 +16,10 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; -import java.io.File; -import java.lang.reflect.Method; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; +import com.github.kongchen.swagger.docgen.AbstractDocumentSource; +import com.github.kongchen.swagger.docgen.GenerateException; + +import io.swagger.util.Json; /** * User: kongchen @@ -112,7 +112,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { for (ApiSource apiSource : apiSources) { validateConfiguration(apiSource); - AbstractDocumentSource documentSource = apiSource.isSpringmvc() + AbstractDocumentSource documentSource = apiSource.isSpringmvc() ? new SpringMavenDocumentSource(apiSource, getLog(), projectEncoding) : new MavenDocumentSource(apiSource, getLog(), projectEncoding); @@ -134,16 +134,17 @@ public void execute() throws MojoExecutionException, MojoFailureException { apiSource.getOutputFormats(), swaggerFileName, projectEncoding); if (apiSource.isAttachSwaggerArtifact() && apiSource.getSwaggerDirectory() != null && project != null) { - String outputFormats = apiSource.getOutputFormats(); - if (outputFormats != null) { - for (String format : outputFormats.split(",")) { - String classifier = swaggerFileName.equals("swagger") - ? getSwaggerDirectoryName(apiSource.getSwaggerDirectory()) - : swaggerFileName; - File swaggerFile = new File(apiSource.getSwaggerDirectory(), swaggerFileName + "." + format.toLowerCase()); - projectHelper.attachArtifact(project, format.toLowerCase(), classifier, swaggerFile); - } + + // Default Output Format to be json. Null Check not required. + String outputFormats = StringUtils.defaultString(apiSource.getOutputFormats(), "json"); + for (String format : outputFormats.split(",")) { + String classifier = swaggerFileName.equals("swagger") + ? getSwaggerDirectoryName(apiSource.getSwaggerDirectory()) + : swaggerFileName; + File swaggerFile = new File(apiSource.getSwaggerDirectory(), swaggerFileName + "." + format.toLowerCase()); + projectHelper.attachArtifact(project, format.toLowerCase(), classifier, swaggerFile); } + } } } catch (GenerateException e) { diff --git a/src/main/java/com/github/kongchen/swagger/docgen/mavenplugin/SecurityDefinition.java b/src/main/java/com/github/kongchen/swagger/docgen/mavenplugin/SecurityDefinition.java index d88d715be..47242d431 100644 --- a/src/main/java/com/github/kongchen/swagger/docgen/mavenplugin/SecurityDefinition.java +++ b/src/main/java/com/github/kongchen/swagger/docgen/mavenplugin/SecurityDefinition.java @@ -84,6 +84,11 @@ private Map loadSecurityDefintionsFromJsonFile() throws Genera try { InputStream jsonStream = json != null ? this.getClass().getResourceAsStream(json) : new FileInputStream(jsonPath); + + if(jsonStream == null) { + String errorMsg = String.format("Invalid Security Definition json = %s, jasonPath = %s", json, jsonPath); + throw new GenerateException(errorMsg); + } JsonNode tree = mapper.readTree(jsonStream); Iterator> fields = tree.fields(); while(fields.hasNext()) {