Skip to content

Commit

Permalink
Merge pull request Azure#166 from Azure/daschult/validation
Browse files Browse the repository at this point in the history
Move validation to runtime
  • Loading branch information
Dan Schulte authored Jun 15, 2018
2 parents bb9a4cd + ee2ff15 commit b7aeb1c
Show file tree
Hide file tree
Showing 99 changed files with 3,985 additions and 7,872 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ npm install -g autorest
# Compatability
This AutoRest extension generates TypeScript code that is compatible with:
```
"ms-rest-azure-js": "~0.5.68",
"ms-rest-js": "~0.9.258"
"ms-rest-azure-js": "~0.6.75",
"ms-rest-js": "~0.10.268"
```

# Usage
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
"mocha": "^5.0.4",
"mocha-chrome": "^1.0.3",
"moment": "~2.21.0",
"ms-rest-azure-js": "~0.5.68",
"ms-rest-js": "~0.9.258",
"ms-rest-azure-js": "~0.6.75",
"ms-rest-js": "~0.10.268",
"run-sequence": "*",
"should": "5.2.0",
"shx": "^0.2.2",
Expand Down
17 changes: 15 additions & 2 deletions src/DSL/TSObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using System.Collections.Generic;
using System.Linq;

namespace AutoRest.TypeScript.DSL
{
Expand All @@ -14,6 +13,7 @@ namespace AutoRest.TypeScript.DSL
public class TSObject : IDisposable
{
private readonly TSBuilder builder;
private string propertyBeingConstructed;
private State currentState = State.Start;
private IList<string> propertyNames = new List<string>();

Expand Down Expand Up @@ -116,6 +116,11 @@ private bool PropertyNameNeedsToBeQuoted(string propertyName)
/// <param name="propertyValueAction">The action to invoke to add the property's value.</param>
public void Property(string propertyName, Action<TSValue> propertyValueAction)
{
if (!string.IsNullOrEmpty(propertyBeingConstructed))
{
throw new InvalidOperationException($"Cannot add a property to a TSObject while constructing its child property (\"{propertyBeingConstructed}\").");
}

SetCurrentState(State.Property);
if (PropertyNameNeedsToBeQuoted(propertyName))
{
Expand All @@ -126,7 +131,15 @@ public void Property(string propertyName, Action<TSValue> propertyValueAction)
builder.Text(propertyName);
}
builder.Text(": ");
builder.Value(propertyValueAction);
propertyBeingConstructed = propertyName;
try
{
builder.Value(propertyValueAction);
}
finally
{
propertyBeingConstructed = null;
}

propertyNames.Add(propertyName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/azure/Model/CodeModelTSa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public override string ConstructRuntimeImportForModelIndex()

public override string PackageDependencies()
{
return "\"ms-rest-azure-js\": \"~0.5.68\"";
return "\"ms-rest-azure-js\": \"~0.6.75\"";
}
}
}
28 changes: 23 additions & 5 deletions src/vanilla/ClientModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,19 @@ public static void ConstructRequestBodyMapper(TSValue value, ParameterTS request
IModelType requestBodyModelType = requestBody.ModelType;
if (requestBodyModelType is CompositeType)
{
value.Text($"Mappers.{requestBodyModelType.Name}");
string mapperReference = $"Mappers.{requestBodyModelType.Name}";
if (!requestBody.IsRequired)
{
value.Text(mapperReference);
}
else
{
value.Object(mapperObject =>
{
mapperObject.Spread(mapperReference);
mapperObject.BooleanProperty("required", true);
});
}
}
else
{
Expand Down Expand Up @@ -865,13 +877,12 @@ public static void ConstructMapper(TSValue value, IModelType type, string serial
typeObject.QuotedStringProperty("uberParent", polymorphicType.Name);
}

mapper.QuotedStringProperty("className", composite.Name);
typeObject.QuotedStringProperty("className", composite.Name);

if (expandComposite)
{
mapper.ObjectProperty("modelProperties", modelProperties =>
typeObject.ObjectProperty("modelProperties", modelProperties =>
{

if (composite.BaseModelType != null && composite.BaseModelType.ComposedProperties.Any())
{
modelProperties.Spread(composite.BaseModelType.Name + ".type.modelProperties");
Expand All @@ -895,7 +906,14 @@ public static void ConstructMapper(TSValue value, IModelType type, string serial
}
}

modelProperties.Property(prop.Name, propertyValue => ConstructMapper(propertyValue, prop.ModelType, serializedPropertyName, prop, false, false, isXML, isCaseSensitive));
if (modelProperties.ContainsProperty(prop.Name))
{
// throw new InvalidOperationException($"Mapper \"{serializedName}\" contains multiple modelProperties with the name \"{prop.Name}\".");
}
else
{
modelProperties.Property(prop.Name, propertyValue => ConstructMapper(propertyValue, prop.ModelType, serializedPropertyName, prop, false, false, isXML, isCaseSensitive));
}
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/vanilla/Model/CodeModelTS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public virtual string ConstructRuntimeImportForModelIndex()

public virtual string PackageDependencies()
{
return "\"ms-rest-js\": \"~0.9.258\"";
return "\"ms-rest-js\": \"~0.10.268\"";
}

public virtual Method GetSampleMethod()
Expand Down
Loading

0 comments on commit b7aeb1c

Please sign in to comment.