Skip to content

Commit ccd166c

Browse files
authored
Merge pull request #138 from RikkiGibson/XmlTests
Fix unwrapped XML lists issue and add tests
2 parents 51d6b1b + d69fd96 commit ccd166c

27 files changed

Lines changed: 1824 additions & 36 deletions

.gulp/gulpfile.iced

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require './common.iced'
22

33
# ==============================================================================
4-
# tasks required for this build
4+
# tasks required for this build
55
Tasks "dotnet" # dotnet functions
66
Tasks "regeneration"
77
Tasks "publishing"
@@ -19,13 +19,14 @@ Import
1919
task 'init', "" ,(done)->
2020
Fail "YOU MUST HAVE NODEJS VERSION GREATER THAN 7.10.0" if semver.lt( process.versions.node , "7.10.0" )
2121
done()
22-
22+
2323
# Run language-specific tests:
2424
task 'test', "", [], (done) ->
2525
await execute "dotnet test test/autorest.java.tests/autorest.java.tests.csproj", defer code, stderr, stdout
2626
await execute "mvn test -pl test/vanilla", defer code, stderr, stdout
2727
await execute "mvn test -pl test/azure", defer code, stderr, stdout
2828
await execute "mvn test -pl test/azurefluent", defer code, stderr, stdout
29+
await execute "mvn test -pl test/xml", defer code, stderr, stdout
2930
done();
3031

3132
# CI job
@@ -48,4 +49,4 @@ task 'testci', "more", [], (done) ->
4849
echo stderr
4950
echo stdout
5051
throw "Potentially unnoticed regression (see diff above)! Run `npm run regenerate`, then review and commit the changes." if stdout.length + stderr.length > 0
51-
done()
52+
done()

.gulp/regeneration.iced

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################
2-
# LEGACY
2+
# LEGACY
33
# Instead: have bunch of configuration files sitting in a well-known spot, discover them, feed them to AutoRest, done.
44

55
rimraf = require "rimraf"
@@ -9,13 +9,13 @@ regenExpected = (opts,done) ->
99
instances = keys.length
1010

1111
outputDir = opts.outputDir
12-
12+
1313
for kkey in keys
1414
optsMappingsValue = opts.mappings[kkey]
1515
key = kkey.trim().toLowerCase()
1616

1717
namespace = key.replace(/\/|\./, '')
18-
18+
1919
args = [
2020
"--java",
2121
"--output-folder=#{outputDir}",
@@ -142,13 +142,35 @@ task 'regenerate-generateclientinterfaces', '', (done) ->
142142
},done
143143
return null
144144

145+
task 'regenerate-xml', '', (done) ->
146+
outputDir = 'test/xml'
147+
148+
namespace = 'xml'
149+
150+
args = [
151+
"--java",
152+
"--output-folder=#{outputDir}",
153+
"--license-header=MICROSOFT_MIT_NO_VERSION",
154+
"--java.namespace=#{['Fixtures', namespace].join('.')}",
155+
"--input-file=test/swagger/xml-service.json",
156+
"--enable-xml=true"
157+
]
158+
159+
baseFolderPath = "#{outputDir}/src/main/java/fixtures/#{namespace}"
160+
rimraf.sync baseFolderPath
161+
162+
autorest args, done
163+
return null
164+
145165
regenerateTasks = [
146166
'regenerate-java',
147167
'regenerate-javaazure',
148168
'regenerate-javaazurefluent',
149169
'regenerate-nonnull',
150170
'regenerate-clienttypeprefix',
151-
'regenerate-generateclientinterfaces'
171+
'regenerate-generateclientinterfaces',
172+
'regenerate-xml'
152173
]
174+
153175
task 'regenerate', "regenerate expected code for tests", regenerateTasks, (done) ->
154176
done();

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,6 @@
201201
<module>test/nonnull</module>
202202
<module>test/clienttypeprefix</module>
203203
<module>test/generateclientinterfaces</module>
204+
<module>test/xml</module>
204205
</modules>
205206
</project>

src/JavaCodeGenerator.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ private static ServiceModel ParseModel(AutoRestCompositeType autoRestCompositeTy
16361636
modelImports.Add("com.fasterxml.jackson.annotation.JsonProperty");
16371637
}
16381638

1639-
if (compositeTypeProperties.Any(p => p.ModelType is AutoRestSequenceType))
1639+
if (compositeTypeProperties.Any(p => p.XmlIsWrapped))
16401640
{
16411641
modelImports.Add("com.fasterxml.jackson.annotation.JsonCreator");
16421642
}
@@ -2451,7 +2451,7 @@ public static JavaFile GetModelJavaFile(ServiceModel model, JavaSettings setting
24512451
foreach (ServiceModelProperty property in model.Properties)
24522452
{
24532453
string xmlWrapperClassName = propertyXmlWrapperClassName(property);
2454-
if (settings.ShouldGenerateXmlSerialization && property.WireType is ListType)
2454+
if (settings.ShouldGenerateXmlSerialization && property.IsXmlWrapper)
24552455
{
24562456
classBlock.PrivateStaticFinalClass(xmlWrapperClassName, innerClass =>
24572457
{
@@ -2481,12 +2481,16 @@ public static JavaFile GetModelJavaFile(ServiceModel model, JavaSettings setting
24812481
string localName = settings.ShouldGenerateXmlSerialization ? property.XmlName : property.SerializedName;
24822482
classBlock.Annotation($"JacksonXmlProperty(localName = \"{localName}\", isAttribute = true)");
24832483
}
2484+
else if (settings.ShouldGenerateXmlSerialization && property.WireType is ListType && !property.IsXmlWrapper)
2485+
{
2486+
classBlock.Annotation($"JsonProperty(\"{property.XmlListElementName}\")");
2487+
}
24842488
else if (!string.IsNullOrEmpty(property.AnnotationArguments))
24852489
{
24862490
classBlock.Annotation($"JsonProperty({property.AnnotationArguments})");
24872491
}
24882492

2489-
if (settings.ShouldGenerateXmlSerialization && property.WireType is ListType)
2493+
if (settings.ShouldGenerateXmlSerialization && property.IsXmlWrapper)
24902494
{
24912495
classBlock.PrivateMemberVariable($"{xmlWrapperClassName} {property.Name}");
24922496
}
@@ -2529,7 +2533,7 @@ public static JavaFile GetModelJavaFile(ServiceModel model, JavaSettings setting
25292533
string expression = $"this.{property.Name}";
25302534
if (sourceTypeName == targetTypeName)
25312535
{
2532-
if (settings.ShouldGenerateXmlSerialization && propertyType is ListType)
2536+
if (settings.ShouldGenerateXmlSerialization && property.IsXmlWrapper)
25332537
{
25342538
methodBlock.Return($"this.{property.Name}.items");
25352539
}
@@ -2635,7 +2639,7 @@ public static JavaFile GetModelJavaFile(ServiceModel model, JavaSettings setting
26352639
}
26362640
else
26372641
{
2638-
if (settings.ShouldGenerateXmlSerialization && propertyType is ListType)
2642+
if (settings.ShouldGenerateXmlSerialization && property.IsXmlWrapper)
26392643
{
26402644
methodBlock.Line($"this.{property.Name} = new {propertyXmlWrapperClassName(property)}({property.Name});");
26412645
}

test/clienttypeprefix/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,6 @@
131131

132132
<plugin>
133133
<artifactId>maven-surefire-plugin</artifactId>
134-
<configuration>
135-
<properties>
136-
<property>
137-
<name>listener</name>
138-
<value>fixtures.azurereport.CoverageReporter</value>
139-
</property>
140-
</properties>
141-
</configuration>
142134
</plugin>
143135
</plugins>
144136
</build>

test/generateclientinterfaces/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,6 @@
131131

132132
<plugin>
133133
<artifactId>maven-surefire-plugin</artifactId>
134-
<configuration>
135-
<properties>
136-
<property>
137-
<name>listener</name>
138-
<value>fixtures.azurereport.CoverageReporter</value>
139-
</property>
140-
</properties>
141-
</configuration>
142134
</plugin>
143135
</plugins>
144136
</build>

test/nonnull/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,6 @@
131131

132132
<plugin>
133133
<artifactId>maven-surefire-plugin</artifactId>
134-
<configuration>
135-
<properties>
136-
<property>
137-
<name>listener</name>
138-
<value>fixtures.azurereport.CoverageReporter</value>
139-
</property>
140-
</properties>
141-
</configuration>
142134
</plugin>
143135
</plugins>
144136
</build>

0 commit comments

Comments
 (0)