Skip to content

Commit

Permalink
code changes to fix serialization for polymorphic types
Browse files Browse the repository at this point in the history
  • Loading branch information
amarzavery committed Jul 26, 2019
1 parent 8b2d805 commit be5280d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -94,4 +94,4 @@
"dependencies": {
"dotnet-2.0.0": "^1.4.4"
}
}
}
2 changes: 1 addition & 1 deletion src/azure/Model/CodeModelTSa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
22 changes: 10 additions & 12 deletions src/vanilla/ClientModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -549,20 +554,13 @@ void applyConstraints(TSObject obj)
polymorphicDiscriminator.QuotedStringProperty("serializedName", composite.PolymorphicDiscriminator);
polymorphicDiscriminator.QuotedStringProperty("clientName", Singleton<CodeNamerTS>.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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/vanilla/Model/CodeModelTS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/vanilla/Templates/TsConfig.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"lib": ["es6"],
"lib": ["es6", "dom"],
"declaration": true,
"outDir": "./esm",
"importHelpers": true
Expand Down

0 comments on commit be5280d

Please sign in to comment.