Skip to content

Commit

Permalink
Merge pull request #138 from RikkiGibson/XmlTests
Browse files Browse the repository at this point in the history
Fix unwrapped XML lists issue and add tests
  • Loading branch information
RikkiGibson authored Feb 13, 2018
2 parents 51d6b1b + d69fd96 commit ccd166c
Show file tree
Hide file tree
Showing 27 changed files with 1,824 additions and 36 deletions.
7 changes: 4 additions & 3 deletions .gulp/gulpfile.iced
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require './common.iced'

# ==============================================================================
# tasks required for this build
# tasks required for this build
Tasks "dotnet" # dotnet functions
Tasks "regeneration"
Tasks "publishing"
Expand All @@ -19,13 +19,14 @@ Import
task 'init', "" ,(done)->
Fail "YOU MUST HAVE NODEJS VERSION GREATER THAN 7.10.0" if semver.lt( process.versions.node , "7.10.0" )
done()

# Run language-specific tests:
task 'test', "", [], (done) ->
await execute "dotnet test test/autorest.java.tests/autorest.java.tests.csproj", defer code, stderr, stdout
await execute "mvn test -pl test/vanilla", defer code, stderr, stdout
await execute "mvn test -pl test/azure", defer code, stderr, stdout
await execute "mvn test -pl test/azurefluent", defer code, stderr, stdout
await execute "mvn test -pl test/xml", defer code, stderr, stdout
done();

# CI job
Expand All @@ -48,4 +49,4 @@ task 'testci', "more", [], (done) ->
echo stderr
echo stdout
throw "Potentially unnoticed regression (see diff above)! Run `npm run regenerate`, then review and commit the changes." if stdout.length + stderr.length > 0
done()
done()
30 changes: 26 additions & 4 deletions .gulp/regeneration.iced
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################
# LEGACY
# LEGACY
# Instead: have bunch of configuration files sitting in a well-known spot, discover them, feed them to AutoRest, done.

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

outputDir = opts.outputDir

for kkey in keys
optsMappingsValue = opts.mappings[kkey]
key = kkey.trim().toLowerCase()

namespace = key.replace(/\/|\./, '')

args = [
"--java",
"--output-folder=#{outputDir}",
Expand Down Expand Up @@ -142,13 +142,35 @@ task 'regenerate-generateclientinterfaces', '', (done) ->
},done
return null

task 'regenerate-xml', '', (done) ->
outputDir = 'test/xml'

namespace = 'xml'

args = [
"--java",
"--output-folder=#{outputDir}",
"--license-header=MICROSOFT_MIT_NO_VERSION",
"--java.namespace=#{['Fixtures', namespace].join('.')}",
"--input-file=test/swagger/xml-service.json",
"--enable-xml=true"
]

baseFolderPath = "#{outputDir}/src/main/java/fixtures/#{namespace}"
rimraf.sync baseFolderPath

autorest args, done
return null

regenerateTasks = [
'regenerate-java',
'regenerate-javaazure',
'regenerate-javaazurefluent',
'regenerate-nonnull',
'regenerate-clienttypeprefix',
'regenerate-generateclientinterfaces'
'regenerate-generateclientinterfaces',
'regenerate-xml'
]

task 'regenerate', "regenerate expected code for tests", regenerateTasks, (done) ->
done();
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,6 @@
<module>test/nonnull</module>
<module>test/clienttypeprefix</module>
<module>test/generateclientinterfaces</module>
<module>test/xml</module>
</modules>
</project>
14 changes: 9 additions & 5 deletions src/JavaCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ private static ServiceModel ParseModel(AutoRestCompositeType autoRestCompositeTy
modelImports.Add("com.fasterxml.jackson.annotation.JsonProperty");
}

if (compositeTypeProperties.Any(p => p.ModelType is AutoRestSequenceType))
if (compositeTypeProperties.Any(p => p.XmlIsWrapped))
{
modelImports.Add("com.fasterxml.jackson.annotation.JsonCreator");
}
Expand Down Expand Up @@ -2451,7 +2451,7 @@ public static JavaFile GetModelJavaFile(ServiceModel model, JavaSettings setting
foreach (ServiceModelProperty property in model.Properties)
{
string xmlWrapperClassName = propertyXmlWrapperClassName(property);
if (settings.ShouldGenerateXmlSerialization && property.WireType is ListType)
if (settings.ShouldGenerateXmlSerialization && property.IsXmlWrapper)
{
classBlock.PrivateStaticFinalClass(xmlWrapperClassName, innerClass =>
{
Expand Down Expand Up @@ -2481,12 +2481,16 @@ public static JavaFile GetModelJavaFile(ServiceModel model, JavaSettings setting
string localName = settings.ShouldGenerateXmlSerialization ? property.XmlName : property.SerializedName;
classBlock.Annotation($"JacksonXmlProperty(localName = \"{localName}\", isAttribute = true)");
}
else if (settings.ShouldGenerateXmlSerialization && property.WireType is ListType && !property.IsXmlWrapper)
{
classBlock.Annotation($"JsonProperty(\"{property.XmlListElementName}\")");
}
else if (!string.IsNullOrEmpty(property.AnnotationArguments))
{
classBlock.Annotation($"JsonProperty({property.AnnotationArguments})");
}
if (settings.ShouldGenerateXmlSerialization && property.WireType is ListType)
if (settings.ShouldGenerateXmlSerialization && property.IsXmlWrapper)
{
classBlock.PrivateMemberVariable($"{xmlWrapperClassName} {property.Name}");
}
Expand Down Expand Up @@ -2529,7 +2533,7 @@ public static JavaFile GetModelJavaFile(ServiceModel model, JavaSettings setting
string expression = $"this.{property.Name}";
if (sourceTypeName == targetTypeName)
{
if (settings.ShouldGenerateXmlSerialization && propertyType is ListType)
if (settings.ShouldGenerateXmlSerialization && property.IsXmlWrapper)
{
methodBlock.Return($"this.{property.Name}.items");
}
Expand Down Expand Up @@ -2635,7 +2639,7 @@ public static JavaFile GetModelJavaFile(ServiceModel model, JavaSettings setting
}
else
{
if (settings.ShouldGenerateXmlSerialization && propertyType is ListType)
if (settings.ShouldGenerateXmlSerialization && property.IsXmlWrapper)
{
methodBlock.Line($"this.{property.Name} = new {propertyXmlWrapperClassName(property)}({property.Name});");
}
Expand Down
8 changes: 0 additions & 8 deletions test/clienttypeprefix/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,6 @@

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<property>
<name>listener</name>
<value>fixtures.azurereport.CoverageReporter</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
8 changes: 0 additions & 8 deletions test/generateclientinterfaces/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,6 @@

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<property>
<name>listener</name>
<value>fixtures.azurereport.CoverageReporter</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
8 changes: 0 additions & 8 deletions test/nonnull/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,6 @@

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<property>
<name>listener</name>
<value>fixtures.azurereport.CoverageReporter</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Loading

0 comments on commit ccd166c

Please sign in to comment.