Skip to content

Commit

Permalink
Xml properties (Azure#215)
Browse files Browse the repository at this point in the history
* Check Property.ModelType.XmlProperties.Name before Property.XmlName

* Update xml tests

* Regenerate xml

* Update testserver and use exact version

* Regenerate

* Use XML name in request body mapper for non-composite type

* Regenerate

* Fix tests
  • Loading branch information
RikkiGibson authored Jul 18, 2018
1 parent 6365c53 commit fa71986
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 11 additions & 18 deletions src/vanilla/ClientModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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))
{
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
2 changes: 1 addition & 1 deletion test/xml/generated/Xml/models/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ export const RootWithRefAndMeta = {
className: "RootWithRefAndMeta",
modelProperties: {
refToModel: {
xmlName: "RefToModel",
xmlName: "XMLComplexTypeWithMeta",
serializedName: "RefToModel",
type: {
name: "Composite",
Expand Down
1 change: 1 addition & 0 deletions test/xml/generated/Xml/operations/xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,7 @@ const putAclsOperationSpec: msRest.OperationSpec = {
requestBody: {
parameterPath: "properties",
mapper: {
xmlName: "SignedIdentifiers",
xmlElementName: "SignedIdentifier",
required: true,
serializedName: "properties",
Expand Down
46 changes: 39 additions & 7 deletions test/xml/xmlTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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')
}
}
];
Expand Down

0 comments on commit fa71986

Please sign in to comment.