Skip to content

Commit e8c739e

Browse files
authored
Read modelFileFolderPath from additionalProperties (#12536)
1 parent a28772b commit e8c739e

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ public class GoClientCodegen extends AbstractGoCodegen {
5050
protected String packageVersion = "1.0.0";
5151
protected String apiDocPath = "docs/";
5252
protected String modelDocPath = "docs/";
53+
protected String modelFileFolder = null;
5354
public static final String WITH_XML = "withXml";
5455
public static final String STRUCT_PREFIX = "structPrefix";
5556
public static final String WITH_AWSV4_SIGNATURE = "withAWSV4Signature";
5657
public static final String GENERATE_INTERFACES = "generateInterfaces";
58+
public static final String MODEL_FILE_FOLDER = "modelFileFolder";
5759
protected String goImportAlias = "openapiclient";
5860
protected boolean isGoSubmodule = false;
5961
protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup
@@ -255,6 +257,10 @@ public void processOpts() {
255257
.get(CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT).toString()));
256258
}
257259

260+
if (additionalProperties.containsKey(MODEL_FILE_FOLDER)) {
261+
modelFileFolder = additionalProperties.get(MODEL_FILE_FOLDER).toString();
262+
}
263+
258264
// add lambda for mustache templates to handle oneOf/anyOf naming
259265
// e.g. []string => ArrayOfString
260266
additionalProperties.put("lambda.type-to-name", (Mustache.Lambda) (fragment, writer) -> writer.write(typeToName(fragment.execute())));
@@ -301,9 +307,17 @@ public String apiFileFolder() {
301307
return outputFolder + File.separator;
302308
}
303309

310+
/**
311+
* Location of created model files (it can be overriden using --additional-properties in openapi-generator-cli
312+
*/
304313
@Override
305314
public String modelFileFolder() {
306-
return outputFolder + File.separator;
315+
String modelFileFolderPath = outputFolder + File.separator;
316+
317+
if(modelFileFolder != null) {
318+
modelFileFolderPath = modelFileFolderPath + modelFileFolder + File.separator;
319+
}
320+
return modelFileFolderPath;
307321
}
308322

309323
@Override

modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public void testInitialConfigValues() throws Exception {
5050

5151
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
5252
Assert.assertTrue(codegen.isHideGenerationTimestamp());
53+
Assert.assertNull(codegen.additionalProperties().get(GoClientCodegen.MODEL_FILE_FOLDER));
5354
}
5455

5556
@Test
@@ -203,6 +204,15 @@ public void testStructPrefix() throws IOException {
203204
TestUtils.assertFileContains(Paths.get(output + "/api_pet.go"), "type PetApiAddPetRequest struct");
204205
}
205206

207+
@Test
208+
public void testAdditionalPropertiesModelFileFolder() throws Exception {
209+
final GoClientCodegen codegen = new GoClientCodegen();
210+
codegen.additionalProperties().put(GoClientCodegen.MODEL_FILE_FOLDER, "model_dir");
211+
codegen.processOpts();
212+
213+
Assert.assertEquals(codegen.modelFileFolder(), "generated-code/go/model_dir/");
214+
}
215+
206216
@Test
207217
public void verifyTestFile() throws IOException {
208218
File output = Files.createTempDirectory("test").toFile();

0 commit comments

Comments
 (0)