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

Enhanced some error message and checks related to "No content to map … #860

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ private Map<String, JsonNode> 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<Map.Entry<String, JsonNode>> fields = tree.fields();
while(fields.hasNext()) {
Expand Down