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 packageVersion = "1.0.0";
|
||||||
protected String apiDocPath = "docs/";
|
protected String apiDocPath = "docs/";
|
||||||
protected String modelDocPath = "docs/";
|
protected String modelDocPath = "docs/";
|
||||||
|
protected String modelFileFolder = null;
|
||||||
public static final String WITH_XML = "withXml";
|
public static final String WITH_XML = "withXml";
|
||||||
public static final String STRUCT_PREFIX = "structPrefix";
|
public static final String STRUCT_PREFIX = "structPrefix";
|
||||||
public static final String WITH_AWSV4_SIGNATURE = "withAWSV4Signature";
|
public static final String WITH_AWSV4_SIGNATURE = "withAWSV4Signature";
|
||||||
public static final String GENERATE_INTERFACES = "generateInterfaces";
|
public static final String GENERATE_INTERFACES = "generateInterfaces";
|
||||||
|
public static final String MODEL_FILE_FOLDER = "modelFileFolder";
|
||||||
protected String goImportAlias = "openapiclient";
|
protected String goImportAlias = "openapiclient";
|
||||||
protected boolean isGoSubmodule = false;
|
protected boolean isGoSubmodule = false;
|
||||||
protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup
|
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()));
|
.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
|
// add lambda for mustache templates to handle oneOf/anyOf naming
|
||||||
// e.g. []string => ArrayOfString
|
// e.g. []string => ArrayOfString
|
||||||
additionalProperties.put("lambda.type-to-name", (Mustache.Lambda) (fragment, writer) -> writer.write(typeToName(fragment.execute())));
|
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;
|
return outputFolder + File.separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Location of created model files (it can be overriden using --additional-properties in openapi-generator-cli
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String modelFileFolder() {
|
public String modelFileFolder() {
|
||||||
return outputFolder + File.separator;
|
String modelFileFolderPath = outputFolder + File.separator;
|
||||||
|
|
||||||
|
if(modelFileFolder != null) {
|
||||||
|
modelFileFolderPath = modelFileFolderPath + modelFileFolder + File.separator;
|
||||||
|
}
|
||||||
|
return modelFileFolderPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,6 +50,7 @@ public class GoClientCodegenTest {
|
|||||||
|
|
||||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||||
Assert.assertTrue(codegen.isHideGenerationTimestamp());
|
Assert.assertTrue(codegen.isHideGenerationTimestamp());
|
||||||
|
Assert.assertNull(codegen.additionalProperties().get(GoClientCodegen.MODEL_FILE_FOLDER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -203,6 +204,15 @@ public class GoClientCodegenTest {
|
|||||||
TestUtils.assertFileContains(Paths.get(output + "/api_pet.go"), "type PetApiAddPetRequest struct");
|
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
|
@Test
|
||||||
public void verifyTestFile() throws IOException {
|
public void verifyTestFile() throws IOException {
|
||||||
File output = Files.createTempDirectory("test").toFile();
|
File output = Files.createTempDirectory("test").toFile();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user