Skip to content

Commit ba9d813

Browse files
committed
Add getters for simplicity
1 parent 5a28ee2 commit ba9d813

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,8 @@ public void execute() throws MojoExecutionException {
585585
configurator = new CodegenConfigurator();
586586
} else {
587587
// retrieve mandatory fields from the configurationFile if not defined in the pom.xml
588-
this.generatorName = fromConfigurator(configurator, "generatorName", String.class, generatorName);
589-
this.inputSpec = fromConfigurator(configurator, "inputSpec", String.class, inputSpec);
588+
this.generatorName = fromConfigurator(configurator.getGeneratorName(), generatorName);
589+
this.inputSpec = fromConfigurator(configurator.getInputSpec(), inputSpec);
590590
}
591591

592592
if (StringUtils.isBlank(inputSpec) && StringUtils.isBlank(inputSpecRootDirectory)) {
@@ -1051,27 +1051,16 @@ public void execute() throws MojoExecutionException {
10511051
}
10521052

10531053
/**
1054-
* Access private fields of the CodegenConfigurator class.
1054+
* Use the configurator value is not defined in the pom.xml
10551055
*
1056-
* @param configurator the CodegenConfigurator
1057-
* @param fieldName name of the field
1058-
* @param clazz type of the field
1059-
* @param defaultValue default if configuration.fieldName is null
1060-
* @return the value of configuration.fieldName if defaultValue is null
1056+
* @param defaultValue default value taking precedence
10611057
*/
1062-
private <T> T fromConfigurator(CodegenConfigurator configurator, String fieldName, Class<T> clazz, T defaultValue) {
1058+
private <T> T fromConfigurator(T value, T defaultValue) {
10631059
if (defaultValue != null) {
10641060
// keep backward compatibilty, the value in the pom.xml has precedence over the value in the config file.
10651061
return defaultValue;
10661062
}
1067-
try {
1068-
Field field = CodegenConfigurator.class.getDeclaredField(fieldName);
1069-
field.setAccessible(true);
1070-
T value = (T)field.get(configurator);
1071-
return value == null? defaultValue : value;
1072-
} catch (Exception e) {
1073-
throw new RuntimeException("Failed to read " + fieldName + " from configuration file.", e);
1074-
}
1063+
return value;
10751064
}
10761065

10771066
/**

modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfigurator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,4 +811,12 @@ public ClientOptInput toClientOptInput() {
811811

812812
return input.openAPI((OpenAPI) context.getSpecDocument());
813813
}
814+
815+
public String getGeneratorName() {
816+
return generatorName;
817+
}
818+
819+
public String getInputSpec() {
820+
return inputSpec;
821+
}
814822
}

0 commit comments

Comments
 (0)