forked from loafle/openapi-generator-original
Read modelFileFolderPath from additionalProperties (#12536)
This commit is contained in:
parent
a28772b08f
commit
e8c739e771
@ -50,10 +50,12 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
protected String packageVersion = "1.0.0";
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
protected String modelFileFolder = null;
|
||||
public static final String WITH_XML = "withXml";
|
||||
public static final String STRUCT_PREFIX = "structPrefix";
|
||||
public static final String WITH_AWSV4_SIGNATURE = "withAWSV4Signature";
|
||||
public static final String GENERATE_INTERFACES = "generateInterfaces";
|
||||
public static final String MODEL_FILE_FOLDER = "modelFileFolder";
|
||||
protected String goImportAlias = "openapiclient";
|
||||
protected boolean isGoSubmodule = false;
|
||||
protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup
|
||||
@ -255,6 +257,10 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
.get(CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(MODEL_FILE_FOLDER)) {
|
||||
modelFileFolder = additionalProperties.get(MODEL_FILE_FOLDER).toString();
|
||||
}
|
||||
|
||||
// add lambda for mustache templates to handle oneOf/anyOf naming
|
||||
// e.g. []string => ArrayOfString
|
||||
additionalProperties.put("lambda.type-to-name", (Mustache.Lambda) (fragment, writer) -> writer.write(typeToName(fragment.execute())));
|
||||
@ -301,9 +307,17 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
return outputFolder + File.separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Location of created model files (it can be overriden using --additional-properties in openapi-generator-cli
|
||||
*/
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator;
|
||||
String modelFileFolderPath = outputFolder + File.separator;
|
||||
|
||||
if(modelFileFolder != null) {
|
||||
modelFileFolderPath = modelFileFolderPath + modelFileFolder + File.separator;
|
||||
}
|
||||
return modelFileFolderPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,6 +50,7 @@ public class GoClientCodegenTest {
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||
Assert.assertTrue(codegen.isHideGenerationTimestamp());
|
||||
Assert.assertNull(codegen.additionalProperties().get(GoClientCodegen.MODEL_FILE_FOLDER));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -203,6 +204,15 @@ public class GoClientCodegenTest {
|
||||
TestUtils.assertFileContains(Paths.get(output + "/api_pet.go"), "type PetApiAddPetRequest struct");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdditionalPropertiesModelFileFolder() throws Exception {
|
||||
final GoClientCodegen codegen = new GoClientCodegen();
|
||||
codegen.additionalProperties().put(GoClientCodegen.MODEL_FILE_FOLDER, "model_dir");
|
||||
codegen.processOpts();
|
||||
|
||||
Assert.assertEquals(codegen.modelFileFolder(), "generated-code/go/model_dir/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyTestFile() throws IOException {
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
|
Loading…
x
Reference in New Issue
Block a user