forked from loafle/openapi-generator-original
removed null fields
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.util.Yaml;
|
||||
import io.swagger.util.DeserializationModule;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -56,8 +60,8 @@ public class SwaggerYamlGenerator extends DefaultCodegen implements CodegenConfi
|
||||
@Override
|
||||
public void processSwagger(Swagger swagger) {
|
||||
try {
|
||||
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()
|
||||
.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true));
|
||||
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory().configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true));
|
||||
configureMapper(mapper);
|
||||
String swaggerString = mapper.writeValueAsString(swagger);
|
||||
String outputFile = outputFolder + File.separator + this.outputFile;
|
||||
FileUtils.writeStringToFile(new File(outputFile), swaggerString);
|
||||
@@ -79,4 +83,12 @@ public class SwaggerYamlGenerator extends DefaultCodegen implements CodegenConfi
|
||||
return input;
|
||||
}
|
||||
|
||||
private void configureMapper(ObjectMapper mapper) {
|
||||
Module deserializerModule = new DeserializationModule(true, true);
|
||||
mapper.registerModule(deserializerModule);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user