From be5280df1e78ab3e8bd1f705160cec54e8ae63d1 Mon Sep 17 00:00:00 2001 From: Amar Zavery Date: Thu, 25 Jul 2019 20:28:21 -0700 Subject: [PATCH] code changes to fix serialization for polymorphic types --- package.json | 10 +++++----- src/azure/Model/CodeModelTSa.cs | 2 +- src/vanilla/ClientModelExtensions.cs | 22 ++++++++++------------ src/vanilla/Model/CodeModelTS.cs | 4 ++-- src/vanilla/Templates/TsConfig.cshtml | 2 +- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 7a75dd9489..94e8ea5e78 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@microsoft.azure/autorest.typescript", - "version": "4.1.1", + "version": "4.2.0", "description": "The typescript extension for classic generators in AutoRest.", "scripts": { "autorest": "autorest", @@ -42,8 +42,8 @@ }, "homepage": "https://github.com/Azure/autorest.typescript/blob/master/README.md", "devDependencies": { - "@azure/ms-rest-azure-js": "^1.3.2", - "@azure/ms-rest-js": "^1.8.1", + "@azure/ms-rest-azure-js": "^2.0.0", + "@azure/ms-rest-js": "^2.0.3", "@microsoft.azure/autorest.modeler": "^2.3.47", "@microsoft.azure/autorest.testserver": "^2.6.1", "@ts-common/azure-js-dev-tools": "^0.7.1", @@ -81,7 +81,7 @@ "through2-parallel": "^0.1.3", "ts-loader": "^5.3.1", "ts-node": "^7.0.1", - "tslib": "^1.9.3", + "tslib": "^1.10.0", "tslint": "^5.10.0", "typescript": "^3.2.2", "underscore": "^1.8.3", @@ -94,4 +94,4 @@ "dependencies": { "dotnet-2.0.0": "^1.4.4" } -} +} \ No newline at end of file diff --git a/src/azure/Model/CodeModelTSa.cs b/src/azure/Model/CodeModelTSa.cs index d60113a8fa..4f0cd55707 100644 --- a/src/azure/Model/CodeModelTSa.cs +++ b/src/azure/Model/CodeModelTSa.cs @@ -69,7 +69,7 @@ public override void ConstructRuntimeImportForModelIndex(TSBuilder builder) public override void PackageDependencies(JSONObject dependencies) { - dependencies.StringProperty("@azure/ms-rest-azure-js", "^1.3.2"); + dependencies.StringProperty("@azure/ms-rest-azure-js", "^2.0.0"); base.PackageDependencies(dependencies); } diff --git a/src/vanilla/ClientModelExtensions.cs b/src/vanilla/ClientModelExtensions.cs index ba4029d57d..82816dd409 100644 --- a/src/vanilla/ClientModelExtensions.cs +++ b/src/vanilla/ClientModelExtensions.cs @@ -537,6 +537,11 @@ void applyConstraints(TSObject obj) { if (expandComposite) { + CompositeType baseType = composite; + while (baseType.BaseModelType != null) + { + baseType = baseType.BaseModelType; + } if (composite.IsPolymorphic) { // Note: If the polymorphicDiscriminator has a dot in it's name then do not escape that dot for @@ -549,20 +554,13 @@ void applyConstraints(TSObject obj) polymorphicDiscriminator.QuotedStringProperty("serializedName", composite.PolymorphicDiscriminator); polymorphicDiscriminator.QuotedStringProperty("clientName", Singleton.Instance.GetPropertyName(composite.PolymorphicDiscriminator)); }); - typeObject.QuotedStringProperty("uberParent", composite.Name); + // uber parent is always the base type, if there exists one + typeObject.QuotedStringProperty("uberParent", baseType.Name); } - else + else if (baseType.IsPolymorphic) { - CompositeType baseType = composite; - while (baseType.BaseModelType != null) - { - baseType = baseType.BaseModelType; - } - if (baseType.IsPolymorphic) - { - typeObject.TextProperty("polymorphicDiscriminator", baseType.Name + ".type.polymorphicDiscriminator"); - typeObject.QuotedStringProperty("uberParent", baseType.Name); - } + typeObject.TextProperty("polymorphicDiscriminator", baseType.Name + ".type.polymorphicDiscriminator"); + typeObject.QuotedStringProperty("uberParent", baseType.Name); } } diff --git a/src/vanilla/Model/CodeModelTS.cs b/src/vanilla/Model/CodeModelTS.cs index cff7a4b8d6..8eab627751 100644 --- a/src/vanilla/Model/CodeModelTS.cs +++ b/src/vanilla/Model/CodeModelTS.cs @@ -582,8 +582,8 @@ public virtual void ConstructRuntimeImportForModelIndex(TSBuilder builder) public virtual void PackageDependencies(JSONObject dependencies) { - dependencies.StringProperty("@azure/ms-rest-js", "^1.8.1"); - dependencies.StringProperty("tslib", "^1.9.3"); + dependencies.StringProperty("@azure/ms-rest-js", "^2.0.3"); + dependencies.StringProperty("tslib", "^1.10.0"); if (Settings.MultiapiLatest) { dependencies.StringProperty(Settings.AliasedNpmPackageName, Settings.AliasedNpmVersion ?? "^1.0.0"); diff --git a/src/vanilla/Templates/TsConfig.cshtml b/src/vanilla/Templates/TsConfig.cshtml index 9d3a289606..95dfe47fad 100644 --- a/src/vanilla/Templates/TsConfig.cshtml +++ b/src/vanilla/Templates/TsConfig.cshtml @@ -10,7 +10,7 @@ "esModuleInterop": true, "allowSyntheticDefaultImports": true, "forceConsistentCasingInFileNames": true, - "lib": ["es6"], + "lib": ["es6", "dom"], "declaration": true, "outDir": "./esm", "importHelpers": true