diff --git a/package.json b/package.json index bcfe3fa55c68..de65f842b2db 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "homepage": "https://github.com/Azure/autorest.typescript/blob/master/README.md", "devDependencies": { "@microsoft.azure/autorest.modeler": "^2.3.51", - "@microsoft.azure/autorest.testserver": "^2.5.22", + "@microsoft.azure/autorest.testserver": "2.5.23", "@types/assert": "0.0.31", "@types/express": "^4.11.1", "@types/fork-ts-checker-webpack-plugin": "^0.4.0", diff --git a/src/vanilla/ClientModelExtensions.cs b/src/vanilla/ClientModelExtensions.cs index 7f59cdb5a592..0a2f98bfaa94 100644 --- a/src/vanilla/ClientModelExtensions.cs +++ b/src/vanilla/ClientModelExtensions.cs @@ -567,7 +567,8 @@ public static void ConstructRequestBodyMapper(TSValue value, Parameter requestBo requestBody, isPageable: false, expandComposite: false, - isXML: requestBody.Parent.CodeModel.ShouldGenerateXmlSerialization == true); + isXML: requestBody.Parent.CodeModel.ShouldGenerateXmlSerialization == true, + xmlName: requestBodyModelType.XmlProperties?.Name); } } @@ -623,11 +624,6 @@ public static void ConstructMapper(TSObject mapper, IModelType type, string seri mapper.QuotedStringProperty("xmlName", xmlName); } - if (!isCaseSensitive) - { - serializedName = serializedName.ToLower(); - } - if (property != null) { isReadOnly = property.IsReadOnly; @@ -644,13 +640,19 @@ public static void ConstructMapper(TSObject mapper, IModelType type, string seri mapper.BooleanProperty("xmlIsWrapped", true); } - if (!addXmlNameFromParameterValue && !string.IsNullOrEmpty(property.XmlName)) + string propertyXmlName = property.ModelType.XmlProperties?.Name ?? property.XmlName; + if (!addXmlNameFromParameterValue && !string.IsNullOrEmpty(propertyXmlName)) { - mapper.QuotedStringProperty("xmlName", property.XmlName); + mapper.QuotedStringProperty("xmlName", propertyXmlName); } } } + if (!isCaseSensitive) + { + serializedName = serializedName.ToLower(); + } + CompositeType composite = type as CompositeType; if (composite != null && composite.ContainsConstantProperties && (parameter != null && parameter.IsRequired)) { @@ -665,16 +667,7 @@ public static void ConstructMapper(TSObject mapper, IModelType type, string seri mapper.BooleanProperty("xmlElementIsWrapped", true); } - string xmlElementName = null; - if (sequence.ElementType is CompositeType compositeElementType) - { - xmlElementName = compositeElementType.XmlName; - } - else - { - xmlElementName = sequence.ElementXmlName; - } - + string xmlElementName = sequence.ElementType.XmlProperties?.Name ?? sequence.ElementXmlName; if (!string.IsNullOrEmpty(xmlElementName)) { mapper.QuotedStringProperty("xmlElementName", xmlElementName); diff --git a/test/xml/generated/Xml/autoRestSwaggerBATXMLServiceContext.ts b/test/xml/generated/Xml/autoRestSwaggerBATXMLServiceContext.ts index 30cc47e1a316..05def3d7b1a2 100644 --- a/test/xml/generated/Xml/autoRestSwaggerBATXMLServiceContext.ts +++ b/test/xml/generated/Xml/autoRestSwaggerBATXMLServiceContext.ts @@ -42,7 +42,7 @@ export class AutoRestSwaggerBATXMLServiceContext extends msRest.ServiceClient { this.baseUri = baseUri as string; if (!this.baseUri) { - this.baseUri = "http://localhost"; + this.baseUri = "http://localhost:3000"; } this.addUserAgentInfo(`${packageName}/${packageVersion}`); diff --git a/test/xml/generated/Xml/models/mappers.ts b/test/xml/generated/Xml/models/mappers.ts index 9902b5817bc7..95d953a5733c 100644 --- a/test/xml/generated/Xml/models/mappers.ts +++ b/test/xml/generated/Xml/models/mappers.ts @@ -1162,7 +1162,7 @@ export const RootWithRefAndMeta = { className: "RootWithRefAndMeta", modelProperties: { refToModel: { - xmlName: "RefToModel", + xmlName: "XMLComplexTypeWithMeta", serializedName: "RefToModel", type: { name: "Composite", diff --git a/test/xml/generated/Xml/operations/xml.ts b/test/xml/generated/Xml/operations/xml.ts index d6aef1b0ac5a..6db6fbc66151 100644 --- a/test/xml/generated/Xml/operations/xml.ts +++ b/test/xml/generated/Xml/operations/xml.ts @@ -1801,6 +1801,7 @@ const putAclsOperationSpec: msRest.OperationSpec = { requestBody: { parameterPath: "properties", mapper: { + xmlName: "SignedIdentifiers", xmlElementName: "SignedIdentifier", required: true, serializedName: "properties", diff --git a/test/xml/xmlTests.ts b/test/xml/xmlTests.ts index dde1d7d7097f..de0d8a6c54e8 100644 --- a/test/xml/xmlTests.ts +++ b/test/xml/xmlTests.ts @@ -212,18 +212,50 @@ describe('typescript', function () { should.exist(banana); banana.name.should.equal('Unknown Banana'); banana.flavor.should.equal(''); - banana.expiration.valueOf().should.equal(new Date('2012-02-24T00:53:52.780Z').valueOf()); + banana.expiration.valueOf().should.equal(new Date('2012-02-24T00:53:52.789Z').valueOf()); }); it('should correctly serialize an XML document with an empty child element', async function () { const banana: models.Banana = { name: 'Unknown Banana', flavor: '', - expiration: new Date('2012-02-24T00:53:52.780Z') + expiration: new Date('2012-02-24T00:53:52.789Z') } await testClient.xml.putEmptyChildElement(banana); }); + it('should get a complex type ref with no XML metadata', async function() { + const result = await testClient.xml.getComplexTypeRefNoMeta(); + result.refToModel.id.should.equal('myid'); + result.something.should.equal('else'); + }); + + it('should put a complex type ref with no XML metadata', async function() { + const arg = { + refToModel: { + id: 'myid' + }, + something: 'else' + }; + await testClient.xml.putComplexTypeRefNoMeta(arg); + }); + + it('should get a complex type ref with XML metadata', async function() { + const result = await testClient.xml.getComplexTypeRefWithMeta(); + result.refToModel.id.should.equal('myid'); + result.something.should.equal('else'); + }); + + it('should put a complex type ref with XML metadata', async function() { + const arg = { + refToModel: { + id: 'myid' + }, + something: 'else' + }; + await testClient.xml.putComplexTypeRefWithMeta(arg); + }); + it('should list containers in a storage account', async function () { const listContainersResponse = await testClient.xml.listContainers(); should.exist(listContainersResponse); @@ -318,18 +350,18 @@ describe('typescript', function () { acls.length.should.equal(1); acls[0].id.should.equal('MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI='); acls[0].accessPolicy.permission.should.equal('rwd'); - acls[0].accessPolicy.start.valueOf().should.equal(new Date('2009-09-28T08:49:37.0000000Z').valueOf()); - acls[0].accessPolicy.expiry.valueOf().should.equal(new Date('2009-09-29T08:49:37.0000000Z').valueOf()); + acls[0].accessPolicy.start.valueOf().should.equal(new Date('2009-09-28T08:49:37.123Z').valueOf()); + acls[0].accessPolicy.expiry.valueOf().should.equal(new Date('2009-09-29T08:49:37.123Z').valueOf()); }); - it.skip('should put storage ACLs for a container', async function () { + it('should put storage ACLs for a container', async function () { const acls: models.SignedIdentifier[] = [ { id: 'MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=', accessPolicy: { permission: 'rwd', - start: new Date('2009-09-28T08:49:37.0000000Z'), - expiry: new Date('2009-09-29T08:49:37.0000000Z') + start: new Date('2009-09-28T08:49:37.123Z'), + expiry: new Date('2009-09-29T08:49:37.123Z') } } ];