Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Jul 11, 2017
2 parents 74b0c04 + 42b77a3 commit 0416b03
Show file tree
Hide file tree
Showing 138 changed files with 10,632 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,4 @@ samples/client/petstore/typescript-node/npm/npm-debug.log

# aspnetcore
samples/server/petstore/aspnetcore/.vs/
effective.pom
34 changes: 34 additions & 0 deletions bin/java-petstore-resttemplate-withxml.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

SCRIPT="$0"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi

executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"

if [ ! -f "$executable" ]
then
mvn clean package
fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l java -c bin/java-petstore-resttemplate.json -o samples/client/petstore/java/resttemplate-withXml -DhideGenerationTimestamp=true,withXml=true"

echo "Removing files and folders under samples/client/petstore/java/resttemplate/src/main"
rm -rf samples/client/petstore/java/resttemplate-withXml/src/main
find samples/client/petstore/java/resttemplate-withXml -maxdepth 1 -type f ! -name "README.md" -exec rm {} +
java $JAVA_OPTS -jar $executable $ags
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ public class CodeGenMojo extends AbstractMojo {
@Parameter(name = "generateApiDocumentation", required = false)
private Boolean generateApiDocumentation = true;

/**
* Generate the api documentation
*/
@Parameter(name = "withXml", required = false)
private Boolean withXml = false;

/**
* Skip the execution.
*/
Expand Down Expand Up @@ -384,6 +390,7 @@ public void execute() throws MojoExecutionException {
System.setProperty("modelDocs", generateModelDocumentation.toString());
System.setProperty("apiTests", generateApiTests.toString());
System.setProperty("apiDocs", generateApiDocumentation.toString());
System.setProperty("withXml", withXml.toString());

if (configOptions != null) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CodegenModel {
public List<CodegenModel> interfaceModels;
public List<CodegenModel> children;

public String name, classname, title, description, classVarName, modelJson, dataType;
public String name, classname, title, description, classVarName, modelJson, dataType, xmlPrefix, xmlNamespace, xmlName;
public String classFilename; // store the class file name, mainly used for import
public String unescapedDescription;
public String discriminator;
Expand Down Expand Up @@ -92,6 +92,12 @@ public boolean equals(Object o) {
return false;
if (dataType != null ? !dataType.equals(that.dataType) : that.dataType != null)
return false;
if (xmlPrefix != null ? !xmlPrefix.equals(that.xmlPrefix) : that.xmlPrefix != null)
return false;
if (xmlNamespace != null ? !xmlNamespace.equals(that.xmlNamespace) : that.xmlNamespace != null)
return false;
if (xmlName != null ? !xmlName.equals(that.xmlName) : that.xmlName != null)
return false;
if (classFilename != null ? !classFilename.equals(that.classFilename) : that.classFilename != null)
return false;
if (unescapedDescription != null ? !unescapedDescription.equals(that.unescapedDescription) : that.unescapedDescription != null)
Expand Down Expand Up @@ -152,6 +158,9 @@ public int hashCode() {
result = 31 * result + (classVarName != null ? classVarName.hashCode() : 0);
result = 31 * result + (modelJson != null ? modelJson.hashCode() : 0);
result = 31 * result + (dataType != null ? dataType.hashCode() : 0);
result = 31 * result + (xmlPrefix != null ? xmlPrefix.hashCode() : 0);
result = 31 * result + (xmlNamespace != null ? xmlNamespace.hashCode() : 0);
result = 31 * result + (xmlName != null ? xmlName.hashCode() : 0);
result = 31 * result + (classFilename != null ? classFilename.hashCode() : 0);
result = 31 * result + (unescapedDescription != null ? unescapedDescription.hashCode() : 0);
result = 31 * result + (discriminator != null ? discriminator.hashCode() : 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public class CodegenProperty implements Cloneable {
public Integer maxItems;
public Integer minItems;

// XML
public boolean isXmlAttribute = false;
public String xmlPrefix;
public String xmlName;
public String xmlNamespace;


@Override
public String toString() {
Expand Down Expand Up @@ -125,6 +131,10 @@ public int hashCode()
result = prime * result + Objects.hashCode(enumName);
result = prime * result + ((maxItems == null) ? 0 : maxItems.hashCode());
result = prime * result + ((minItems == null) ? 0 : minItems.hashCode());
result = prime * result + ((isXmlAttribute ? 13:31));
result = prime * result + ((xmlPrefix == null) ? 0 : xmlPrefix.hashCode());
result = prime * result + ((xmlName == null) ? 0 : xmlName.hashCode());
result = prime * result + ((xmlNamespace == null) ? 0 : xmlNamespace.hashCode());
return result;
}

Expand Down Expand Up @@ -300,6 +310,18 @@ public boolean equals(Object obj) {
if (this.minItems != other.minItems && (this.minItems == null || !this.minItems.equals(other.minItems))) {
return false;
}
if (!Objects.equals(this.isXmlAttribute, other.isXmlAttribute)) {
return false;
}
if (!Objects.equals(this.xmlPrefix, other.xmlPrefix)) {
return false;
}
if (!Objects.equals(this.xmlName, other.xmlName)) {
return false;
}
if (!Objects.equals(this.xmlNamespace, other.xmlNamespace)) {
return false;
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

public class DefaultCodegen {
protected static final Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);

protected String inputSpec;
protected String outputFolder = "";
protected Set<String> defaultIncludes = new HashSet<String>();
Expand Down Expand Up @@ -228,7 +228,7 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {

/**
* post process enum defined in model's properties
*
*
* @param objs Map of models
* @return maps of models with better enum support
*/
Expand Down Expand Up @@ -275,7 +275,7 @@ public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {

/**
* Returns the common prefix of variables for enum naming
*
*
* @param vars List of variable names
* @return the common prefix for naming
*/
Expand All @@ -290,10 +290,10 @@ public String findCommonPrefixOfVars(List<Object> vars) {
return "";
}
}

/**
* Return the enum default value in the language specified format
*
*
* @param value enum variable name
* @param datatype data type
* @return the default value for the enum
Expand All @@ -305,7 +305,7 @@ public String toEnumDefaultValue(String value, String datatype) {
/**
* Return the enum value in the language specified format
* e.g. status becomes "status"
*
*
* @param value enum variable name
* @param datatype data type
* @return the sanitized value for enum
Expand All @@ -317,10 +317,10 @@ public String toEnumValue(String value, String datatype) {
return "\"" + escapeText(value) + "\"";
}
}

/**
* Return the sanitized variable name for enum
*
*
* @param value enum variable name
* @param datatype data type
* @return the sanitized variable name for enum
Expand Down Expand Up @@ -369,7 +369,7 @@ public void preprocessSwagger(Swagger swagger) {
@SuppressWarnings("unused")
public void processSwagger(Swagger swagger) {
}

// override with any special handling of the JMustache compiler
@SuppressWarnings("unused")
public Compiler processCompiler(Compiler compiler) {
Expand Down Expand Up @@ -414,7 +414,7 @@ public String escapeUnsafeCharacters(String input) {
}

/**
* Escape single and/or double quote to avoid code injection
* Escape single and/or double quote to avoid code injection
* @param input String to be cleaned up
* @return string with quotation mark removed or escaped
*/
Expand Down Expand Up @@ -491,7 +491,7 @@ public Map<String, String> apiDocTemplateFiles() {
public Map<String, String> modelDocTemplateFiles() {
return modelDocTemplateFiles;
}

public Map<String, String> reservedWordsMappings() {
return reservedWordsMappings;
}
Expand Down Expand Up @@ -621,8 +621,8 @@ public String toApiFilename(String name) {
}

/**
* Return the file name of the Api Documentation
*
* Return the file name of the Api Documentation
*
* @param name the file name of the Api
* @return the file name of the Api
*/
Expand Down Expand Up @@ -672,14 +672,14 @@ public String toModelTestFilename(String name) {

/**
* Return the capitalized file name of the model documentation
*
*
* @param name the model name
* @return the file name of the model
*/
public String toModelDocFilename(String name) {
return initialCaps(name);
}

/**
* Return the operation ID (method name)
*
Expand Down Expand Up @@ -844,9 +844,9 @@ public DefaultCodegen() {
importMapping.put("LocalDate", "org.joda.time.*");
importMapping.put("LocalTime", "org.joda.time.*");

// we've used the .swagger-codegen-ignore approach as
// we've used the .swagger-codegen-ignore approach as
// suppportingFiles can be cleared by code generator that extends
// the default codegen, leaving the commented code below for
// the default codegen, leaving the commented code below for
// future reference
//supportingFiles.add(new GlobalSupportingFile("LICENSE", "LICENSE"));

Expand Down Expand Up @@ -1000,7 +1000,7 @@ public String toInstantiationType(Property p) {
}

/**
* Return the example value of the parameter.
* Return the example value of the parameter.
*
* @param p Swagger property object
*/
Expand Down Expand Up @@ -1292,7 +1292,14 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
m.vendorExtensions = model.getVendorExtensions();

if (model instanceof ModelImpl) {
m.discriminator = ((ModelImpl) model).getDiscriminator();
ModelImpl modelImpl = (ModelImpl) model;
m.discriminator = modelImpl.getDiscriminator();

if (modelImpl.getXml() != null) {
m.xmlPrefix = modelImpl.getXml().getPrefix();
m.xmlNamespace = modelImpl.getXml().getNamespace();
m.xmlName = modelImpl.getXml().getName();
}
}

if (model instanceof ArrayModel) {
Expand All @@ -1316,8 +1323,14 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
int modelImplCnt = 0; // only one inline object allowed in a ComposedModel
for (Model innerModel: ((ComposedModel)model).getAllOf()) {
if (innerModel instanceof ModelImpl) {
ModelImpl modelImpl = (ModelImpl) innerModel;
if (m.discriminator == null) {
m.discriminator = ((ModelImpl) innerModel).getDiscriminator();
m.discriminator = modelImpl.getDiscriminator();
}
if (modelImpl.getXml() != null) {
m.xmlPrefix = modelImpl.getXml().getPrefix();
m.xmlNamespace = modelImpl.getXml().getNamespace();
m.xmlName = modelImpl.getXml().getName();
}
if (modelImplCnt++ > 1) {
LOGGER.warn("More than one inline schema specified in allOf:. Only the first one is recognized. All others are ignored.");
Expand Down Expand Up @@ -1517,6 +1530,14 @@ public CodegenProperty fromProperty(String name, Property p) {
if (p.getReadOnly() != null) {
property.isReadOnly = p.getReadOnly();
}
if (p.getXml() != null) {
if (p.getXml().getAttribute() != null) {
property.isXmlAttribute = p.getXml().getAttribute();
}
property.xmlPrefix = p.getXml().getPrefix();
property.xmlName = p.getXml().getName();
property.xmlNamespace = p.getXml().getNamespace();
}
property.vendorExtensions = p.getVendorExtensions();

String type = getSwaggerType(p);
Expand Down Expand Up @@ -3026,7 +3047,7 @@ private void addVars(CodegenModel m, List<CodegenProperty> vars, Map<String, Pro
final int totalCount = propertyList.size();
for (int i = 0; i < totalCount; i++) {
Map.Entry<String, Property> entry = propertyList.get(i);

final String key = entry.getKey();
final Property prop = entry.getValue();

Expand Down Expand Up @@ -3247,7 +3268,7 @@ public Map<String, String> supportedLibraries() {
/**
* Set library template (sub-template).
*
* @param library Library template
* @param library Library template
*/
public void setLibrary(String library) {
if (library != null && !supportedLibraries.containsKey(library))
Expand All @@ -3267,7 +3288,7 @@ public String getLibrary() {
/**
* Set Git user ID.
*
* @param gitUserId Git user ID
* @param gitUserId Git user ID
*/
public void setGitUserId(String gitUserId) {
this.gitUserId = gitUserId;
Expand All @@ -3285,7 +3306,7 @@ public String getGitUserId() {
/**
* Set Git repo ID.
*
* @param gitRepoId Git repo ID
* @param gitRepoId Git repo ID
*/
public void setGitRepoId(String gitRepoId) {
this.gitRepoId = gitRepoId;
Expand Down Expand Up @@ -3328,7 +3349,7 @@ public void setHttpUserAgent(String httpUserAgent) {
}

/**
* HTTP user agent
* HTTP user agent
*
* @return HTTP user agent
*/
Expand Down Expand Up @@ -3509,7 +3530,7 @@ public void setParameterBooleanFlagWithCodegenProperty(CodegenParameter paramete

/**
* Update codegen property's enum by adding "enumVars" (with name and value)
*
*
* @param var list of CodegenProperty
*/
public void updateCodegenPropertyEnum(CodegenProperty var) {
Expand Down Expand Up @@ -3588,7 +3609,7 @@ public String addRegularExpressionDelimiter(String pattern) {
* reads propertyKey from additionalProperties, converts it to a boolean and
* writes it back to additionalProperties to be usable as a boolean in
* mustache files.
*
*
* @param propertyKey
* @return property value as boolean
*/
Expand Down Expand Up @@ -3631,7 +3652,7 @@ public boolean convertPropertyToBoolean(String propertyKey) {

return booleanValue;
}

public void writePropertyBack(String propertyKey, boolean value) {
additionalProperties.put(propertyKey, value);
}
Expand Down
Loading

0 comments on commit 0416b03

Please sign in to comment.