Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 3.3.x
Browse files Browse the repository at this point in the history
Conflicts:
	modules/openapi-generator-online/Dockerfile
  • Loading branch information
jmini committed Aug 26, 2018
2 parents 704c1b8 + 40d8159 commit 267ffc0
Show file tree
Hide file tree
Showing 62 changed files with 1,573 additions and 610 deletions.
2 changes: 1 addition & 1 deletion .hub.online.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN mkdir -p ${TARGET_DIR}

WORKDIR ${TARGET_DIR}

COPY --from=builder ${GEN_DIR}/modules/openapi-generator-online/target/openapi-generator-*.jar ${TARGET_DIR}/openapi-generator-online.jar
COPY --from=builder ${GEN_DIR}/modules/openapi-generator-online/target/openapi-generator.jar ${TARGET_DIR}/openapi-generator-online.jar

ENV GENERATOR_HOST=http://localhost

Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ after_success:
./gradlew -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="${TRAVIS_BUILD_DIR}/sec.gpg" -PossrhUsername="${SONATYPE_USERNAME}" -PossrhPassword="${SONATYPE_PASSWORD}" uploadArchives --no-daemon;
echo "Finished ./gradlew uploadArchives";
popd;
elif ([ "$TRAVIS_BRANCH" == "4.0.x" ]) ; then
elif ([[ "$TRAVIS_BRANCH" =~ ^[0-9]+\.[0-9]+\.x$ ]]) ; then
mvn clean deploy --settings CI/settings.xml;
echo "Finished mvn clean deploy for $TRAVIS_BRANCH";
pushd .;
Expand Down
1 change: 0 additions & 1 deletion bin/utils/release_version_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ declare -a files=("CI/pom.xml.bash"
"modules/openapi-generator-maven-plugin/pom.xml"
"modules/openapi-generator-online/pom.xml"
"modules/openapi-generator/pom.xml"
"modules/openapi-generator-online/Dockerfile"
"pom.xml")

for filename in "${files[@]}"; do
Expand Down
2 changes: 1 addition & 1 deletion modules/openapi-generator-online/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM openjdk:8-jre-alpine

WORKDIR /generator

COPY target/openapi-generator-online-3.3.0-SNAPSHOT.jar /generator/openapi-generator-online.jar
COPY target/openapi-generator-online.jar /generator/openapi-generator-online.jar

ENV GENERATOR_HOST=http://localhost

Expand Down
1 change: 1 addition & 0 deletions modules/openapi-generator-online/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
</dependencies>
</dependencyManagement>
<build>
<finalName>openapi-generator-online</finalName>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class CodegenParameter {
public CodegenProperty mostInnerItems;
public Map<String, Object> vendorExtensions = new HashMap<String, Object>();
public boolean hasValidation;
public boolean isNullable;

/**
* Determines whether this parameter is mandatory. If the parameter is in "path",
Expand Down Expand Up @@ -150,6 +151,7 @@ public CodegenParameter copy() {
output.vendorExtensions = new HashMap<String, Object>(this.vendorExtensions);
}
output.hasValidation = this.hasValidation;
output.isNullable = this.isNullable;
output.isBinary = this.isBinary;
output.isByteArray = this.isByteArray;
output.isString = this.isString;
Expand Down Expand Up @@ -269,6 +271,8 @@ public boolean equals(Object o) {
return false;
if (hasValidation != that.hasValidation)
return false;
if (isNullable != that.isNullable)
return false;
if (required != that.required)
return false;
if (maximum != null ? !maximum.equals(that.maximum) : that.maximum != null)
Expand Down Expand Up @@ -344,6 +348,7 @@ public int hashCode() {
result = 31 * result + (mostInnerItems != null ? mostInnerItems.hashCode() : 0);
result = 31 * result + (vendorExtensions != null ? vendorExtensions.hashCode() : 0);
result = 31 * result + (hasValidation ? 13:31);
result = 31 * result + (isNullable ? 13:31);
result = 31 * result + (required ? 13:31);
result = 31 * result + (maximum != null ? maximum.hashCode() : 0);
result = 31 * result + (exclusiveMaximum ? 13:31);
Expand Down Expand Up @@ -409,6 +414,7 @@ public java.lang.String toString() {
", mostInnerItems=" + mostInnerItems +
", vendorExtensions=" + vendorExtensions +
", hasValidation=" + hasValidation +
", isNullable=" + isNullable +
", required=" + required +
", maximum='" + maximum + '\'' +
", exclusiveMaximum=" + exclusiveMaximum +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,11 @@ public CodegenProperty fromProperty(String name, Schema p) {
if (p.getWriteOnly() != null) {
property.isWriteOnly = p.getWriteOnly();
}
if (p.getNullable() != null) {

// use x-nullable
if (p.getExtensions() != null && p.getExtensions().get("x-nullable") != null) {
property.isNullable = Boolean.valueOf(p.getExtensions().get("x-nullable").toString());
} else if (p.getNullable() != null) { // use nullable defined in OAS3
property.isNullable = p.getNullable();
}

Expand Down Expand Up @@ -2649,6 +2653,14 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
LOGGER.warn("warning! Schema not found for parameter \"" + parameter.getName() + "\", using String");
parameterSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to missing type definition.");
}

// x-nullable extension in OAS2
if (parameter.getExtensions() != null && parameter.getExtensions().get("x-nullable") != null) {
codegenParameter.isNullable = Boolean.valueOf(parameter.getExtensions().get("x-nullable").toString());
} else if (Boolean.TRUE.equals(parameterSchema.getNullable())) { // use nullable defined in the spec
codegenParameter.isNullable = true;
}

// set default value
if (parameterSchema.getDefault() != null) {
codegenParameter.defaultValue = toDefaultValue(parameterSchema);
Expand Down Expand Up @@ -4265,6 +4277,9 @@ public List<CodegenParameter> fromRequestBodyToFormParameters(RequestBody body,
// default to csv:
codegenParameter.collectionFormat = StringUtils.isEmpty(collectionFormat) ? "csv" : collectionFormat;

// set nullable
setParameterNullable(codegenParameter, codegenProperty);

// recursively add import
while (codegenProperty != null) {
imports.add(codegenProperty.baseType);
Expand Down Expand Up @@ -4293,7 +4308,7 @@ public List<CodegenParameter> fromRequestBodyToFormParameters(RequestBody body,
public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set<String> imports) {
CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);

LOGGER.debug("Debugging fromFormProperty: " + name);
LOGGER.debug("Debugging fromFormProperty {}: {}", name, propertySchema);
CodegenProperty codegenProperty = fromProperty(name, propertySchema);

codegenParameter.isFormParam = Boolean.TRUE;
Expand All @@ -4307,7 +4322,6 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set
codegenParameter.jsonSchema = Json.pretty(propertySchema);
codegenParameter.defaultValue = codegenProperty.getDefaultValue();


if (codegenProperty.getVendorExtensions() != null && !codegenProperty.getVendorExtensions().isEmpty()) {
codegenParameter.vendorExtensions = codegenProperty.getVendorExtensions();
}
Expand Down Expand Up @@ -4366,6 +4380,8 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set

setParameterBooleanFlagWithCodegenProperty(codegenParameter, codegenProperty);
setParameterExampleValue(codegenParameter);
// set nullable
setParameterNullable(codegenParameter, codegenProperty);

//TODO collectionFormat for form parameter not yet supported
//codegenParameter.collectionFormat = getCollectionFormat(propertySchema);
Expand Down Expand Up @@ -4415,6 +4431,9 @@ public CodegenParameter fromRequestBody(RequestBody body, Map<String, Schema> sc
codegenParameter.isMapContainer = Boolean.TRUE;

setParameterBooleanFlagWithCodegenProperty(codegenParameter, codegenProperty);

// set nullable
setParameterNullable(codegenParameter, codegenProperty);
} else if (ModelUtils.isArraySchema(schema)) {
final ArraySchema arraySchema = (ArraySchema) schema;
Schema inner = arraySchema.getItems();
Expand Down Expand Up @@ -4454,6 +4473,8 @@ public CodegenParameter fromRequestBody(RequestBody body, Map<String, Schema> sc
codegenParameter.isListContainer = Boolean.TRUE;

setParameterBooleanFlagWithCodegenProperty(codegenParameter, codegenProperty);
// set nullable
setParameterNullable(codegenParameter, codegenProperty);

while (codegenProperty != null) {
imports.add(codegenProperty.baseType);
Expand Down Expand Up @@ -4516,6 +4537,8 @@ public CodegenParameter fromRequestBody(RequestBody body, Map<String, Schema> sc
}
}
setParameterBooleanFlagWithCodegenProperty(codegenParameter, codegenProperty);
// set nullable
setParameterNullable(codegenParameter, codegenProperty);
}

} else {
Expand All @@ -4539,6 +4562,8 @@ public CodegenParameter fromRequestBody(RequestBody body, Map<String, Schema> sc

}
setParameterBooleanFlagWithCodegenProperty(codegenParameter, codegenProperty);
// set nullable
setParameterNullable(codegenParameter, codegenProperty);
}

// set the parameter's example value
Expand Down Expand Up @@ -4636,4 +4661,12 @@ public List<CodegenServerVariable> fromServerVariables(Map<String, ServerVariabl
}
return codegenServerVariables;
}

private void setParameterNullable(CodegenParameter parameter, CodegenProperty property) {
if (property.getVendorExtensions() != null && property.getVendorExtensions().get("x-nullable") != null) {
parameter.isNullable = Boolean.valueOf(property.getVendorExtensions().get("x-nullable").toString());
} else {
parameter.isNullable = property.isNullable;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,13 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
}
op.vendorExtensions.put("x-codegen-pistache-consumesJson", consumeJson);
op.vendorExtensions.put("x-codegen-pistache-isParsingSupported", isParsingSupported);

// Check if any one of the operations needs a model, then at API file level, at least one model has to be included.
for(String hdr : op.imports) {
if(importMapping.containsKey(hdr)) {
continue;
}
additionalProperties.put("hasModelImport", true);
operations.put("hasModelImport", true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenParameter;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.utils.ModelUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
Expand All @@ -55,7 +59,7 @@ public class CppQt5QHttpEngineServerCodegen extends AbstractCppCodegen implement
protected Map<String, String> namespaces = new HashMap<String, String>();
protected Set<String> systemIncludes = new HashSet<String>();
protected String cppNamespace = "OpenAPI";

protected Set<String> nonFrameworkPrimitives = new HashSet<String>();
public CppQt5QHttpEngineServerCodegen() {
super();

Expand Down Expand Up @@ -135,7 +139,17 @@ public CppQt5QHttpEngineServerCodegen() {
"float",
"double")
);

nonFrameworkPrimitives.addAll(languageSpecificPrimitives);

foundationClasses.addAll(
Arrays.asList(
"QString",
"QDate",
"QDateTime",
"QByteArray")
);
languageSpecificPrimitives.addAll(foundationClasses);

supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.h"));
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.cpp"));
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder + MODEL_DIR, PREFIX + "Object.h"));
Expand Down Expand Up @@ -174,7 +188,7 @@ public CppQt5QHttpEngineServerCodegen() {
importMapping = new HashMap<String, String>();
namespaces = new HashMap<String, String>();

foundationClasses.add("QString");


systemIncludes.add("QString");
systemIncludes.add("QList");
Expand Down Expand Up @@ -434,4 +448,71 @@ public String toParamName(String name) {
public String getTypeDeclaration(String str) {
return str;
}

@Override
protected boolean needToImport(String type) {
return StringUtils.isNotBlank(type) && !defaultIncludes.contains(type)
&& !nonFrameworkPrimitives.contains(type);
}

@Override
@SuppressWarnings("unchecked")
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");

List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
for (CodegenOperation operation : operations) {
// Check all return parameter baseType if there is a necessity to include, include it if not
// already done
if (operation.returnBaseType != null && needToImport(operation.returnBaseType)) {
if(!isIncluded(operation.returnBaseType, imports)) {
imports.add(createMapping("import", operation.returnBaseType));
}
}
List<CodegenParameter> params = new ArrayList<CodegenParameter>();
if (operation.allParams != null)params.addAll(operation.allParams);

// Check all parameter baseType if there is a necessity to include, include it if not
// already done
for(CodegenParameter param : params) {
if(param.isPrimitiveType && needToImport(param.baseType)) {
if(!isIncluded(param.baseType, imports)) {
imports.add(createMapping("import", param.baseType));
}
}
}
if (operation.pathParams != null) {
// We use QString to pass path params, add it to include
if(!isIncluded("QString", imports)) {
imports.add(createMapping("import", "QString"));
}
}
}
if(isIncluded("QMap", imports)) {
// Maps uses QString as key
if(!isIncluded("QString", imports)) {
imports.add(createMapping("import", "QString"));
}
}
return objs;
}

public Map<String, String> createMapping(String key, String value) {
Map<String, String> customImport = new HashMap<String, String>();
customImport.put(key, toModelImport(value));
return customImport;
}

private boolean isIncluded(String type, List<Map<String, String>> imports) {
boolean included = false;
String inclStr = toModelImport(type);
for (Map<String, String> importItem : imports) {
if(importItem.containsValue(inclStr)) {
included = true;
break;
}
}
return included;
}
}
Loading

0 comments on commit 267ffc0

Please sign in to comment.