Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
040ca71
Swagger schema adjustment
Dec 20, 2016
620758f
wip -1
fearthecowboy Dec 21, 2016
100d167
Merge branch 'xmlBackup' into Xml
Dec 21, 2016
d8727d8
removed old xml gen
Dec 21, 2016
7c743de
xml model
Dec 21, 2016
df7dc57
tests
Dec 21, 2016
ac10ed3
real path
Dec 28, 2016
08481f3
wip 2
fearthecowboy Dec 28, 2016
83eab0d
Merge pull request #2 from olydis/Xml
fearthecowboy Dec 28, 2016
6c9c0f5
additional test
Dec 28, 2016
1c974d6
Merge pull request #3 from olydis/Xml
fearthecowboy Dec 28, 2016
9dbef48
wip 3
fearthecowboy Dec 28, 2016
d281b63
Merge branch 'Xml' of github.com:fearthecowboy/autorest into Xml
fearthecowboy Dec 28, 2016
9f3106c
test server
Dec 29, 2016
628f440
wip 5
fearthecowboy Dec 30, 2016
86bb4ce
Merge pull request #4 from olydis/Xml
fearthecowboy Dec 30, 2016
5c8b018
xml wip
fearthecowboy Jan 17, 2017
05799a7
missing files
fearthecowboy Jan 17, 2017
a5523a4
fixes
Jan 18, 2017
2361574
Merge pull request #8 from olydis/Xml
fearthecowboy Jan 18, 2017
6b7e4b6
Tweaked enum serialization
fearthecowboy Jan 18, 2017
bcd365f
generic deserialization
Jan 19, 2017
4dcd675
isWrapped serialization support
Jan 19, 2017
bd2fa92
Merge remote-tracking branch 'garrett/Xml' into Xml
Jan 19, 2017
db3e692
rfc date
Jan 19, 2017
874021b
niklas
Jan 19, 2017
261859b
new properties
Jan 19, 2017
74e8ee1
fix response header creation
Jan 20, 2017
e0bf760
refactor and remove custom (de)serialization
Jan 20, 2017
aed5c90
naming
Jan 21, 2017
5d094a2
unnecessary whitespace change
Jan 21, 2017
1470dd8
fixed templates to be non-xml sensitive
Jan 21, 2017
7b6726b
regen
Jan 21, 2017
64693d4
regen
Jan 21, 2017
4dcdcdb
fixed nullable dictionary xml deserialization and regened petstoreV2
Jan 21, 2017
5d1687a
cleanup
Jan 21, 2017
4c2c33f
xml serialization fix
Jan 21, 2017
36935cd
Merge remote-tracking branch 'azure/master' into Xml
Jan 23, 2017
bbd2ad5
fixed testcase
Jan 23, 2017
66ae094
another special case for list serialization
Jan 26, 2017
420066b
Merge branch 'Xml' of https://github.com/olydis/autorest into Xml
Jan 26, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/core/AutoRest.Core/Model/CodeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,10 @@ public virtual IEnumerable<string> MyReservedNames
}

public virtual HashSet<string> LocallyUsedNames => null;

public bool ShouldGenerateXmlSerialization =>
Methods.Any(method =>
method.RequestContentType == "application/xml" ||
(method.ResponseContentTypes?.Any(rct => rct.StartsWith("application/xml")) ?? false));
}
}
25 changes: 25 additions & 0 deletions src/core/AutoRest.Core/Model/IModelType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ public interface IModelType : IParent, IChild
/// <param name="other">The object to compare with this object.</param>
/// <returns>true if the specified object is functionally equal to this object; otherwise, false.</returns>
bool StructurallyEquals(IModelType other);

XmlProperties XmlProperties { get; set; }

[JsonIgnore]
string XmlName { get; }
[JsonIgnore]
string XmlNamespace { get; }
[JsonIgnore]
string XmlPrefix { get; }
[JsonIgnore]
bool XmlIsWrapped { get; }
[JsonIgnore]
bool XmlIsAttribute { get; }
}

/// <summary>
Expand Down Expand Up @@ -179,7 +192,19 @@ public virtual bool StructurallyEquals(IModelType other)
public virtual IEnumerable<IIdentifier> IdentifiersInScope => this.SingleItemConcat(Parent?.IdentifiersInScope);
[JsonIgnore]
public virtual IEnumerable<IChild> Children => Enumerable.Empty<IChild>();

public XmlProperties XmlProperties { get; set; }

[JsonIgnore]
public virtual string XmlName => XmlProperties?.Name ?? Name.RawValue;
[JsonIgnore]
public string XmlNamespace => XmlProperties?.Namespace;
[JsonIgnore]
public string XmlPrefix => XmlProperties?.Prefix;
[JsonIgnore]
public bool XmlIsWrapped => XmlProperties?.Wrapped ?? false;
[JsonIgnore]
public bool XmlIsAttribute => XmlProperties?.Attribute ?? false;
}

}
5 changes: 5 additions & 0 deletions src/core/AutoRest.Core/Model/Method.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ public string Summary
/// </summary>
public string RequestContentType { get; set; }

/// <summary>
/// The potential response content types.
/// </summary>
public string[] ResponseContentTypes { get; set;}

/// <summary>
/// Gets vendor extensions dictionary.
/// </summary>
Expand Down
41 changes: 41 additions & 0 deletions src/core/AutoRest.Core/Model/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,46 @@ public Fixable<string> Summary
}

public virtual bool IsPolymorphicDiscriminator => true == (Parent as CompositeType)?.BasePolymorphicDiscriminator?.EqualsIgnoreCase(Name.RawValue);

/// <summary>
/// Represents the path for getting to this property when holding the JSON node of the parent object in your hand.
/// </summary>
public IEnumerable<string> RealPath { get; set; }

/// <summary>
/// Represents the path for getting to this property when holding the XML node of the parent object in your hand.
/// </summary>
public IEnumerable<string> RealXmlPath
{
get
{
// special case: sequence types are usually inlined into parent
if (ModelType is SequenceType && !XmlIsWrapped)
{
yield break;
}

// special case: inline property (like additional properties and such)
if (RealPath?.Any() != true)
{
yield break;
}

yield return XmlName;
}
}

public XmlProperties XmlProperties { get; set; }

[JsonIgnore]
public string XmlName => XmlProperties?.Name ?? RealPath.FirstOrDefault() ?? Name;
[JsonIgnore]
public string XmlNamespace => XmlProperties?.Namespace ?? ModelType.XmlNamespace;
[JsonIgnore]
public string XmlPrefix => XmlProperties?.Prefix ?? ModelType.XmlPrefix;
[JsonIgnore]
public bool XmlIsWrapped => XmlProperties?.Wrapped ?? ModelType.XmlIsWrapped;
[JsonIgnore]
public bool XmlIsAttribute => XmlProperties?.Attribute ?? ModelType.XmlIsAttribute;
}
}
18 changes: 18 additions & 0 deletions src/core/AutoRest.Core/Model/SequenceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Globalization;
using Newtonsoft.Json;
using AutoRest.Core.Utilities;

namespace AutoRest.Core.Model
{
Expand All @@ -28,5 +29,22 @@ public override void Disambiguate()
/// Gets or sets the element type of the collection.
/// </summary>
public virtual IModelType ElementType { get; set; }

/// <summary>
/// Xml Properties...
/// </summary>
public XmlProperties ElementXmlProperties { get; set; }

[JsonIgnore]
public override string XmlName => base.XmlName.Else(ElementType.XmlName);

[JsonIgnore]
public string ElementXmlName => ElementXmlProperties?.Name ?? XmlName;
[JsonIgnore]
public string ElementXmlNamespace => ElementXmlProperties?.Namespace ?? ElementType.XmlNamespace;
[JsonIgnore]
public string ElementXmlPrefix => ElementXmlProperties?.Prefix ?? ElementType.XmlPrefix;
[JsonIgnore]
public bool ElementXmlIsWrapped => ElementXmlProperties?.Wrapped ?? ElementType.XmlIsWrapped;
}
}
41 changes: 41 additions & 0 deletions src/core/AutoRest.Core/Model/XmlProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoRest.Core.Model
{
public class XmlProperties
{
/// <summary>
/// Replaces the name of the element/attribute used for the described schema property.
/// When defined within the Items Object (items), it will affect the name of the individual XML elements within the list.
/// When defined alongside type being array (outside the items), it will affect the wrapping element and only if wrapped is true.
/// If wrapped is false, it will be ignored.
/// </summary>
public string Name { get; set; }

/// <summary>
/// The URL of the namespace definition.
/// Value SHOULD be in the form of a URL.
/// </summary>
public string Namespace { get; set; }

/// <summary>
/// The prefix to be used for the name.
/// </summary>
public string Prefix { get; set; }

/// <summary>
/// Declares whether the property definition translates to an attribute instead of an element.
/// </summary>
public bool Attribute { get; set; }

/// <summary>
/// MAY be used only for an array definition.
/// Signifies whether the array is wrapped (for example, `<books><book/><book/></books>`) or unwrapped (`<book/><book/>`).
/// The definition takes effect only when defined alongside type being array (outside the items).
/// </summary>
public bool Wrapped { get; set; }
}
}
1 change: 1 addition & 0 deletions src/core/AutoRest.Extensions/SwaggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public abstract class SwaggerExtensions
public const string PositionInOperation = "positionInOperation";
public const string ParameterLocationExtension = "x-ms-parameter-location";
public const string ExternalExtension = "x-ms-external";
public const string HeaderCollectionPrefix = "x-ms-header-collection-prefix";

private static bool hostChecked = false;

Expand Down
31 changes: 15 additions & 16 deletions src/core/AutoRest/Simplify/CSharpSimplifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@ namespace AutoRest.Simplify
public class CSharpSimplifier
{
private static MetadataReference mscorlib;
private static MetadataReference newtonsoft;
private static MetadataReference xml;

private static MetadataReference Mscorlib
{
get
{
if (mscorlib == null)
{
mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location);
}
get {return mscorlib ?? (mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location));}
}

return mscorlib;
}
private static MetadataReference Xml {
get {return xml ?? (xml = MetadataReference.CreateFromFile($"{Path.GetDirectoryName(typeof(object).Assembly.Location)}\\System.Xml.Linq.dll"));}
}

private static MetadataReference Newtonsoft
{
get {return newtonsoft ?? (newtonsoft = MetadataReference.CreateFromFile(typeof(Newtonsoft.Json.JsonObjectAttribute).Assembly.Location));}
}

public async Task Run()
Expand All @@ -45,17 +48,13 @@ public async Task Run()
var solution = new AdhocWorkspace().CurrentSolution
.AddProject(projectId, "MyProject", "MyProject", LanguageNames.CSharp)
.AddMetadataReference(projectId, Mscorlib)
.AddMetadataReference(projectId, Xml)
.AddMetadataReference(projectId, Newtonsoft)
.AddMetadataReference(projectId, AppDomain.CurrentDomain.GetAssemblies()
.Where(
a =>
string.Compare(a.GetName().Name, "Microsoft.Rest.ClientRuntime.Azure",
StringComparison.OrdinalIgnoreCase) == 0)
.Where(a =>string.Compare(a.GetName().Name, "Microsoft.Rest.ClientRuntime.Azure",StringComparison.OrdinalIgnoreCase) == 0)
.Select(a => MetadataReference.CreateFromFile(a.Location)).Single())
.AddMetadataReference(projectId, AppDomain.CurrentDomain.GetAssemblies()
.Where(
a =>
string.Compare(a.GetName().Name, "Microsoft.Rest.ClientRuntime",
StringComparison.OrdinalIgnoreCase) == 0)
.Where(a =>string.Compare(a.GetName().Name, "Microsoft.Rest.ClientRuntime",StringComparison.OrdinalIgnoreCase) == 0)
.Select(a => MetadataReference.CreateFromFile(a.Location)).Single())
.AddMetadataReference(projectId, AppDomain.CurrentDomain.GetAssemblies()
.Where(a => string.Compare(a.GetName().Name, "System", StringComparison.OrdinalIgnoreCase) == 0)
Expand Down
1 change: 1 addition & 0 deletions src/core/AutoRest/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},

"dependencies": {
"System.Xml.XDocument" : "4.0.0",
"Newtonsoft.Json": {"version": "[9.0.1,10.0)", "type":"build"},
"AutoRest.Core": { "target": "project" ,"type":"build"},
"AutoRest.Swagger": { "target": "project", "type": "build" },
Expand Down
25 changes: 14 additions & 11 deletions src/dev/AutoRest.Preview/Linting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,20 @@ public void ProcessMessages(string swagger, IEnumerable<LogMessage> messages)
{
foreach (var message in messages.Where(m => m.Path != null))
{
scintilla.IndicatorCurrent = INDICATOR_BASE + (int)message.Severity;
var node = message.Path.SelectNode(doc);
var start = node.Start.Index;
var len = Math.Max(1, node.End.Index - start);
scintilla.IndicatorFillRange(start, len);
highlights.Add(new Highlight
{
Start = start,
End = start + len,
Message = $"{message.Severity}: [{message.Path.XPath}] {message.Message}"
});
try {
scintilla.IndicatorCurrent = INDICATOR_BASE + (int)message.Severity;
var node = message.Path.SelectNode(doc);
var start = node.Start.Index;
var len = Math.Max(1, node.End.Index - start);
scintilla.IndicatorFillRange(start, len);
highlights.Add(new Highlight {
Start = start,
End = start + len,
Message = $"{message.Severity}: [{message.Path.XPath}] {message.Message}"
});
} catch {

}
}
}
}
Expand Down
Loading