Skip to content

Commit e319763

Browse files
committed
feat(golang): support for wrapped and xml name
1 parent 3f24026 commit e319763

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,9 @@ public ModelsMap postProcessModels(ModelsMap objs) {
800800

801801
if (withXml) {
802802
goDataTag += " xml:" + "\"" + cp.baseName;
803+
if (cp.isXmlWrapped) {
804+
goDataTag += ">" + ("".equals(cp.xmlName) ? cp.baseName : cp.xmlName);
805+
}
803806
if (cp.isXmlAttribute) {
804807
goDataTag += ",attr";
805808
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,4 +396,26 @@ public void testAdditionalPropertiesWithoutGoMod() throws Exception {
396396
Path goSumFile = Paths.get(output + "/go.sum");
397397
TestUtils.assertFileNotExists(goSumFile);
398398
}
399+
400+
@Test
401+
public void testXmlOptionsBeingUsed() throws IOException {
402+
Map<String, Object> properties = new HashMap<>();
403+
properties.put(GoClientCodegen.STRUCT_PREFIX, true);
404+
properties.put(GoClientCodegen.WITH_XML, true);
405+
406+
File output = Files.createTempDirectory("test").toFile();
407+
output.deleteOnExit();
408+
409+
final CodegenConfigurator configurator = new CodegenConfigurator()
410+
.setGeneratorName("go")
411+
.setAdditionalProperties(properties)
412+
.setInputSpec("src/test/resources/3_0/petstore.yaml")
413+
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
414+
415+
DefaultGenerator generator = new DefaultGenerator();
416+
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
417+
files.forEach(File::deleteOnExit);
418+
419+
TestUtils.assertFileContains(Paths.get(output + "/model_pet.go"), "tags>tag");
420+
}
399421
}

0 commit comments

Comments
 (0)