Skip to content

Commit

Permalink
Added all models to postProcessOperations (#6194)
Browse files Browse the repository at this point in the history
* Added all models to postProcessOperations

* Added new postProcessOperationsWithModels
  • Loading branch information
ToreJohansson authored and wing328 committed Aug 2, 2017
1 parent 1e18702 commit 34e5838
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package io.swagger.codegen;

import io.swagger.models.Model;
import io.swagger.models.Operation;
import io.swagger.models.Swagger;
import io.swagger.models.auth.SecuritySchemeDefinition;
import io.swagger.models.properties.Property;

import java.util.List;
import java.util.Map;
import java.util.Set;

import com.samskivert.mustache.Mustache.Compiler;

import io.swagger.models.Model;
import io.swagger.models.Operation;
import io.swagger.models.Swagger;
import io.swagger.models.auth.SecuritySchemeDefinition;
import io.swagger.models.properties.Property;

public interface CodegenConfig {
CodegenType getTag();

Expand Down Expand Up @@ -153,6 +153,8 @@ public interface CodegenConfig {

Map<String, Object> postProcessOperations(Map<String, Object> objs);

Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels);

Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs);

void postProcessModelProperty(CodegenModel model, CodegenProperty property);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
package io.swagger.codegen;

import javax.annotation.Nullable;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.samskivert.mustache.Mustache.Compiler;
Expand Down Expand Up @@ -48,30 +73,6 @@
import io.swagger.models.properties.StringProperty;
import io.swagger.models.properties.UUIDProperty;
import io.swagger.util.Json;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DefaultCodegen {
protected static final Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
Expand Down Expand Up @@ -344,6 +345,12 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
return objs;
}

// override with any special post-processing
@SuppressWarnings("static-method")
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
return objs;
}

// override with any special post-processing
@SuppressWarnings("static-method")
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,54 @@
package io.swagger.codegen;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;

import io.swagger.codegen.ignore.CodegenIgnoreProcessor;
import io.swagger.codegen.utils.ImplementationVersion;
import io.swagger.codegen.languages.AbstractJavaCodegen;
import io.swagger.models.*;
import io.swagger.codegen.utils.ImplementationVersion;
import io.swagger.models.ComposedModel;
import io.swagger.models.Contact;
import io.swagger.models.Info;
import io.swagger.models.License;
import io.swagger.models.Model;
import io.swagger.models.Operation;
import io.swagger.models.Path;
import io.swagger.models.RefModel;
import io.swagger.models.SecurityRequirement;
import io.swagger.models.Swagger;
import io.swagger.models.Tag;
import io.swagger.models.auth.OAuth2Definition;
import io.swagger.models.auth.SecuritySchemeDefinition;
import io.swagger.models.parameters.Parameter;
import io.swagger.util.Json;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.*;

import org.apache.commons.lang3.StringUtils;

public class DefaultGenerator extends AbstractGenerator implements Generator {
protected final Logger LOGGER = LoggerFactory.getLogger(DefaultGenerator.class);
Expand Down Expand Up @@ -382,7 +411,7 @@ private Model getParent(Model model) {

}

private void generateApis(List<File> files, List<Object> allOperations) {
private void generateApis(List<File> files, List<Object> allOperations, List<Object> allModels) {
if (!generateApis) {
return;
}
Expand Down Expand Up @@ -410,7 +439,7 @@ public int compare(CodegenOperation one, CodegenOperation another) {
return ObjectUtils.compare(one.operationId, another.operationId);
}
});
Map<String, Object> operation = processOperations(config, tag, ops);
Map<String, Object> operation = processOperations(config, tag, ops, allModels);

operation.put("basePath", basePath);
operation.put("basePathWithoutHost", basePathWithoutHost);
Expand Down Expand Up @@ -698,7 +727,7 @@ public List<File> generate() {
generateModels(files, allModels);
// apis
List<Object> allOperations = new ArrayList<Object>();
generateApis(files, allOperations);
generateApis(files, allOperations, allModels);

// supporting files
Map<String, Object> bundle = buildSupportFileBundle(allOperations, allModels);
Expand Down Expand Up @@ -895,7 +924,7 @@ private static String generateParameterId(Parameter parameter) {
}


private Map<String, Object> processOperations(CodegenConfig config, String tag, List<CodegenOperation> ops) {
private Map<String, Object> processOperations(CodegenConfig config, String tag, List<CodegenOperation> ops, List<Object> allModels) {
Map<String, Object> operations = new HashMap<String, Object>();
Map<String, Object> objs = new HashMap<String, Object>();
objs.put("classname", config.toApiName(tag));
Expand Down Expand Up @@ -943,6 +972,7 @@ private Map<String, Object> processOperations(CodegenConfig config, String tag,
operations.put("hasImport", true);
}
config.postProcessOperations(operations);
config.postProcessOperationsWithModels(operations, allModels);
if (objs.size() > 0) {
List<CodegenOperation> os = (List<CodegenOperation>) objs.get("operation");

Expand Down

0 comments on commit 34e5838

Please sign in to comment.