Generate swagger yaml for go client (#7281)

This commit is contained in:
Ben Wells 2018-01-07 03:37:40 +00:00 committed by William Cheng
parent bedd4c880e
commit 7479fc5361
6 changed files with 1557 additions and 22 deletions

View File

@ -5,12 +5,15 @@ import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.MapProperty;
import io.swagger.models.properties.Property;
import io.swagger.models.parameters.Parameter;
import io.swagger.models.Swagger;
import io.swagger.util.Yaml;
import java.util.*;
import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -362,6 +365,19 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
return postProcessModelsEnum(objs);
}
@Override
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
Swagger swagger = (Swagger)objs.get("swagger");
if(swagger != null) {
try {
objs.put("swagger-yaml", Yaml.mapper().writeValueAsString(swagger));
} catch (JsonProcessingException e) {
LOGGER.error(e.getMessage(), e);
}
}
return super.postProcessSupportingFileData(objs);
}
@Override
protected boolean needToImport(String type) {
return !defaultIncludes.contains(type)

View File

@ -87,6 +87,7 @@ public class GoClientCodegen extends AbstractGoCodegen {
modelPackage = packageName;
apiPackage = packageName;
supportingFiles.add(new SupportingFile("swagger.mustache", "api", "swagger.yaml"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));

View File

@ -5,20 +5,12 @@ import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.MapProperty;
import io.swagger.models.properties.Property;
import io.swagger.models.parameters.Parameter;
import io.swagger.models.*;
import io.swagger.util.Yaml;
import java.io.File;
import java.util.*;
import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -167,17 +159,4 @@ public class GoServerCodegen extends AbstractGoCodegen {
return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar);
}
@Override
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
Swagger swagger = (Swagger)objs.get("swagger");
if(swagger != null) {
try {
objs.put("swagger-yaml", Yaml.mapper().writeValueAsString(swagger));
} catch (JsonProcessingException e) {
LOGGER.error(e.getMessage(), e);
}
}
return super.postProcessSupportingFileData(objs);
}
}

View File

@ -0,0 +1 @@
{{{swagger-yaml}}}

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,7 @@ To see how to make this your own, look here:
[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md)
- API version: 1.0.0
- Build date: 2017-12-18T09:35:47.160Z
- Build date: 2017-12-20T21:53:07.200Z
### Running the server