mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-18 05:39:21 +00:00
[elm] Add flag to prefix custom type variants (#1288)
This commit is contained in:
committed by
William Cheng
parent
ed8433a849
commit
1b115bb4f7
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user