forked from loafle/openapi-generator-original
throw exception for invalid framework (#7901)
This commit is contained in:
parent
81e0e8dfa8
commit
b1b64cb356
@ -31,6 +31,7 @@ import java.io.File;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||||
@ -547,7 +548,6 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
|||||||
additionalProperties.put(CodegenConstants.OPTIONAL_EMIT_DEFAULT_VALUES, optionalEmitDefaultValuesFlag);
|
additionalProperties.put(CodegenConstants.OPTIONAL_EMIT_DEFAULT_VALUES, optionalEmitDefaultValuesFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (additionalProperties.containsKey(CodegenConstants.MODEL_PROPERTY_NAMING)) {
|
if (additionalProperties.containsKey(CodegenConstants.MODEL_PROPERTY_NAMING)) {
|
||||||
setModelPropertyNaming((String) additionalProperties.get(CodegenConstants.MODEL_PROPERTY_NAMING));
|
setModelPropertyNaming((String) additionalProperties.get(CodegenConstants.MODEL_PROPERTY_NAMING));
|
||||||
}
|
}
|
||||||
@ -561,13 +561,24 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
|||||||
clientPackage = "Client";
|
clientPackage = "Client";
|
||||||
|
|
||||||
String framework = (String) additionalProperties.getOrDefault(CodegenConstants.DOTNET_FRAMEWORK, defaultFramework.name);
|
String framework = (String) additionalProperties.getOrDefault(CodegenConstants.DOTNET_FRAMEWORK, defaultFramework.name);
|
||||||
|
boolean strategyMatched = false;
|
||||||
FrameworkStrategy strategy = defaultFramework;
|
FrameworkStrategy strategy = defaultFramework;
|
||||||
for (FrameworkStrategy frameworkStrategy : frameworkStrategies) {
|
for (FrameworkStrategy frameworkStrategy : frameworkStrategies) {
|
||||||
if (framework.equals(frameworkStrategy.name)) {
|
if (framework.equals(frameworkStrategy.name)) {
|
||||||
strategy = frameworkStrategy;
|
strategy = frameworkStrategy;
|
||||||
|
strategyMatched = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// throws exception if the input targetFramework is invalid
|
||||||
|
if (strategyMatched == false) {
|
||||||
|
throw new IllegalArgumentException("Invalid .NET framework version: " +
|
||||||
|
framework + ". List of supported versions: " +
|
||||||
|
frameworkStrategies.stream()
|
||||||
|
.map(p -> p.name)
|
||||||
|
.collect(Collectors.joining(", ")));
|
||||||
|
}
|
||||||
|
|
||||||
strategy.configureAdditionalProperties(additionalProperties);
|
strategy.configureAdditionalProperties(additionalProperties);
|
||||||
|
|
||||||
setTargetFrameworkNuget(strategy.getNugetFrameworkIdentifier());
|
setTargetFrameworkNuget(strategy.getNugetFrameworkIdentifier());
|
||||||
@ -710,7 +721,11 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
|||||||
|
|
||||||
public void setTargetFramework(String dotnetFramework) {
|
public void setTargetFramework(String dotnetFramework) {
|
||||||
if (!frameworks.containsKey(dotnetFramework)) {
|
if (!frameworks.containsKey(dotnetFramework)) {
|
||||||
LOGGER.warn("Invalid .NET framework version, defaulting to " + this.targetFramework);
|
throw new IllegalArgumentException("Invalid .NET framework version: " +
|
||||||
|
dotnetFramework + ". List of supported versions: " +
|
||||||
|
frameworkStrategies.stream()
|
||||||
|
.map(p -> p.name)
|
||||||
|
.collect(Collectors.joining(", ")));
|
||||||
} else {
|
} else {
|
||||||
this.targetFramework = dotnetFramework;
|
this.targetFramework = dotnetFramework;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user