mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-19 10:09:08 +00:00
Merge remote-tracking branch 'origin/3.4.x' into 4.0.x
This commit is contained in:
@@ -278,4 +278,5 @@ public class CodegenConstants {
|
||||
public static final String ENABLE_POST_PROCESS_FILE = "enablePostProcessFile";
|
||||
public static final String ENABLE_POST_PROCESS_FILE_DESC = "Enable post-processing file using environment variables.";
|
||||
|
||||
public static final String OPEN_API_SPEC_NAME = "openAPISpecName";
|
||||
}
|
||||
@@ -25,13 +25,13 @@ import java.util.Map;
|
||||
public class CodegenParameter {
|
||||
public boolean isFormParam, isQueryParam, isPathParam, isHeaderParam,
|
||||
isCookieParam, isBodyParam, hasMore, isContainer,
|
||||
secondaryParam, isCollectionFormatMulti, isPrimitiveType;
|
||||
secondaryParam, isCollectionFormatMulti, isPrimitiveType, isModel;
|
||||
public String baseName, paramName, dataType, datatypeWithEnum, dataFormat,
|
||||
collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName;
|
||||
|
||||
public String example; // example value (x-example)
|
||||
public String jsonSchema;
|
||||
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid;
|
||||
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isEmail;
|
||||
public boolean isListContainer, isMapContainer;
|
||||
public boolean isFile;
|
||||
public boolean isEnum;
|
||||
@@ -110,6 +110,7 @@ public class CodegenParameter {
|
||||
output.collectionFormat = this.collectionFormat;
|
||||
output.isCollectionFormatMulti = this.isCollectionFormatMulti;
|
||||
output.isPrimitiveType = this.isPrimitiveType;
|
||||
output.isModel = this.isModel;
|
||||
output.description = this.description;
|
||||
output.unescapedDescription = this.unescapedDescription;
|
||||
output.baseType = this.baseType;
|
||||
@@ -165,6 +166,7 @@ public class CodegenParameter {
|
||||
output.isDate = this.isDate;
|
||||
output.isDateTime = this.isDateTime;
|
||||
output.isUuid = this.isUuid;
|
||||
output.isEmail = this.isEmail;
|
||||
output.isListContainer = this.isListContainer;
|
||||
output.isMapContainer = this.isMapContainer;
|
||||
|
||||
@@ -201,6 +203,8 @@ public class CodegenParameter {
|
||||
return false;
|
||||
if (isPrimitiveType != that.isPrimitiveType)
|
||||
return false;
|
||||
if (isModel != that.isModel)
|
||||
return false;
|
||||
if (baseName != null ? !baseName.equals(that.baseName) : that.baseName != null)
|
||||
return false;
|
||||
if (paramName != null ? !paramName.equals(that.paramName) : that.paramName != null)
|
||||
@@ -253,6 +257,8 @@ public class CodegenParameter {
|
||||
return false;
|
||||
if (isUuid != that.isUuid)
|
||||
return false;
|
||||
if (isEmail != that.isEmail)
|
||||
return false;
|
||||
if (isListContainer != that.isListContainer)
|
||||
return false;
|
||||
if (isMapContainer != that.isMapContainer)
|
||||
@@ -312,6 +318,7 @@ public class CodegenParameter {
|
||||
result = 31 * result + (secondaryParam ? 13:31);
|
||||
result = 31 * result + (isCollectionFormatMulti ? 13:31);
|
||||
result = 31 * result + (isPrimitiveType ? 13:31);
|
||||
result = 31 * result + (isModel ? 13:31);
|
||||
result = 31 * result + (baseName != null ? baseName.hashCode() : 0);
|
||||
result = 31 * result + (paramName != null ? paramName.hashCode() : 0);
|
||||
result = 31 * result + (dataType != null ? dataType.hashCode() : 0);
|
||||
@@ -338,6 +345,7 @@ public class CodegenParameter {
|
||||
result = 31 * result + (isDate ? 13:31);
|
||||
result = 31 * result + (isDateTime ? 13:31);
|
||||
result = 31 * result + (isUuid ? 13:31);
|
||||
result = 31 * result + (isEmail ? 13:31);
|
||||
result = 31 * result + (isListContainer ? 13:31);
|
||||
result = 31 * result + (isMapContainer ? 13:31);
|
||||
result = 31 * result + (isFile ? 13:31);
|
||||
@@ -378,6 +386,7 @@ public class CodegenParameter {
|
||||
", secondaryParam=" + secondaryParam +
|
||||
", isCollectionFormatMulti=" + isCollectionFormatMulti +
|
||||
", isPrimitiveType=" + isPrimitiveType +
|
||||
", isModel=" + isModel +
|
||||
", baseName='" + baseName + '\'' +
|
||||
", paramName='" + paramName + '\'' +
|
||||
", dataType='" + dataType + '\'' +
|
||||
@@ -404,6 +413,7 @@ public class CodegenParameter {
|
||||
", isDate=" + isDate +
|
||||
", isDateTime=" + isDateTime +
|
||||
", isUuid=" + isUuid +
|
||||
", isEmail=" + isEmail +
|
||||
", isListContainer=" + isListContainer +
|
||||
", isMapContainer=" + isMapContainer +
|
||||
", isFile=" + isFile +
|
||||
|
||||
@@ -55,8 +55,8 @@ public class CodegenProperty implements Cloneable {
|
||||
public boolean exclusiveMaximum;
|
||||
public boolean hasMore, required, secondaryParam;
|
||||
public boolean hasMoreNonReadOnly; // for model constructor, true if next property is not readonly
|
||||
public boolean isPrimitiveType, isContainer, isNotContainer;
|
||||
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBinary, isFile, isBoolean, isDate, isDateTime, isUuid;
|
||||
public boolean isPrimitiveType, isModel, isContainer, isNotContainer;
|
||||
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBinary, isFile, isBoolean, isDate, isDateTime, isUuid, isEmail;
|
||||
public boolean isListContainer, isMapContainer;
|
||||
public boolean isEnum;
|
||||
public boolean isReadOnly;
|
||||
@@ -438,6 +438,7 @@ public class CodegenProperty implements Cloneable {
|
||||
result = prime * result + (isEnum ? 1231 : 1237);
|
||||
result = prime * result + ((isNotContainer ? 13:31));
|
||||
result = prime * result + ((isPrimitiveType ? 13:31));
|
||||
result = prime * result + ((isModel ? 13:31));
|
||||
result = prime * result + ((isReadOnly ? 13:31));
|
||||
result = prime * result + ((isWriteOnly ? 13:31));
|
||||
result = prime * result + ((isNullable ? 13:31));
|
||||
@@ -472,6 +473,7 @@ public class CodegenProperty implements Cloneable {
|
||||
result = prime * result + ((isDate ? 13:31));
|
||||
result = prime * result + ((isDateTime ? 13:31));
|
||||
result = prime * result + ((isUuid ? 13:31));
|
||||
result = prime * result + ((isEmail ? 13:31));
|
||||
result = prime * result + ((isMapContainer ? 13:31));
|
||||
result = prime * result + ((isListContainer ? 13:31));
|
||||
result = prime * result + Objects.hashCode(isInherited);
|
||||
@@ -579,6 +581,9 @@ public class CodegenProperty implements Cloneable {
|
||||
if (this.isPrimitiveType != other.isPrimitiveType) {
|
||||
return false;
|
||||
}
|
||||
if (this.isModel != other.isModel) {
|
||||
return false;
|
||||
}
|
||||
if (this.isContainer != other.isContainer) {
|
||||
return false;
|
||||
}
|
||||
@@ -649,6 +654,9 @@ public class CodegenProperty implements Cloneable {
|
||||
if (this.isUuid != other.isUuid) {
|
||||
return false;
|
||||
}
|
||||
if (this.isEmail != other.isEmail) {
|
||||
return false;
|
||||
}
|
||||
if (this.isBinary != other.isBinary) {
|
||||
return false;
|
||||
}
|
||||
@@ -759,6 +767,7 @@ public class CodegenProperty implements Cloneable {
|
||||
", secondaryParam=" + secondaryParam +
|
||||
", hasMoreNonReadOnly=" + hasMoreNonReadOnly +
|
||||
", isPrimitiveType=" + isPrimitiveType +
|
||||
", isModel=" + isModel +
|
||||
", isContainer=" + isContainer +
|
||||
", isNotContainer=" + isNotContainer +
|
||||
", isString=" + isString +
|
||||
@@ -775,6 +784,7 @@ public class CodegenProperty implements Cloneable {
|
||||
", isDate=" + isDate +
|
||||
", isDateTime=" + isDateTime +
|
||||
", isUuid=" + isUuid +
|
||||
", isEmail=" + isEmail +
|
||||
", isListContainer=" + isListContainer +
|
||||
", isMapContainer=" + isMapContainer +
|
||||
", isEnum=" + isEnum +
|
||||
|
||||
@@ -30,7 +30,7 @@ public class CodegenResponse {
|
||||
public List<Map<String, Object>> examples;
|
||||
public String dataType, baseType, containerType;
|
||||
public boolean hasHeaders;
|
||||
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBoolean, isDate, isDateTime, isUuid;
|
||||
public boolean isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBoolean, isDate, isDateTime, isUuid, isEmail;
|
||||
public boolean isDefault;
|
||||
public boolean simpleType;
|
||||
public boolean primitiveType;
|
||||
|
||||
@@ -1895,6 +1895,9 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
// keep isString to true to make it backward compatible
|
||||
property.isString = true;
|
||||
property.isUuid = true;
|
||||
} else if (ModelUtils.isEmailSchema(p)) {
|
||||
property.isString = true;
|
||||
property.isEmail = true;
|
||||
} else {
|
||||
property.isString = true;
|
||||
}
|
||||
@@ -2175,6 +2178,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
property.isPrimitiveType = true;
|
||||
} else {
|
||||
property.complexType = property.baseType;
|
||||
property.isModel = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2578,8 +2582,9 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
r.dataType = cp.dataType;
|
||||
|
||||
if (Boolean.TRUE.equals(cp.isString) && Boolean.TRUE.equals(cp.isUuid)) {
|
||||
if (Boolean.TRUE.equals(cp.isString) && Boolean.TRUE.equals(cp.isEmail)) {
|
||||
r.isEmail = true;
|
||||
} else if (Boolean.TRUE.equals(cp.isString) && Boolean.TRUE.equals(cp.isUuid)) {
|
||||
r.isUuid = true;
|
||||
} else if (Boolean.TRUE.equals(cp.isByteArray)) {
|
||||
r.isByteArray = true;
|
||||
@@ -3840,8 +3845,9 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
LOGGER.error("Codegen Property cannot be null.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(property.isUuid) && Boolean.TRUE.equals(property.isString)) {
|
||||
if (Boolean.TRUE.equals(property.isEmail) && Boolean.TRUE.equals(property.isString)) {
|
||||
parameter.isEmail = true;
|
||||
} else if (Boolean.TRUE.equals(property.isUuid) && Boolean.TRUE.equals(property.isString)) {
|
||||
parameter.isUuid = true;
|
||||
} else if (Boolean.TRUE.equals(property.isByteArray)) {
|
||||
parameter.isByteArray = true;
|
||||
@@ -4515,6 +4521,9 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
schema.setName(name);
|
||||
codegenModel = fromModel(name, schema, schemas);
|
||||
}
|
||||
if (codegenModel != null) {
|
||||
codegenParameter.isModel = true;
|
||||
}
|
||||
|
||||
if (codegenModel != null && !codegenModel.emptyVars) {
|
||||
if (StringUtils.isEmpty(bodyParameterName)) {
|
||||
|
||||
@@ -500,6 +500,7 @@ public class InlineModelResolver {
|
||||
model.setExample(example);
|
||||
model.setName(object.getName());
|
||||
model.setXml(xml);
|
||||
model.setRequired(object.getRequired());
|
||||
if (properties != null) {
|
||||
flattenProperties(properties, path);
|
||||
model.setProperties(properties);
|
||||
@@ -545,6 +546,9 @@ public class InlineModelResolver {
|
||||
|
||||
public void copyVendorExtensions(Schema source, Schema target) {
|
||||
Map<String, Object> vendorExtensions = source.getExtensions();
|
||||
if (vendorExtensions == null) {
|
||||
return;
|
||||
}
|
||||
for (String extName : vendorExtensions.keySet()) {
|
||||
target.addExtension(extName, vendorExtensions.get(extName));
|
||||
}
|
||||
|
||||
@@ -549,7 +549,6 @@ public class CodegenConfigurator implements Serializable {
|
||||
final List<AuthorizationValue> authorizationValues = AuthParser.parse(auth);
|
||||
ParseOptions options = new ParseOptions();
|
||||
options.setResolve(true);
|
||||
options.setFlatten(true);
|
||||
SwaggerParseResult result = new OpenAPIParser().readLocation(inputSpec, authorizationValues, options);
|
||||
|
||||
Set<String> validationMessages = new HashSet<>(result.getMessages());
|
||||
|
||||
@@ -27,6 +27,7 @@ import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.media.StringSchema;
|
||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
@@ -212,6 +213,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("JAVA_POST_PROCESS_FILE"))) {
|
||||
LOGGER.info("Environment variable JAVA_POST_PROCESS_FILE not defined so the Java code may not be properly formatted. To define it, try 'export JAVA_POST_PROCESS_FILE=\"/usr/local/bin/clang-format -i\"' (Linux/Mac)");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(SUPPORT_JAVA6)) {
|
||||
this.setSupportJava6(Boolean.valueOf(additionalProperties.get(SUPPORT_JAVA6).toString()));
|
||||
}
|
||||
@@ -226,7 +231,6 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
this.setBooleanGetterPrefix(additionalProperties.get(BOOLEAN_GETTER_PREFIX).toString());
|
||||
}
|
||||
additionalProperties.put(BOOLEAN_GETTER_PREFIX, booleanGetterPrefix);
|
||||
|
||||
if (additionalProperties.containsKey(USE_NULL_FOR_UNKNOWN_ENUM_VALUE)) {
|
||||
this.setUseNullForUnknownEnumValue(Boolean.valueOf(additionalProperties.get(USE_NULL_FOR_UNKNOWN_ENUM_VALUE).toString()));
|
||||
}
|
||||
@@ -1382,6 +1386,35 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessFile(File file, String fileType) {
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String javaPostProcessFile = System.getenv("JAVA_POST_PROCESS_FILE");
|
||||
if (StringUtils.isEmpty(javaPostProcessFile)) {
|
||||
return; // skip if JAVA_POST_PROCESS_FILE env variable is not defined
|
||||
}
|
||||
|
||||
// only process files with hs extension
|
||||
if ("java".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||
String command = javaPostProcessFile + " " + file.toString();
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
p.waitFor();
|
||||
int exitValue = p.exitValue();
|
||||
if (exitValue != 0) {
|
||||
LOGGER.error("Error running the command ({}). Exit value: {}", command, exitValue);
|
||||
} else {
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setParentGroupId(final String parentGroupId) {
|
||||
this.parentGroupId = parentGroupId;
|
||||
}
|
||||
|
||||
@@ -82,8 +82,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
apiTemplateFiles.put("api-header.mustache", ".h");
|
||||
apiTemplateFiles.put("api-source.mustache", ".cpp");
|
||||
apiTemplateFiles.put("api-impl-header.mustache", ".h");
|
||||
apiTemplateFiles.put("api-impl-source.mustache", ".cpp");
|
||||
apiTemplateFiles.put("main-api-server.mustache", ".cpp");
|
||||
apiTemplateFiles.put("api-impl-source.mustache", ".cpp");
|
||||
|
||||
embeddedTemplateDir = templateDir = "cpp-pistache-server";
|
||||
|
||||
@@ -97,6 +96,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
supportingFiles.add(new SupportingFile("modelbase-source.mustache", "model", modelNamePrefix + "ModelBase.cpp"));
|
||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", "model", modelNamePrefix + "Helpers.h"));
|
||||
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
|
||||
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));
|
||||
supportingFiles.add(new SupportingFile("cmake.mustache", "", "CMakeLists.txt"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
@@ -139,6 +139,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
supportingFiles.add(new SupportingFile("modelbase-source.mustache", "model", modelNamePrefix + "ModelBase.cpp"));
|
||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", "model", modelNamePrefix + "Helpers.h"));
|
||||
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
|
||||
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));
|
||||
supportingFiles.add(new SupportingFile("cmake.mustache", "", "CMakeLists.txt"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
}
|
||||
@@ -291,10 +292,6 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
int ix = result.lastIndexOf(File.separatorChar);
|
||||
result = result.substring(0, ix) + result.substring(ix, result.length() - 4) + "Impl.cpp";
|
||||
result = result.replace(apiFileFolder(), implFileFolder());
|
||||
} else if (templateName.endsWith("api-server.mustache")) {
|
||||
int ix = result.lastIndexOf(File.separatorChar);
|
||||
result = result.substring(0, ix) + result.substring(ix, result.length() - 4) + "MainServer.cpp";
|
||||
result = result.replace(apiFileFolder(), outputFolder);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -154,7 +155,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
typeMapping.put("map", "std::map");
|
||||
typeMapping.put("file", "HttpContent");
|
||||
typeMapping.put("object", "Object");
|
||||
typeMapping.put("binary", "std::string");
|
||||
typeMapping.put("binary", "utility::string_t");
|
||||
typeMapping.put("number", "double");
|
||||
typeMapping.put("UUID", "utility::string_t");
|
||||
typeMapping.put("ByteArray", "utility::string_t");
|
||||
@@ -249,6 +250,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
|
||||
if (methodResponse != null) {
|
||||
Schema response = ModelUtils.getSchemaFromResponse(methodResponse);
|
||||
response = ModelUtils.unaliasSchema(openAPI.getComponents().getSchemas(), response);
|
||||
if (response != null) {
|
||||
CodegenProperty cm = fromProperty("response", response);
|
||||
op.vendorExtensions.put("x-codegen-response", cm);
|
||||
@@ -276,6 +278,24 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
// override with any special post-processing
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
||||
for (CodegenOperation op : operationList) {
|
||||
for(String hdr : op.imports) {
|
||||
if(importMapping.containsKey(hdr)) {
|
||||
continue;
|
||||
}
|
||||
operations.put("hasModelImport", true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
protected boolean isFileSchema(CodegenProperty property) {
|
||||
return property.baseType.equals("HttpContent");
|
||||
}
|
||||
|
||||
@@ -59,8 +59,10 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ElmClientCodegen.class);
|
||||
private Set<String> customPrimitives = new HashSet<String>();
|
||||
private ElmVersion elmVersion = ElmVersion.ELM_019;
|
||||
private Boolean elmPrefixCustomTypeVariants = false;
|
||||
|
||||
private static final String ELM_VERSION = "elmVersion";
|
||||
private static final String ELM_PREFIX_CUSTOM_TYPE_VARIANTS = "elmPrefixCustomTypeVariants";
|
||||
private static final String ENCODER = "elmEncoder";
|
||||
private static final String DECODER = "elmDecoder";
|
||||
private static final String DISCRIMINATOR_NAME = "discriminatorName";
|
||||
@@ -162,13 +164,14 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportedVersions.put("0.19", "Elm 0.19");
|
||||
elmVersion.setEnum(supportedVersions);
|
||||
cliOptions.add(elmVersion);
|
||||
final CliOption elmPrefixCustomTypeVariants = CliOption.newBoolean(ELM_PREFIX_CUSTOM_TYPE_VARIANTS, "Prefix custom type variants");
|
||||
cliOptions.add(elmPrefixCustomTypeVariants);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
|
||||
if (additionalProperties.containsKey(ELM_VERSION)) {
|
||||
final String version = (String) additionalProperties.get(ELM_VERSION);
|
||||
if ("0.18".equals(version)) {
|
||||
@@ -178,6 +181,10 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(ELM_PREFIX_CUSTOM_TYPE_VARIANTS)) {
|
||||
elmPrefixCustomTypeVariants = Boolean.TRUE.equals(Boolean.valueOf(additionalProperties.get(ELM_PREFIX_CUSTOM_TYPE_VARIANTS).toString()));
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("ELM_POST_PROCESS_FILE"))) {
|
||||
if (elmVersion.equals(ElmVersion.ELM_018)) { // 0.18
|
||||
LOGGER.info("Environment variable ELM_POST_PROCESS_FILE not defined so the Elm code may not be properly formatted. To define it, try `export ELM_POST_PROCESS_FILE=\"/usr/local/bin/elm-format --elm-version={} --yes\"` (Linux/Mac)", "0.18");
|
||||
@@ -188,7 +195,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
switch (elmVersion) {
|
||||
case ELM_018:
|
||||
LOGGER.info("Elm version = 0.18");
|
||||
LOGGER.info("Elm version: 0.18");
|
||||
additionalProperties.put("isElm018", true);
|
||||
supportingFiles.add(new SupportingFile("DateOnly018.mustache", "src", "DateOnly.elm"));
|
||||
supportingFiles.add(new SupportingFile("DateTime018.mustache", "src", "DateTime.elm"));
|
||||
@@ -196,7 +203,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("Main018.mustache", "src", "Main.elm"));
|
||||
break;
|
||||
case ELM_019:
|
||||
LOGGER.info("Elm version = 0.19");
|
||||
LOGGER.info("Elm version: 0.19");
|
||||
additionalProperties.put("isElm019", true);
|
||||
supportingFiles.add(new SupportingFile("DateOnly.mustache", "src", "DateOnly.elm"));
|
||||
supportingFiles.add(new SupportingFile("DateTime.mustache", "src", "DateTime.elm"));
|
||||
@@ -590,6 +597,28 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
addEncoderAndDecoder(parameter.vendorExtensions, parameter.dataType, isPrimitiveType ? DataTypeExposure.PRIMITIVE : DataTypeExposure.EXTERNAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCodegenPropertyEnum(final CodegenProperty property) {
|
||||
super.updateCodegenPropertyEnum(property);
|
||||
if (!elmPrefixCustomTypeVariants) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Map<String, Object> allowableValues = property.allowableValues;
|
||||
if (allowableValues == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Map<String, Object>> enumVars = (ArrayList<Map<String, Object>>) allowableValues.get("enumVars");
|
||||
if (enumVars == null) {
|
||||
return;
|
||||
}
|
||||
final String prefix = toEnumName(property);
|
||||
for (Map<String, Object> enumVar : enumVars) {
|
||||
enumVar.put("name", prefix + enumVar.get("name"));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPrimitiveDataType(String dataType) {
|
||||
return languageSpecificPrimitives.contains(dataType);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
protected String apiVersion = "1.0.0";
|
||||
protected String apiPath = "src";
|
||||
protected String packageName = "openapi";
|
||||
protected String openApiSpecName = "openapi";
|
||||
|
||||
public ErlangServerCodegen() {
|
||||
super();
|
||||
@@ -47,13 +48,6 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/erlang-server";
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
* Models. You can write model files using the modelTemplateFiles map.
|
||||
* if you want to create one template for file, you can do so here.
|
||||
@@ -117,6 +111,27 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Erlang package name (convention: lowercase).")
|
||||
.defaultValue(this.packageName));
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.OPEN_API_SPEC_NAME, "Openapi Spec Name.")
|
||||
.defaultValue(this.openApiSpecName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.OPEN_API_SPEC_NAME)) {
|
||||
setOpenApiSpecName((String) additionalProperties.get(CodegenConstants.OPEN_API_SPEC_NAME));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.OPEN_API_SPEC_NAME, openApiSpecName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
@@ -135,7 +150,7 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
supportingFiles.add(new SupportingFile("server.mustache", "", toSourceFilePath("server", "erl")));
|
||||
supportingFiles.add(new SupportingFile("utils.mustache", "", toSourceFilePath("utils", "erl")));
|
||||
supportingFiles.add(new SupportingFile("auth.mustache", "", toSourceFilePath("auth", "erl")));
|
||||
supportingFiles.add(new SupportingFile("openapi.mustache", "", toPrivFilePath("openapi", "json")));
|
||||
supportingFiles.add(new SupportingFile("openapi.mustache", "", toPrivFilePath(this.openApiSpecName, "json")));
|
||||
supportingFiles.add(new SupportingFile("default_logic_handler.mustache", "", toSourceFilePath("default_logic_handler", "erl")));
|
||||
supportingFiles.add(new SupportingFile("logic_handler.mustache", "", toSourceFilePath("logic_handler", "erl")));
|
||||
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
||||
@@ -254,6 +269,10 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public void setOpenApiSpecName(String openApiSpecName) {
|
||||
this.openApiSpecName = openApiSpecName;
|
||||
}
|
||||
|
||||
protected String toHandlerName(String name) {
|
||||
return toModuleName(name) + "_handler";
|
||||
}
|
||||
|
||||
@@ -269,10 +269,13 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
apiDocTemplateFiles.remove("api_doc.mustache");
|
||||
}
|
||||
|
||||
if (!(FEIGN.equals(getLibrary()) || RESTTEMPLATE.equals(getLibrary()) || usesAnyRetrofitLibrary() || GOOGLE_API_CLIENT.equals(getLibrary()) || REST_ASSURED.equals(getLibrary()))) {
|
||||
if (!(FEIGN.equals(getLibrary()) || RESTTEMPLATE.equals(getLibrary()) || usesAnyRetrofitLibrary() || GOOGLE_API_CLIENT.equals(getLibrary()) || REST_ASSURED.equals(getLibrary()) || WEBCLIENT.equals(getLibrary()))) {
|
||||
supportingFiles.add(new SupportingFile("apiException.mustache", invokerFolder, "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache", invokerFolder, "Configuration.java"));
|
||||
supportingFiles.add(new SupportingFile("Pair.mustache", invokerFolder, "Pair.java"));
|
||||
}
|
||||
|
||||
if (!(FEIGN.equals(getLibrary()) || RESTTEMPLATE.equals(getLibrary()) || usesAnyRetrofitLibrary() || GOOGLE_API_CLIENT.equals(getLibrary()) || REST_ASSURED.equals(getLibrary()))) {
|
||||
supportingFiles.add(new SupportingFile("auth/Authentication.mustache", authFolder, "Authentication.java"));
|
||||
}
|
||||
|
||||
|
||||
@@ -17,27 +17,17 @@
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenProperty;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.DefaultCodegen;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.openapitools.codegen.utils.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@@ -45,6 +35,9 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public static final String PACKAGE_NAME = "packageName";
|
||||
public static final String PACKAGE_VERSION = "packageVersion";
|
||||
|
||||
public static final String HYPER_LIBRARY = "hyper";
|
||||
public static final String REQWEST_LIBRARY = "reqwest";
|
||||
|
||||
protected String packageName = "openapi";
|
||||
protected String packageVersion = "1.0.0";
|
||||
protected String apiDocPath = "docs/";
|
||||
@@ -68,7 +61,6 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
super();
|
||||
outputFolder = "generated-code/rust";
|
||||
modelTemplateFiles.put("model.mustache", ".rs");
|
||||
apiTemplateFiles.put("api.mustache", ".rs");
|
||||
|
||||
modelDocTemplateFiles.put("model_doc.mustache", ".md");
|
||||
apiDocTemplateFiles.put("api_doc.mustache", ".md");
|
||||
@@ -141,6 +133,15 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC)
|
||||
.defaultValue(Boolean.TRUE.toString()));
|
||||
|
||||
supportedLibraries.put(HYPER_LIBRARY, "HTTP client: Hyper.");
|
||||
supportedLibraries.put(REQWEST_LIBRARY, "HTTP client: Reqwest.");
|
||||
|
||||
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use.");
|
||||
libraryOption.setEnum(supportedLibraries);
|
||||
// set hyper as the default
|
||||
libraryOption.setDefault(HYPER_LIBRARY);
|
||||
cliOptions.add(libraryOption);
|
||||
setLibrary(HYPER_LIBRARY);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -165,21 +166,34 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
|
||||
if ( HYPER_LIBRARY.equals(getLibrary())){
|
||||
additionalProperties.put(HYPER_LIBRARY, "true");
|
||||
} else if (REQWEST_LIBRARY.equals(getLibrary())) {
|
||||
additionalProperties.put(REQWEST_LIBRARY, "true");
|
||||
} else {
|
||||
LOGGER.error("Unknown library option (-l/--library): {}", getLibrary());
|
||||
}
|
||||
|
||||
apiTemplateFiles.put(getLibrary() + "/api.mustache", ".rs");
|
||||
|
||||
modelPackage = packageName;
|
||||
apiPackage = packageName;
|
||||
|
||||
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"));
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", apiFolder, "configuration.rs"));
|
||||
supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("api_mod.mustache", apiFolder, "mod.rs"));
|
||||
supportingFiles.add(new SupportingFile("client.mustache", apiFolder, "client.rs"));
|
||||
supportingFiles.add(new SupportingFile("request.rs", apiFolder, "request.rs"));
|
||||
supportingFiles.add(new SupportingFile("model_mod.mustache", modelFolder, "mod.rs"));
|
||||
supportingFiles.add(new SupportingFile("lib.rs", "src", "lib.rs"));
|
||||
supportingFiles.add(new SupportingFile("lib.mustache", "src", "lib.rs"));
|
||||
supportingFiles.add(new SupportingFile("Cargo.mustache", "", "Cargo.toml"));
|
||||
|
||||
if (HYPER_LIBRARY.equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("request.rs", apiFolder, "request.rs"));
|
||||
}
|
||||
|
||||
supportingFiles.add(new SupportingFile(getLibrary() + "/configuration.mustache", apiFolder, "configuration.rs"));
|
||||
supportingFiles.add(new SupportingFile(getLibrary() + "/client.mustache", apiFolder, "client.rs"));
|
||||
supportingFiles.add(new SupportingFile(getLibrary() + "/api_mod.mustache", apiFolder, "mod.rs"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -209,7 +223,7 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return name;
|
||||
|
||||
// snake_case, e.g. PetId => pet_id
|
||||
name = org.openapitools.codegen.utils.StringUtils.underscore(name);
|
||||
name = StringUtils.underscore(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name))
|
||||
@@ -231,16 +245,17 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public String toModelName(String name) {
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(toModelFilename(name));
|
||||
return StringUtils.camelize(toModelFilename(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
if (!StringUtils.isEmpty(modelNamePrefix)) {
|
||||
|
||||
if (!Strings.isNullOrEmpty(modelNamePrefix)) {
|
||||
name = modelNamePrefix + "_" + name;
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(modelNameSuffix)) {
|
||||
if (!Strings.isNullOrEmpty(modelNameSuffix)) {
|
||||
name = name + "_" + modelNameSuffix;
|
||||
}
|
||||
|
||||
@@ -258,7 +273,7 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
name = "model_" + name; // e.g. 200Response => Model200Response (after camelize)
|
||||
}
|
||||
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(name);
|
||||
return StringUtils.underscore(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -267,7 +282,7 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// e.g. PetApi.rs => pet_api.rs
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(name) + "_api";
|
||||
return StringUtils.underscore(name) + "_api";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -340,11 +355,11 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(sanitizedOperationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore("call_" + operationId));
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + StringUtils.underscore("call_" + operationId));
|
||||
sanitizedOperationId = "call_" + sanitizedOperationId;
|
||||
}
|
||||
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(sanitizedOperationId);
|
||||
return StringUtils.underscore(sanitizedOperationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -353,9 +368,15 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
|
||||
@SuppressWarnings("unchecked")
|
||||
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||
Set<String> headerKeys = new HashSet<>();
|
||||
for (CodegenOperation operation : operations) {
|
||||
// http method verb conversion (e.g. PUT => Put)
|
||||
operation.httpMethod = org.openapitools.codegen.utils.StringUtils.camelize(operation.httpMethod.toLowerCase(Locale.ROOT));
|
||||
// http method verb conversion, depending on client library (e.g. Hyper: PUT => Put, Reqwest: PUT => put)
|
||||
if (HYPER_LIBRARY.equals(getLibrary())) {
|
||||
operation.httpMethod = StringUtils.camelize(operation.httpMethod.toLowerCase(Locale.ROOT));
|
||||
} else if (REQWEST_LIBRARY.equals(getLibrary())) {
|
||||
operation.httpMethod = operation.httpMethod.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
// update return type to conform to rust standard
|
||||
/*
|
||||
if (operation.returnType != null) {
|
||||
@@ -407,6 +428,9 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}*/
|
||||
}
|
||||
|
||||
additionalProperties.put("headerKeys", headerKeys);
|
||||
additionalProperties.putIfAbsent("authHeaderKey", "api-key");
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
|
||||
import org.openapitools.codegen.languages.features.OptionalFeatures;
|
||||
import org.openapitools.codegen.languages.features.PerformBeanValidationFeatures;
|
||||
import org.openapitools.codegen.utils.URLPathUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -51,7 +52,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class SpringCodegen extends AbstractJavaCodegen
|
||||
implements BeanValidationFeatures, OptionalFeatures {
|
||||
implements BeanValidationFeatures, PerformBeanValidationFeatures,
|
||||
OptionalFeatures {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SpringCodegen.class);
|
||||
|
||||
public static final String TITLE = "title";
|
||||
@@ -74,6 +76,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
public static final String IMPLICIT_HEADERS = "implicitHeaders";
|
||||
public static final String OPENAPI_DOCKET_CONFIG = "swaggerDocketConfig";
|
||||
public static final String API_FIRST = "apiFirst";
|
||||
public static final String HATEOAS = "hateoas";
|
||||
|
||||
protected String title = "OpenAPI Spring";
|
||||
protected String configPackage = "org.openapitools.configuration";
|
||||
@@ -88,11 +91,13 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
protected String responseWrapper = "";
|
||||
protected boolean useTags = false;
|
||||
protected boolean useBeanValidation = true;
|
||||
protected boolean performBeanValidation = false;
|
||||
protected boolean implicitHeaders = false;
|
||||
protected boolean openapiDocketConfig = false;
|
||||
protected boolean apiFirst = false;
|
||||
protected boolean useOptional = false;
|
||||
protected boolean virtualService = false;
|
||||
protected boolean hateoas = false;
|
||||
|
||||
public SpringCodegen() {
|
||||
super();
|
||||
@@ -120,10 +125,12 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
cliOptions.add(CliOption.newBoolean(VIRTUAL_SERVICE, "Generates the virtual service. For more details refer - https://github.com/elan-venture/virtualan/wiki"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_TAGS, "use tags for creating interface and controller classnames", useTags));
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations", useBeanValidation));
|
||||
cliOptions.add(CliOption.newBoolean(PERFORM_BEANVALIDATION, "Use Bean Validation Impl. to perform BeanValidation", performBeanValidation));
|
||||
cliOptions.add(CliOption.newBoolean(IMPLICIT_HEADERS, "Use of @ApiImplicitParams for headers.", implicitHeaders));
|
||||
cliOptions.add(CliOption.newBoolean(OPENAPI_DOCKET_CONFIG, "Generate Spring OpenAPI Docket configuration class.", openapiDocketConfig));
|
||||
cliOptions.add(CliOption.newBoolean(API_FIRST, "Generate the API from the OAI spec at server compile time (API first approach)", apiFirst));
|
||||
cliOptions.add(CliOption.newBoolean(USE_OPTIONAL,"Use Optional container for optional parameters", useOptional));
|
||||
cliOptions.add(CliOption.newBoolean(HATEOAS, "Use Spring HATEOAS library to allow adding HATEOAS links", hateoas));
|
||||
|
||||
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application using the SpringFox integration.");
|
||||
supportedLibraries.put(SPRING_MVC_LIBRARY, "Spring-MVC Server application using the SpringFox integration.");
|
||||
@@ -245,6 +252,11 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
}
|
||||
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
|
||||
|
||||
if (additionalProperties.containsKey(PERFORM_BEANVALIDATION)) {
|
||||
this.setPerformBeanValidation(convertPropertyToBoolean(PERFORM_BEANVALIDATION));
|
||||
}
|
||||
writePropertyBack(PERFORM_BEANVALIDATION, performBeanValidation);
|
||||
|
||||
if (additionalProperties.containsKey(USE_OPTIONAL)) {
|
||||
this.setUseOptional(convertPropertyToBoolean(USE_OPTIONAL));
|
||||
}
|
||||
@@ -260,6 +272,10 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
if (additionalProperties.containsKey(API_FIRST)) {
|
||||
this.setApiFirst(Boolean.valueOf(additionalProperties.get(API_FIRST).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(HATEOAS)) {
|
||||
this.setHateoas(Boolean.valueOf(additionalProperties.get(HATEOAS).toString()));
|
||||
}
|
||||
|
||||
typeMapping.put("file", "Resource");
|
||||
importMapping.put("Resource", "org.springframework.core.io.Resource");
|
||||
@@ -700,6 +716,10 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
public void setApiFirst(boolean apiFirst) {
|
||||
this.apiFirst = apiFirst;
|
||||
}
|
||||
|
||||
public void setHateoas(boolean hateoas) {
|
||||
this.hateoas = hateoas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
@@ -750,6 +770,10 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
public void setPerformBeanValidation(boolean performBeanValidation) {
|
||||
this.performBeanValidation = performBeanValidation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseOptional(boolean useOptional) {
|
||||
this.useOptional = useOptional;
|
||||
|
||||
@@ -69,7 +69,7 @@ public class StaticHtmlGenerator extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
additionalProperties.put("appName", "OpenAPI Sample");
|
||||
additionalProperties.put("appDescription", "A sample OpenAPI server");
|
||||
additionalProperties.put("infoUrl", "https//openapi-generator.tech");
|
||||
additionalProperties.put("infoUrl", "https://openapi-generator.tech");
|
||||
additionalProperties.put("infoEmail", "team@openapitools.org");
|
||||
additionalProperties.put("licenseInfo", "All rights reserved");
|
||||
additionalProperties.put("licenseUrl", "http://apache.org/licenses/LICENSE-2.0.html");
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.openapitools.codegen.utils;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.PathItem;
|
||||
import io.swagger.v3.oas.models.callbacks.Callback;
|
||||
import io.swagger.v3.oas.models.headers.Header;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.BinarySchema;
|
||||
@@ -167,40 +168,56 @@ public class ModelUtils {
|
||||
|
||||
if (paths != null) {
|
||||
for (PathItem path : paths.values()) {
|
||||
List<Operation> allOperations = path.readOperations();
|
||||
if (allOperations != null) {
|
||||
for (Operation operation : allOperations) {
|
||||
//Params:
|
||||
if (operation.getParameters() != null) {
|
||||
for (Parameter p : operation.getParameters()) {
|
||||
Parameter parameter = getReferencedParameter(openAPI, p);
|
||||
if (parameter.getSchema() != null) {
|
||||
visitSchema(openAPI, parameter.getSchema(), null, visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
visitPathItem(path, openAPI, visitor, visitedSchemas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//RequestBody:
|
||||
RequestBody requestBody = getReferencedRequestBody(openAPI, operation.getRequestBody());
|
||||
if (requestBody != null && requestBody.getContent() != null) {
|
||||
for (Entry<String, MediaType> e : requestBody.getContent().entrySet()) {
|
||||
private static void visitPathItem(PathItem pathItem, OpenAPI openAPI, OpenAPISchemaVisitor visitor, List<String> visitedSchemas) {
|
||||
List<Operation> allOperations = pathItem.readOperations();
|
||||
if (allOperations != null) {
|
||||
for (Operation operation : allOperations) {
|
||||
//Params:
|
||||
if (operation.getParameters() != null) {
|
||||
for (Parameter p : operation.getParameters()) {
|
||||
Parameter parameter = getReferencedParameter(openAPI, p);
|
||||
if (parameter.getSchema() != null) {
|
||||
visitSchema(openAPI, parameter.getSchema(), null, visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//RequestBody:
|
||||
RequestBody requestBody = getReferencedRequestBody(openAPI, operation.getRequestBody());
|
||||
if (requestBody != null && requestBody.getContent() != null) {
|
||||
for (Entry<String, MediaType> e : requestBody.getContent().entrySet()) {
|
||||
if (e.getValue().getSchema() != null) {
|
||||
visitSchema(openAPI, e.getValue().getSchema(), e.getKey(), visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Responses:
|
||||
if (operation.getResponses() != null) {
|
||||
for (ApiResponse r : operation.getResponses().values()) {
|
||||
ApiResponse apiResponse = getReferencedApiResponse(openAPI, r);
|
||||
if (apiResponse != null && apiResponse.getContent() != null) {
|
||||
for (Entry<String, MediaType> e : apiResponse.getContent().entrySet()) {
|
||||
if (e.getValue().getSchema() != null) {
|
||||
visitSchema(openAPI, e.getValue().getSchema(), e.getKey(), visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Responses:
|
||||
if (operation.getResponses() != null) {
|
||||
for (ApiResponse r : operation.getResponses().values()) {
|
||||
ApiResponse apiResponse = getReferencedApiResponse(openAPI, r);
|
||||
if (apiResponse != null && apiResponse.getContent() != null) {
|
||||
for (Entry<String, MediaType> e : apiResponse.getContent().entrySet()) {
|
||||
if (e.getValue().getSchema() != null) {
|
||||
visitSchema(openAPI, e.getValue().getSchema(), e.getKey(), visitedSchemas, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
//Callbacks:
|
||||
if (operation.getCallbacks() != null) {
|
||||
for (Callback c : operation.getCallbacks().values()) {
|
||||
Callback callback = getReferencedCallback(openAPI, c);
|
||||
if (callback != null) {
|
||||
for (PathItem p : callback.values()) {
|
||||
visitPathItem(p, openAPI, visitor, visitedSchemas);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -603,6 +620,35 @@ public class ModelUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a Callback contains a reference to an other Callback with '$ref', returns the referenced Callback if it is found or the actual Callback in the other cases.
|
||||
*
|
||||
* @param openAPI specification being checked
|
||||
* @param callback potentially containing a '$ref'
|
||||
* @return callback without '$ref'
|
||||
*/
|
||||
public static Callback getReferencedCallback(OpenAPI openAPI, Callback callback) {
|
||||
if (callback != null && StringUtils.isNotEmpty(callback.get$ref())) {
|
||||
String name = getSimpleRef(callback.get$ref());
|
||||
Callback referencedCallback = getCallback(openAPI, name);
|
||||
if (referencedCallback != null) {
|
||||
return referencedCallback;
|
||||
}
|
||||
}
|
||||
return callback;
|
||||
}
|
||||
|
||||
public static Callback getCallback(OpenAPI openAPI, String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (openAPI != null && openAPI.getComponents() != null && openAPI.getComponents().getCallbacks() != null) {
|
||||
return openAPI.getComponents().getCallbacks().get(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first defined Schema for a RequestBody
|
||||
*
|
||||
|
||||
@@ -168,7 +168,7 @@ public class URLPathUtils {
|
||||
*/
|
||||
public static String getHost(OpenAPI openAPI) {
|
||||
if (openAPI.getServers() != null && openAPI.getServers().size() > 0) {
|
||||
return sanitizeUrl(openAPI.getServers().get(0).getUrl());
|
||||
return sanitizeUrl(getServerURL(openAPI.getServers().get(0)).toString());
|
||||
}
|
||||
return LOCAL_HOST;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user